Skip to content

Commit

Permalink
fix: lang codes not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 7, 2024
1 parent 40c2989 commit fda68a7
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class AnimeWatchAdapter(
val adapter = ArrayAdapter(
fragment.requireContext(),
R.layout.item_dropdown,
parser.extension.sources.map { LanguageMapper.getLanguageCode(it.lang) }
parser.extension.sources.map { LanguageMapper.getLanguageName(it.lang) }
)
val items = adapter.count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class AnimeWatchFragment : Fragment() {
var selectedSetting = allSettings[0]
if (allSettings.size > 1) {
val names =
allSettings.map { LanguageMapper.getLanguageCode(it.lang) }.toTypedArray()
allSettings.map { LanguageMapper.getLanguageName(it.lang) }.toTypedArray()
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, -1) { dialog, which ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class MangaReadAdapter(
val adapter = ArrayAdapter(
fragment.requireContext(),
R.layout.item_dropdown,
parser.extension.sources.map { LanguageMapper.getLanguageCode(it.lang) }
parser.extension.sources.map { LanguageMapper.getLanguageName(it.lang) }
)
val items = adapter.count
binding?.animeSourceLanguageContainer?.isVisible = items > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
var selectedSetting = allSettings[0]
if (allSettings.size > 1) {
val names =
allSettings.map { LanguageMapper.getLanguageCode(it.lang) }.toTypedArray()
allSettings.map { LanguageMapper.getLanguageName(it.lang) }.toTypedArray()
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, -1) { dialog, which ->
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/ani/dantotsu/others/LanguageMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class LanguageMapper {
"zu" to "Zulu"
)

fun getLanguage(code: String): String {
fun getLanguageName(code: String): String {
return if (code.contains("-")) {
try {
val parts = code.split("-")
Expand All @@ -129,6 +129,9 @@ class LanguageMapper {
}
} else {
try {
if (code == "all") {
return codeMap[code] ?: code
}
Locale(code).displayName
} catch (ignored: Exception) {
code
Expand All @@ -137,7 +140,8 @@ class LanguageMapper {
}

fun getLanguageCode(language: String): String {
return codeMap.filterValues { it.lowercase() == language.lowercase() }.keys.firstOrNull() ?: "all"
return codeMap.filterValues { it.lowercase() == language.lowercase() }.keys.firstOrNull()
?: "all"
}

enum class Language(val code: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
if (allSettings.isNotEmpty()) {
var selectedSetting = allSettings[0]
if (allSettings.size > 1) {
val names = allSettings.map { LanguageMapper.getLanguageCode(it.lang) }
val names = allSettings.map { LanguageMapper.getLanguageName(it.lang) }
.toTypedArray()
var selectedIndex = 0
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
Expand Down Expand Up @@ -295,7 +295,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val extension = getItem(position)
val nsfw = if (extension.isNsfw) "(18+)" else ""
val lang = LanguageMapper.getLanguageCode(extension.lang)
val lang = LanguageMapper.getLanguageName(extension.lang)
holder.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
holder.extensionVersionTextView.text = versionText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
if (allSettings.isNotEmpty()) {
var selectedSetting = allSettings[0]
if (allSettings.size > 1) {
val names = allSettings.map { LanguageMapper.getLanguageCode(it.lang) }
val names = allSettings.map { LanguageMapper.getLanguageName(it.lang) }
.toTypedArray()
var selectedIndex = 0
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
Expand Down Expand Up @@ -293,7 +293,7 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val extension = getItem(position) // Use getItem() from ListAdapter
val nsfw = if (extension.isNsfw) "(18+)" else ""
val lang = LanguageMapper.getLanguageCode(extension.lang)
val lang = LanguageMapper.getLanguageName(extension.lang)
holder.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
holder.extensionVersionTextView.text = versionText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class InstalledNovelExtensionsFragment : Fragment(), SearchQueryHandler {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val extension = getItem(position) // Use getItem() from ListAdapter
val nsfw = ""
val lang = LanguageMapper.getLanguageCode("all")
val lang = LanguageMapper.getLanguageName("all")
holder.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
holder.extensionVersionTextView.text = versionText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class AnimeExtensionAdapter(private val clickListener: OnAnimeInstallClickListen

fun bind(extension: AnimeExtension.Available) {
val nsfw = if (extension.isNsfw) "(18+)" else ""
val lang = LanguageMapper.getLanguageCode(extension.lang)
val lang = LanguageMapper.getLanguageName(extension.lang)
binding.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
binding.extensionVersionTextView.text = versionText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class MangaExtensionAdapter(private val clickListener: OnMangaInstallClickListen

fun bind(extension: MangaExtension.Available) {
val nsfw = if (extension.isNsfw) "(18+)" else ""
val lang = LanguageMapper.getLanguageCode(extension.lang)
val lang = LanguageMapper.getLanguageName(extension.lang)
binding.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
binding.extensionVersionTextView.text = versionText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class NovelExtensionAdapter(private val clickListener: OnNovelInstallClickListen
val extensionIconImageView: ImageView = binding.extensionIconImageView
fun bind(extension: NovelExtension.Available) {
val nsfw = ""
val lang = LanguageMapper.getLanguageCode("all")
val lang = LanguageMapper.getLanguageName("all")
binding.extensionNameTextView.text = extension.name
binding.extensionVersionTextView.text = "$lang ${extension.versionName} $nsfw"
}
Expand Down

0 comments on commit fda68a7

Please sign in to comment.