Merge pull request #334 from Bnyro/master

player stops in settings fixed
This commit is contained in:
Bnyro 2022-05-30 22:24:43 +02:00 committed by GitHub
commit 15de27676a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,7 @@ import org.json.JSONTokener
import retrofit2.HttpException import retrofit2.HttpException
private var isCurrentViewMainSettings = true private var isCurrentViewMainSettings = true
private var requireMainActivityRestart = false
class SettingsActivity : class SettingsActivity :
AppCompatActivity(), AppCompatActivity(),
@ -243,11 +244,13 @@ class SettingsActivity :
themeToggle?.setOnPreferenceChangeListener { _, _ -> themeToggle?.setOnPreferenceChangeListener { _, _ ->
val refresh = Intent(context, SettingsActivity::class.java) val refresh = Intent(context, SettingsActivity::class.java)
startActivity(refresh) startActivity(refresh)
requireMainActivityRestart = true
true true
} }
val accentColor = findPreference<Preference>("accent_color") val accentColor = findPreference<Preference>("accent_color")
accentColor?.setOnPreferenceChangeListener { _, _ -> accentColor?.setOnPreferenceChangeListener { _, _ ->
requireMainActivityRestart = true
val refresh = Intent(context, SettingsActivity::class.java) val refresh = Intent(context, SettingsActivity::class.java)
startActivity(refresh) startActivity(refresh)
true true
@ -259,9 +262,9 @@ class SettingsActivity :
true true
} }
val changeLanguage = findPreference<ListPreference>("language") val gridColumns = findPreference<ListPreference>("grid")
changeLanguage?.setOnPreferenceChangeListener { _, _ -> gridColumns?.setOnPreferenceChangeListener { _, _ ->
restartMainActivity(requireContext()) requireMainActivityRestart = true
true true
} }
@ -384,7 +387,13 @@ class SettingsActivity :
if (isCurrentViewMainSettings) { if (isCurrentViewMainSettings) {
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this) .unregisterOnSharedPreferenceChangeListener(this)
if (requireMainActivityRestart) {
restartMainActivity(this) restartMainActivity(this)
finishAffinity()
} else {
super.onBackPressed()
}
finishAndRemoveTask()
} else { } else {
isCurrentViewMainSettings = true isCurrentViewMainSettings = true
supportFragmentManager supportFragmentManager