From 828bdaf0fb47caf3a7a261c977d1e314496d89d3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 30 May 2022 22:19:42 +0200 Subject: [PATCH 1/2] player stops in settings fixed --- .../com/github/libretube/SettingsActivity.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt index 7c1ed9fab..720f79306 100644 --- a/app/src/main/java/com/github/libretube/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt @@ -28,20 +28,20 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.google.android.material.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.json.JSONObject +import org.json.JSONTokener +import retrofit2.HttpException import java.io.IOException import java.io.InputStream import java.util.zip.ZipEntry import java.util.zip.ZipInputStream -import org.json.JSONObject -import org.json.JSONTokener -import retrofit2.HttpException private var isCurrentViewMainSettings = true +private var requireMainActivityRestart = false class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener { - override fun onCreate(savedInstanceState: Bundle?) { DynamicColors.applyToActivityIfAvailable(this) updateAccentColor(this) @@ -243,11 +243,13 @@ class SettingsActivity : themeToggle?.setOnPreferenceChangeListener { _, _ -> val refresh = Intent(context, SettingsActivity::class.java) startActivity(refresh) + requireMainActivityRestart = true true } val accentColor = findPreference("accent_color") accentColor?.setOnPreferenceChangeListener { _, _ -> + requireMainActivityRestart = true val refresh = Intent(context, SettingsActivity::class.java) startActivity(refresh) true @@ -259,9 +261,9 @@ class SettingsActivity : true } - val changeLanguage = findPreference("language") - changeLanguage?.setOnPreferenceChangeListener { _, _ -> - restartMainActivity(requireContext()) + val gridColumns = findPreference("grid") + gridColumns?.setOnPreferenceChangeListener { _, _ -> + requireMainActivityRestart = true true } @@ -384,7 +386,13 @@ class SettingsActivity : if (isCurrentViewMainSettings) { PreferenceManager.getDefaultSharedPreferences(this) .unregisterOnSharedPreferenceChangeListener(this) - restartMainActivity(this) + if (requireMainActivityRestart) { + restartMainActivity(this) + finishAffinity() + } else { + super.onBackPressed() + } + finishAndRemoveTask() } else { isCurrentViewMainSettings = true supportFragmentManager From 3f19d016f7374e817dc3d76a9f5c6423276f27b8 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 30 May 2022 22:23:44 +0200 Subject: [PATCH 2/2] ktlint --- app/src/main/java/com/github/libretube/SettingsActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt index 720f79306..8b0060f55 100644 --- a/app/src/main/java/com/github/libretube/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt @@ -28,13 +28,13 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.google.android.material.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder -import org.json.JSONObject -import org.json.JSONTokener -import retrofit2.HttpException import java.io.IOException import java.io.InputStream import java.util.zip.ZipEntry import java.util.zip.ZipInputStream +import org.json.JSONObject +import org.json.JSONTokener +import retrofit2.HttpException private var isCurrentViewMainSettings = true private var requireMainActivityRestart = false @@ -42,6 +42,7 @@ private var requireMainActivityRestart = false class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener { + override fun onCreate(savedInstanceState: Bundle?) { DynamicColors.applyToActivityIfAvailable(this) updateAccentColor(this)