UX improvements
parent
a2765eef60
commit
15784416eb
|
@ -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,15 +76,38 @@ 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
|
||||||
|
if (request.url.path?.matches(memoriesRegex) == true) {
|
||||||
return false
|
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? {
|
||||||
return if (request.url.host == "127.0.0.1") {
|
return if (request.url.host == "127.0.0.1") {
|
||||||
mNativeX.handleRequest(request)
|
mNativeX.handleRequest(request)
|
||||||
|
|
Loading…
Reference in New Issue