diff --git a/app/src/main/java/gallery/memories/MainActivity.kt b/app/src/main/java/gallery/memories/MainActivity.kt index 91e8628d..c70968d3 100644 --- a/app/src/main/java/gallery/memories/MainActivity.kt +++ b/app/src/main/java/gallery/memories/MainActivity.kt @@ -4,9 +4,11 @@ import android.annotation.SuppressLint import android.content.Intent import android.graphics.Color import android.net.Uri +import android.os.Build import android.os.Bundle import android.view.KeyEvent import android.view.View +import android.view.WindowInsetsController import android.webkit.* import androidx.appcompat.app.AppCompatActivity import androidx.media3.common.MediaItem @@ -38,6 +40,9 @@ import gallery.memories.databinding.ActivityMainBinding super.onCreate(savedInstanceState) setContentView(binding.root) + // Restore last known look + restoreTheme() + // Initialize services mNativeX = NativeX(this) @@ -47,6 +52,7 @@ import gallery.memories.databinding.ActivityMainBinding // Destroy video after 1 seconds (workaround for video not showing on first load) binding.videoView.postDelayed({ binding.videoView.visibility = View.GONE + binding.videoView.alpha = 1.0f }, 1000) } @@ -207,4 +213,32 @@ import gallery.memories.databinding.ActivityMainBinding player = null binding.videoView.visibility = View.GONE } + + fun storeTheme(color: String?, isDark: Boolean) { + if (color == null) return + getSharedPreferences(getString(R.string.preferences_key), 0).edit() + .putString("themeColor", color) + .putBoolean("themeDark", isDark) + .apply() + } + + fun restoreTheme() { + val preferences = getSharedPreferences(getString(R.string.preferences_key), 0) + val color = preferences.getString("themeColor", null) + val isDark = preferences.getBoolean("themeDark", false) + applyTheme(color, isDark) + } + + fun applyTheme(color: String?, isDark: Boolean) { + if (color == null) return + setTheme(if (isDark) android.R.style.Theme_Black else android.R.style.Theme_Light) + window.navigationBarColor = Color.parseColor(color) + window.statusBarColor = Color.parseColor(color) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val appearance = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + window.insetsController?.setSystemBarsAppearance(if (isDark) 0 else appearance, appearance) + } else { + window.decorView.systemUiVisibility = if (isDark) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } + } } \ No newline at end of file diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index d3e9fdd3..df9b0ac4 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -1,13 +1,8 @@ package gallery.memories -import android.R -import android.graphics.Color import android.net.Uri -import android.os.Build import android.util.Log import android.view.SoundEffectConstants -import android.view.View -import android.view.WindowInsetsController import android.webkit.JavascriptInterface import android.webkit.WebResourceRequest import android.webkit.WebResourceResponse @@ -24,6 +19,7 @@ import java.net.URLDecoder private val mImageService: ImageService = ImageService(mActivity) private val mQuery: TimelineQuery = TimelineQuery(mActivity) + private var themeStored = false object API { val DAYS = Regex("^/api/days$") @@ -91,17 +87,15 @@ import java.net.URLDecoder @JavascriptInterface fun setThemeColor(color: String?, isDark: Boolean) { + // Save for getting it back on next start + if (!themeStored) { + themeStored = true + mActivity.storeTheme(color, isDark); + } + + // Apply the theme mActivity.runOnUiThread { - val window = mActivity.window - mActivity.setTheme(if (isDark) R.style.Theme_Black else R.style.Theme_Light) - window.navigationBarColor = Color.parseColor(color) - window.statusBarColor = Color.parseColor(color) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - val appearance = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS - window.insetsController?.setSystemBarsAppearance(if (isDark) 0 else appearance, appearance) - } else { - window.decorView.systemUiVisibility = if (isDark) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } + mActivity.applyTheme(color, isDark) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7edf6d3c..fc2a496e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,6 +12,7 @@ android:layout_height="match_parent" android:background="@android:color/black" app:show_buffering="always" + android:alpha="0.0" /> Memories Settings - - First Fragment - Second Fragment - Next - Previous - Hello first fragment - Hello second fragment. Arg: %1$s + memories \ No newline at end of file