UX improvements

pull/653/merge
Varun Patil 2023-05-14 22:16:11 -07:00
parent e8c59d7648
commit 9488a2bc7d
4 changed files with 45 additions and 22 deletions

View File

@ -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
}
}
}

View File

@ -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)
}
}

View File

@ -12,6 +12,7 @@
android:layout_height="match_parent"
android:background="@android:color/black"
app:show_buffering="always"
android:alpha="0.0"
/>
<WebView

View File

@ -1,12 +1,6 @@
<resources>
<string name="app_name">Memories</string>
<string name="action_settings">Settings</string>
<!-- Strings used for fragments for navigation -->
<string name="first_fragment_label">First Fragment</string>
<string name="second_fragment_label">Second Fragment</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="preferences_key">memories</string>
</resources>