UX improvements

pull/653/merge
Varun Patil 2023-05-14 19:04:46 -07:00
parent a2765eef60
commit 15784416eb
1 changed files with 29 additions and 2 deletions

View File

@ -1,9 +1,11 @@
package gallery.memories package gallery.memories
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent
import android.view.View import android.view.View
import android.webkit.* import android.webkit.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -30,6 +32,8 @@ import gallery.memories.databinding.ActivityMainBinding
private var mediaItemIndex = 0 private var mediaItemIndex = 0
private var playbackPosition = 0L private var playbackPosition = 0L
private val memoriesRegex = Regex("/apps/memories/.*$")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(binding.root) setContentView(binding.root)
@ -72,13 +76,36 @@ import gallery.memories.databinding.ActivityMainBinding
} }
} }
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
if (binding.webview.canGoBack()) {
binding.webview.goBack()
} else {
finish()
}
return true
}
}
}
return super.onKeyDown(keyCode, event)
}
@SuppressLint("SetJavaScriptEnabled", "ClickableViewAccessibility") @SuppressLint("SetJavaScriptEnabled", "ClickableViewAccessibility")
private fun initializeWebView() { private fun initializeWebView() {
// Intercept local APIs // Intercept local APIs
binding.webview.webViewClient = object : WebViewClient() { binding.webview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean { override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
view.loadUrl(request.url.toString()) // TODO: check host as well
return false if (request.url.path?.matches(memoriesRegex) == true) {
return false
}
// Open external links in browser
Intent(Intent.ACTION_VIEW, request.url).apply { startActivity(this) }
return true
} }
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {