Request permission
parent
a4d250168f
commit
e1b58ae6fb
|
@ -10,6 +10,7 @@ import android.view.KeyEvent
|
|||
import android.view.View
|
||||
import android.view.WindowInsetsController
|
||||
import android.webkit.*
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
|
@ -46,6 +47,9 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
// Initialize services
|
||||
mNativeX = NativeX(this)
|
||||
|
||||
// Ensure storage permissions
|
||||
ensureStoragePermissions()
|
||||
|
||||
// Load JavaScript
|
||||
initializeWebView()
|
||||
|
||||
|
@ -160,15 +164,31 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
// Load accounts
|
||||
val authHeader = mNativeX.mAccountService.authHeader
|
||||
val memoriesUrl = mNativeX.mAccountService.memoriesUrl
|
||||
|
||||
// Load app interface if authenticated
|
||||
if (authHeader != null && memoriesUrl != null) {
|
||||
binding.webview.loadUrl(memoriesUrl, mapOf(
|
||||
"Authorization" to authHeader
|
||||
))
|
||||
return true
|
||||
} else {
|
||||
binding.webview.loadUrl("file:///android_asset/welcome.html");
|
||||
return false
|
||||
}
|
||||
|
||||
// Load welcome page
|
||||
binding.webview.loadUrl("file:///android_asset/welcome.html");
|
||||
return false
|
||||
}
|
||||
|
||||
fun ensureStoragePermissions() {
|
||||
val requestPermissionLauncher =
|
||||
registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted && !hasMediaPermission()) {
|
||||
mNativeX.mQuery.syncFullDb()
|
||||
}
|
||||
setHasMediaPermission(isGranted)
|
||||
}
|
||||
requestPermissionLauncher.launch(android.Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
}
|
||||
|
||||
fun initializePlayer(uri: Uri, uid: String) {
|
||||
|
@ -268,4 +288,15 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
window.decorView.systemUiVisibility = if (isDark) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
}
|
||||
|
||||
fun hasMediaPermission(): Boolean {
|
||||
return getSharedPreferences(getString(R.string.preferences_key), 0)
|
||||
.getBoolean(getString(R.string.preferences_has_media_permission), false)
|
||||
}
|
||||
|
||||
private fun setHasMediaPermission(v: Boolean) {
|
||||
getSharedPreferences(getString(R.string.preferences_key), 0).edit()
|
||||
.putBoolean(getString(R.string.preferences_has_media_permission), v)
|
||||
.apply()
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ import java.net.URLDecoder
|
|||
val TAG = "NativeX"
|
||||
|
||||
private var themeStored = false
|
||||
private val mImageService = ImageService(mActivity)
|
||||
private val mQuery = TimelineQuery(mActivity)
|
||||
val mImageService = ImageService(mActivity)
|
||||
val mQuery = TimelineQuery(mActivity)
|
||||
val mAccountService = AccountService(mActivity)
|
||||
|
||||
object API {
|
||||
|
@ -41,8 +41,10 @@ import java.net.URLDecoder
|
|||
init {
|
||||
mDlService = DownloadService(mActivity)
|
||||
|
||||
// Synchronize the database
|
||||
mQuery.syncDeltaDb()
|
||||
// Synchronize the database if possible
|
||||
if (mActivity.hasMediaPermission()) {
|
||||
mQuery.syncDeltaDb()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<string name="preferences_theme_color">themeColor</string>
|
||||
<string name="preferences_theme_dark">themeDark</string>
|
||||
<string name="preferences_last_sync_time">lastDbSyncTime</string>
|
||||
<string name="preferences_has_media_permission">hasMediaPermission</string>
|
||||
|
||||
<!-- https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome -->
|
||||
<string name="ua_chrome">"Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.76 Mobile Safari/537.36"</string>
|
||||
|
|
Loading…
Reference in New Issue