[Android] Prpoperly exit headless fragments
Geoffrey Métais
git at videolan.org
Wed Jan 23 11:35:25 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 23 11:34:59 2019 +0100| [5354d5e85e9af15a1c6c20a4cae01cf0f14e0f4e] | committer: Geoffrey Métais
Prpoperly exit headless fragments
> https://code.videolan.org/videolan/vlc-android/commit/5354d5e85e9af15a1c6c20a4cae01cf0f14e0f4e
---
.../videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt | 1 +
.../vlc/gui/helpers/hf/StoragePermissionsDelegate.kt | 16 +++++++++-------
.../videolan/vlc/gui/helpers/hf/WriteExternalDelegate.kt | 9 ++++++---
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
index 91391f886..59b08667f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
@@ -37,6 +37,7 @@ open class BaseHeadlessFragment : Fragment() {
}
protected fun exit() {
+ retainInstance = false
activity?.run {
if (!isFinishing) supportFragmentManager
.beginTransaction()
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
index 3eebe2dfb..a1fe03593 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
@@ -72,8 +72,9 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
}
private fun requestStorageAccess(write: Boolean) {
- requestPermissions(arrayOf(if (write) Manifest.permission.WRITE_EXTERNAL_STORAGE else Manifest.permission.READ_EXTERNAL_STORAGE),
- if (write) Permissions.PERMISSION_WRITE_STORAGE_TAG else Permissions.PERMISSION_STORAGE_TAG)
+ val code = if (write) Manifest.permission.WRITE_EXTERNAL_STORAGE else Manifest.permission.READ_EXTERNAL_STORAGE
+ val tag = if (write) Permissions.PERMISSION_WRITE_STORAGE_TAG else Permissions.PERMISSION_STORAGE_TAG
+ requestPermissions(arrayOf(code), tag)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
@@ -85,20 +86,21 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
storageAccessGranted.value = true
deferredGrant.complete(true)
exit()
+ return
} else {
if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) {
Permissions.showStoragePermissionDialog(ctx, false)
return
- } else {
- storageAccessGranted.value = false
- deferredGrant.complete(false)
- exit()
}
}
storageAccessGranted.value = false
deferredGrant.complete(false)
+ exit()
+ }
+ Permissions.PERMISSION_WRITE_STORAGE_TAG -> {
+ deferredGrant.complete(grantResults.isGranted())
+ exit()
}
- Permissions.PERMISSION_WRITE_STORAGE_TAG -> deferredGrant.complete(grantResults.isGranted())
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/WriteExternalDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/WriteExternalDelegate.kt
index 68e5a9261..b604d77e7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/WriteExternalDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/WriteExternalDelegate.kt
@@ -7,10 +7,10 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.DocumentsContract
-import androidx.fragment.app.FragmentActivity
-import androidx.documentfile.provider.DocumentFile
-import androidx.appcompat.app.AlertDialog
import android.text.TextUtils
+import androidx.appcompat.app.AlertDialog
+import androidx.documentfile.provider.DocumentFile
+import androidx.fragment.app.FragmentActivity
import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.vlc.R
@@ -73,6 +73,7 @@ class WriteExternalDelegate : BaseHeadlessFragment() {
if (treeFile?.name == file?.name) {
contentResolver.releasePersistableUriPermission(uriPermission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
deferredGrant.complete(false)
+ exit()
return
}
}
@@ -80,10 +81,12 @@ class WriteExternalDelegate : BaseHeadlessFragment() {
// else set permission
contentResolver.takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
deferredGrant.complete(true)
+ exit()
return
}
}
deferredGrant.complete(false)
+ exit()
}
companion object {
More information about the Android
mailing list