From 95b558118a6003b813c957d4da12183a9bd5525f Mon Sep 17 00:00:00 2001 From: Sadwhy <99601717+Sadwhy@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:24:19 +0600 Subject: [PATCH] feat(settings): Smooth theme transitions (#514) --- app/src/main/java/ani/dantotsu/Functions.kt | 1 + .../ani/dantotsu/settings/SettingsThemeActivity.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index c41d22ced6..5c1f325519 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -314,6 +314,7 @@ fun Activity.reloadActivity() { Refresh.all() finish() startActivity(Intent(this, this::class.java)) + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) initActivity(this) } diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsThemeActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsThemeActivity.kt index 05ab6e4145..c315305b2a 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsThemeActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsThemeActivity.kt @@ -4,6 +4,8 @@ import android.content.ComponentName import android.content.Intent import android.os.Build import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter @@ -16,7 +18,6 @@ import ani.dantotsu.databinding.ActivitySettingsThemeBinding import ani.dantotsu.initActivity import ani.dantotsu.navBarHeight import ani.dantotsu.reloadActivity -import ani.dantotsu.restartApp import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.statusBarHeight @@ -73,7 +74,7 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi previous = current current.alpha = 1f PrefManager.setVal(PrefName.DarkMode, mode) - reloadActivity() + reload() } settingsUiAuto.setOnClickListener { @@ -210,7 +211,9 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi fun reload() { PrefManager.setCustomVal("reload", true) - restartApp() + Handler(Looper.getMainLooper()).postDelayed({ + reloadActivity() + finishAndRemoveTask() + }, 100) } - } \ No newline at end of file