Fix recreate activity loop in kitkat

This commit is contained in:
J-Jamet
2021-08-20 20:44:54 +02:00
parent 041583bf96
commit c179ac626a
3 changed files with 28 additions and 9 deletions

View File

@@ -22,6 +22,8 @@ package com.kunzisoft.keepass.activities.stylish
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.WindowManager
import androidx.annotation.StyleRes
@@ -90,7 +92,12 @@ abstract class StylishActivity : AppCompatActivity() {
|| DATABASE_APPEARANCE_PREFERENCE_CHANGED) {
DATABASE_APPEARANCE_PREFERENCE_CHANGED = false
Log.d(this.javaClass.name, "Theme change detected, restarting activity")
this.recreate()
recreateActivity()
}
}
private fun recreateActivity() {
// To prevent KitKat bugs
Handler(Looper.getMainLooper()).post { recreate() }
}
}

View File

@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.icons
import android.content.Context
import android.util.Log
import com.kunzisoft.keepass.BuildConfig
import com.kunzisoft.keepass.settings.NestedAppSettingsFragment.Companion.DATABASE_APPEARANCE_PREFERENCE_CHANGED
import com.kunzisoft.keepass.settings.PreferencesUtil
import java.util.*
@@ -93,11 +92,6 @@ object IconPackChooser {
fun setSelectedIconPack(iconPackIdString: String?) {
for (iconPack in iconPackList) {
if (iconPack.id == iconPackIdString) {
// To change list items appearance
if (iconPackSelected != null
&& iconPackSelected != iconPack) {
DATABASE_APPEARANCE_PREFERENCE_CHANGED = true
}
iconPackSelected = iconPack
break
}

View File

@@ -392,8 +392,6 @@ class NestedAppSettingsFragment : NestedSettingsFragment() {
private fun onCreateAppearancePreferences(rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_appearance, rootKey)
DATABASE_APPEARANCE_PREFERENCE_CHANGED = true
activity?.let { activity ->
findPreference<ListPreference>(getString(R.string.setting_style_key))?.setOnPreferenceChangeListener { _, newValue ->
var styleEnabled = true
@@ -455,6 +453,26 @@ class NestedAppSettingsFragment : NestedSettingsFragment() {
}
}
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
// To reload group when appearence settings are modified
when (preference?.key) {
getString(R.string.setting_style_key),
getString(R.string.setting_style_brightness_key),
getString(R.string.setting_icon_pack_choose_key),
getString(R.string.list_entries_show_username_key),
getString(R.string.list_groups_show_number_entries_key),
getString(R.string.list_size_key),
getString(R.string.monospace_font_fields_enable_key),
getString(R.string.hide_expired_entries_key),
getString(R.string.show_uuid_key),
getString(R.string.enable_education_screens_key),
getString(R.string.reset_education_screens_key) -> {
DATABASE_APPEARANCE_PREFERENCE_CHANGED = true
}
}
return super.onPreferenceTreeClick(preference)
}
override fun onDisplayPreferenceDialog(preference: Preference?) {
var otherDialogFragment = false