mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Update SettingsFragment.kt
This commit is contained in:
parent
650522993c
commit
a1985a10b1
1 changed files with 199 additions and 197 deletions
|
@ -242,219 +242,221 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
settingsManager.edit().putString(getString(R.string.download_path_pref), dirs[it]).apply()
|
settingsManager.edit().putString(getString(R.string.download_path_pref), dirs[it]).apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
if (preferedMediaTypePreference != null) {
|
if (preferedMediaTypePreference != null) {
|
||||||
preferedMediaTypePreference.setOnPreferenceClickListener {
|
preferedMediaTypePreference.setOnPreferenceClickListener {
|
||||||
val prefNames = resources.getStringArray(R.array.media_type_pref)
|
val prefNames = resources.getStringArray(R.array.media_type_pref)
|
||||||
val prefValues = resources.getIntArray(R.array.media_type_pref_values)
|
val prefValues = resources.getIntArray(R.array.media_type_pref_values)
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
val currentPrefMedia =
|
|
||||||
settingsManager.getInt(getString(R.string.preferred_media_settings), 0)
|
|
||||||
|
|
||||||
context?.showBottomDialog(
|
|
||||||
prefNames.toList(),
|
|
||||||
prefValues.indexOf(currentPrefMedia),
|
|
||||||
getString(R.string.preferred_media_settings),
|
|
||||||
true,
|
|
||||||
{}) {
|
|
||||||
settingsManager.edit()
|
|
||||||
.putInt(getString(R.string.preferred_media_settings), prefValues[it])
|
|
||||||
.apply()
|
|
||||||
context?.initRequestClient()
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allLayoutPreference.setOnPreferenceClickListener {
|
|
||||||
val prefNames = resources.getStringArray(R.array.app_layout)
|
|
||||||
val prefValues = resources.getIntArray(R.array.app_layout_values)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
val currentLayout =
|
val currentPrefMedia =
|
||||||
settingsManager.getInt(getString(R.string.app_layout_key), -1)
|
settingsManager.getInt(getString(R.string.preferred_media_settings), 0)
|
||||||
|
|
||||||
context?.showBottomDialog(
|
context?.showBottomDialog(
|
||||||
prefNames.toList(),
|
prefNames.toList(),
|
||||||
prefValues.indexOf(currentLayout),
|
prefValues.indexOf(currentPrefMedia),
|
||||||
getString(R.string.app_layout),
|
getString(R.string.preferred_media_settings),
|
||||||
true,
|
true,
|
||||||
{}) {
|
{}) {
|
||||||
try {
|
settingsManager.edit()
|
||||||
settingsManager.edit().putInt(getString(R.string.app_layout_key), prefValues[it])
|
.putInt(getString(R.string.preferred_media_settings), prefValues[it])
|
||||||
.apply()
|
|
||||||
activity?.recreate()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
colorPrimaryPreference.setOnPreferenceClickListener {
|
|
||||||
val prefNames = resources.getStringArray(R.array.themes_overlay_names)
|
|
||||||
val prefValues = resources.getStringArray(R.array.themes_overlay_names_values)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
val currentLayout =
|
|
||||||
settingsManager.getString(getString(R.string.primary_color_key), prefValues.first())
|
|
||||||
context?.showBottomDialog(
|
|
||||||
prefNames.toList(),
|
|
||||||
prefValues.indexOf(currentLayout),
|
|
||||||
getString(R.string.primary_color_settings),
|
|
||||||
true,
|
|
||||||
{}) {
|
|
||||||
try {
|
|
||||||
settingsManager.edit().putString(getString(R.string.primary_color_key), prefValues[it])
|
|
||||||
.apply()
|
|
||||||
activity?.recreate()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
appThemePreference.setOnPreferenceClickListener {
|
|
||||||
val prefNames = resources.getStringArray(R.array.themes_names)
|
|
||||||
val prefValues = resources.getStringArray(R.array.themes_names_values)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
val currentLayout =
|
|
||||||
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
|
|
||||||
context?.showBottomDialog(
|
|
||||||
prefNames.toList(),
|
|
||||||
prefValues.indexOf(currentLayout),
|
|
||||||
getString(R.string.app_theme_settings),
|
|
||||||
true,
|
|
||||||
{}) {
|
|
||||||
try {
|
|
||||||
settingsManager.edit().putString(getString(R.string.app_theme_key), prefValues[it])
|
|
||||||
.apply()
|
|
||||||
activity?.recreate()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
watchQualityPreference.setOnPreferenceClickListener {
|
|
||||||
val prefNames = resources.getStringArray(R.array.quality_pref)
|
|
||||||
val prefValues = resources.getIntArray(R.array.quality_pref_values)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
val currentQuality =
|
|
||||||
settingsManager.getInt(
|
|
||||||
getString(R.string.watch_quality_pref),
|
|
||||||
Qualities.values().last().value
|
|
||||||
)
|
|
||||||
context?.showBottomDialog(
|
|
||||||
prefNames.toList(),
|
|
||||||
prefValues.indexOf(currentQuality),
|
|
||||||
getString(R.string.watch_quality_pref),
|
|
||||||
true,
|
|
||||||
{}) {
|
|
||||||
settingsManager.edit().putInt(getString(R.string.watch_quality_pref), prefValues[it])
|
|
||||||
.apply()
|
.apply()
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
dnsPreference.setOnPreferenceClickListener {
|
|
||||||
val prefNames = resources.getStringArray(R.array.dns_pref)
|
|
||||||
val prefValues = resources.getIntArray(R.array.dns_pref_values)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
val currentDns =
|
|
||||||
settingsManager.getInt(getString(R.string.dns_pref), 0)
|
|
||||||
context?.showBottomDialog(
|
|
||||||
prefNames.toList(),
|
|
||||||
prefValues.indexOf(currentDns),
|
|
||||||
getString(R.string.dns_pref),
|
|
||||||
true,
|
|
||||||
{}) {
|
|
||||||
settingsManager.edit().putInt(getString(R.string.dns_pref), prefValues[it]).apply()
|
|
||||||
context?.initRequestClient()
|
context?.initRequestClient()
|
||||||
}
|
}
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
beneneCount = settingsManager.getInt(getString(R.string.benene_count), 0)
|
|
||||||
|
|
||||||
benenePreference.summary =
|
|
||||||
if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(
|
|
||||||
beneneCount
|
|
||||||
)
|
|
||||||
benenePreference.setOnPreferenceClickListener {
|
|
||||||
try {
|
|
||||||
beneneCount++
|
|
||||||
settingsManager.edit().putInt(getString(R.string.benene_count), beneneCount).apply()
|
|
||||||
it.summary = getString(R.string.benene_count_text).format(beneneCount)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePreference.setOnPreferenceClickListener {
|
|
||||||
thread {
|
|
||||||
if (!requireActivity().runAutoUpdate(false)) {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
showToast(activity, R.string.no_update_found, Toast.LENGTH_SHORT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
localePreference.setOnPreferenceClickListener { pref ->
|
|
||||||
val tempLangs = languages.toMutableList()
|
|
||||||
if (beneneCount > 100) {
|
|
||||||
tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
|
|
||||||
}
|
|
||||||
val current = getCurrentLocale()
|
|
||||||
val languageCodes = tempLangs.map { it.third }
|
|
||||||
val languageNames = tempLangs.map { "${it.first} ${it.second}" }
|
|
||||||
val index = languageCodes.indexOf(current)
|
|
||||||
pref?.context?.showDialog(
|
|
||||||
languageNames, index, getString(R.string.app_language), true, { }
|
|
||||||
) { languageIndex ->
|
|
||||||
try {
|
|
||||||
val code = languageCodes[languageIndex]
|
|
||||||
setLocale(activity, code)
|
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(pref.context)
|
|
||||||
settingsManager.edit().putString(getString(R.string.locale_key), code).apply()
|
|
||||||
activity?.recreate()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@setOnPreferenceClickListener true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentLocale(): String {
|
allLayoutPreference.setOnPreferenceClickListener {
|
||||||
val res = context!!.resources
|
val prefNames = resources.getStringArray(R.array.app_layout)
|
||||||
// Change locale settings in the app.
|
val prefValues = resources.getIntArray(R.array.app_layout_values)
|
||||||
// val dm = res.displayMetrics
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val conf = res.configuration
|
|
||||||
return conf?.locale?.language ?: "en"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
val currentLayout =
|
||||||
if (preference != null) {
|
settingsManager.getInt(getString(R.string.app_layout_key), -1)
|
||||||
if (preference.key == getString(R.string.subtitle_settings_key)) {
|
context?.showBottomDialog(
|
||||||
SubtitlesFragment.push(activity, false)
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(currentLayout),
|
||||||
|
getString(R.string.app_layout),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
try {
|
||||||
|
settingsManager.edit().putInt(getString(R.string.app_layout_key), prefValues[it])
|
||||||
|
.apply()
|
||||||
|
activity?.recreate()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onPreferenceTreeClick(preference)
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
colorPrimaryPreference.setOnPreferenceClickListener {
|
||||||
|
val prefNames = resources.getStringArray(R.array.themes_overlay_names)
|
||||||
|
val prefValues = resources.getStringArray(R.array.themes_overlay_names_values)
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
val currentLayout =
|
||||||
|
settingsManager.getString(getString(R.string.primary_color_key), prefValues.first())
|
||||||
|
context?.showBottomDialog(
|
||||||
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(currentLayout),
|
||||||
|
getString(R.string.primary_color_settings),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
try {
|
||||||
|
settingsManager.edit().putString(getString(R.string.primary_color_key), prefValues[it])
|
||||||
|
.apply()
|
||||||
|
activity?.recreate()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
appThemePreference.setOnPreferenceClickListener {
|
||||||
|
val prefNames = resources.getStringArray(R.array.themes_names)
|
||||||
|
val prefValues = resources.getStringArray(R.array.themes_names_values)
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
val currentLayout =
|
||||||
|
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
|
||||||
|
context?.showBottomDialog(
|
||||||
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(currentLayout),
|
||||||
|
getString(R.string.app_theme_settings),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
try {
|
||||||
|
settingsManager.edit().putString(getString(R.string.app_theme_key), prefValues[it])
|
||||||
|
.apply()
|
||||||
|
activity?.recreate()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
watchQualityPreference.setOnPreferenceClickListener {
|
||||||
|
val prefNames = resources.getStringArray(R.array.quality_pref)
|
||||||
|
val prefValues = resources.getIntArray(R.array.quality_pref_values)
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
val currentQuality =
|
||||||
|
settingsManager.getInt(
|
||||||
|
getString(R.string.watch_quality_pref),
|
||||||
|
Qualities.values().last().value
|
||||||
|
)
|
||||||
|
context?.showBottomDialog(
|
||||||
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(currentQuality),
|
||||||
|
getString(R.string.watch_quality_pref),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
settingsManager.edit().putInt(getString(R.string.watch_quality_pref), prefValues[it])
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
dnsPreference.setOnPreferenceClickListener {
|
||||||
|
val prefNames = resources.getStringArray(R.array.dns_pref)
|
||||||
|
val prefValues = resources.getIntArray(R.array.dns_pref_values)
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
val currentDns =
|
||||||
|
settingsManager.getInt(getString(R.string.dns_pref), 0)
|
||||||
|
context?.showBottomDialog(
|
||||||
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(currentDns),
|
||||||
|
getString(R.string.dns_pref),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
settingsManager.edit().putInt(getString(R.string.dns_pref), prefValues[it]).apply()
|
||||||
|
context?.initRequestClient()
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
beneneCount = settingsManager.getInt(getString(R.string.benene_count), 0)
|
||||||
|
|
||||||
|
benenePreference.summary =
|
||||||
|
if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(
|
||||||
|
beneneCount
|
||||||
|
)
|
||||||
|
benenePreference.setOnPreferenceClickListener {
|
||||||
|
try {
|
||||||
|
beneneCount++
|
||||||
|
settingsManager.edit().putInt(getString(R.string.benene_count), beneneCount).apply()
|
||||||
|
it.summary = getString(R.string.benene_count_text).format(beneneCount)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePreference.setOnPreferenceClickListener {
|
||||||
|
thread {
|
||||||
|
if (!requireActivity().runAutoUpdate(false)) {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
showToast(activity, R.string.no_update_found, Toast.LENGTH_SHORT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
localePreference.setOnPreferenceClickListener { pref ->
|
||||||
|
val tempLangs = languages.toMutableList()
|
||||||
|
if (beneneCount > 100) {
|
||||||
|
tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
|
||||||
|
}
|
||||||
|
val current = getCurrentLocale()
|
||||||
|
val languageCodes = tempLangs.map { it.third }
|
||||||
|
val languageNames = tempLangs.map { "${it.first} ${it.second}" }
|
||||||
|
val index = languageCodes.indexOf(current)
|
||||||
|
pref?.context?.showDialog(
|
||||||
|
languageNames, index, getString(R.string.app_language), true, { }
|
||||||
|
) { languageIndex ->
|
||||||
|
try {
|
||||||
|
val code = languageCodes[languageIndex]
|
||||||
|
setLocale(activity, code)
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(pref.context)
|
||||||
|
settingsManager.edit().putString(getString(R.string.locale_key), code).apply()
|
||||||
|
activity?.recreate()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCurrentLocale(): String {
|
||||||
|
val res = context!!.resources
|
||||||
|
// Change locale settings in the app.
|
||||||
|
// val dm = res.displayMetrics
|
||||||
|
val conf = res.configuration
|
||||||
|
return conf?.locale?.language ?: "en"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||||
|
if (preference != null) {
|
||||||
|
if (preference.key == getString(R.string.subtitle_settings_key)) {
|
||||||
|
SubtitlesFragment.push(activity, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onPreferenceTreeClick(preference)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue