fix: double setting page in theme settings

This commit is contained in:
aayush262 2024-04-21 21:46:36 +05:30
parent 3fd01d582a
commit d2127f92a1

View file

@ -27,7 +27,7 @@ import eltos.simpledialogfragment.color.SimpleColorDialog
class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListener { class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListener {
private lateinit var binding: ActivitySettingsThemeBinding private lateinit var binding: ActivitySettingsThemeBinding
private var reload = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
@ -41,16 +41,22 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi
bottomMargin = navBarHeight bottomMargin = navBarHeight
} }
onBackPressedDispatcher.addCallback(context) { onBackPressedDispatcher.addCallback(context) {
val mainIntent = Intent.makeRestartActivityTask( if (reload) {
packageManager.getLaunchIntentForPackage(packageName)!!.component val packageName = context.packageName
) val mainIntent = Intent.makeRestartActivityTask(
val component = ComponentName(packageName, SettingsActivity::class.qualifiedName!!) packageManager.getLaunchIntentForPackage(packageName)!!.component
try { )
startActivity(Intent().setComponent(component)) val component = ComponentName(packageName, SettingsActivity::class.qualifiedName!!)
} catch (anything: Exception) { try {
startActivity(mainIntent) startActivity(Intent().setComponent(component))
} catch (e: Exception) {
startActivity(mainIntent)
}
finishAndRemoveTask()
reload = false
} else {
finish()
} }
finishAndRemoveTask()
} }
themeSettingsBack.setOnClickListener { themeSettingsBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed() onBackPressedDispatcher.onBackPressed()
@ -205,6 +211,7 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi
fun reload() { fun reload() {
PrefManager.setCustomVal("reload", true) PrefManager.setCustomVal("reload", true)
restartApp() restartApp()
reload = true
} }
} }