mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
subtitle pref cleanup
This commit is contained in:
parent
3b67ab07e2
commit
44e79d8096
@ -8,6 +8,7 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.ui.activities.SettingsActivity
|
import com.github.libretube.ui.activities.SettingsActivity
|
||||||
import com.github.libretube.ui.base.BasePreferenceFragment
|
import com.github.libretube.ui.base.BasePreferenceFragment
|
||||||
|
import com.github.libretube.util.LocaleHelper
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -36,24 +37,24 @@ class PlayerSettings : BasePreferenceFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val defaultSubtitle = findPreference<ListPreference>(PreferenceKeys.DEFAULT_SUBTITLE)
|
val defaultSubtitle = findPreference<ListPreference>(PreferenceKeys.DEFAULT_SUBTITLE)
|
||||||
val locales: Array<Locale> = Locale.getAvailableLocales()
|
defaultSubtitle?.let { setupSubtitlePref(it) }
|
||||||
val localeNames = ArrayList<String>()
|
}
|
||||||
val localeCodes = ArrayList<String>()
|
|
||||||
|
|
||||||
localeNames.add(context?.getString(R.string.none)!!)
|
private fun setupSubtitlePref(preference: ListPreference) {
|
||||||
localeCodes.add("")
|
val locales = LocaleHelper.getAvailableLocales()
|
||||||
|
val localeNames = locales.map { it.name }
|
||||||
|
.toMutableList()
|
||||||
|
localeNames.add(0, requireContext().getString(R.string.none))
|
||||||
|
|
||||||
locales.forEach {
|
val localeCodes = locales.map { it.code }
|
||||||
if (!localeNames.contains(it.getDisplayLanguage())) {
|
.toMutableList()
|
||||||
localeNames.add(it.getDisplayLanguage())
|
localeCodes.add(0, "")
|
||||||
localeCodes.add(it.language)
|
|
||||||
}
|
preference.entries = localeNames.toTypedArray()
|
||||||
}
|
preference.entryValues = localeCodes.toTypedArray()
|
||||||
defaultSubtitle?.entries = localeNames.toTypedArray()
|
preference.summaryProvider =
|
||||||
defaultSubtitle?.entryValues = localeCodes.toTypedArray()
|
Preference.SummaryProvider<ListPreference> {
|
||||||
defaultSubtitle?.summaryProvider =
|
it.entry
|
||||||
Preference.SummaryProvider<ListPreference> { preference ->
|
|
||||||
preference.entry
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,4 +103,21 @@ object LocaleHelper {
|
|||||||
countries.sortBy { it.name }
|
countries.sortBy { it.name }
|
||||||
return countries
|
return countries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAvailableLocales(): List<Country> {
|
||||||
|
val availableLocales: Array<Locale> = Locale.getAvailableLocales()
|
||||||
|
val locales = mutableListOf<Country>()
|
||||||
|
|
||||||
|
availableLocales.forEach { locale ->
|
||||||
|
if (locales.filter { it.code == locale.language }.isEmpty()) {
|
||||||
|
locales.add(
|
||||||
|
Country(
|
||||||
|
locale.displayLanguage,
|
||||||
|
locale.language
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return locales
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user