[Android] Create a PinCodeDelegate to check the PIN code
Nicolas Pomepuy
git at videolan.org
Wed Jul 12 08:30:36 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 27 10:09:23 2023 +0200| [9965c80e2bc98ddf4bcb6928e492393f6bb7bde5] | committer: Duncan McNamara
Create a PinCodeDelegate to check the PIN code
> https://code.videolan.org/videolan/vlc-android/commit/9965c80e2bc98ddf4bcb6928e492393f6bb7bde5
---
.../videolan/vlc/gui/helpers/hf/PinCodeDelegate.kt | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/PinCodeDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/PinCodeDelegate.kt
new file mode 100644
index 0000000000..671e4a63c6
--- /dev/null
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/PinCodeDelegate.kt
@@ -0,0 +1,40 @@
+package org.videolan.vlc.gui.helpers.hf
+
+import android.annotation.TargetApi
+import android.app.Activity
+import android.os.Build
+import android.os.Bundle
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.activity.viewModels
+import androidx.fragment.app.FragmentActivity
+import org.videolan.tools.Settings
+import org.videolan.vlc.gui.PinCodeActivity
+import org.videolan.vlc.gui.PinCodeReason
+
+class PinCodeDelegate : BaseHeadlessFragment() {
+ var pinCodeResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
+ model.complete(result.resultCode == Activity.RESULT_OK)
+ exit()
+ }
+
+ @TargetApi(Build.VERSION_CODES.O)
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val intent = PinCodeActivity.getIntent(requireActivity(), PinCodeReason.CHECK)
+ pinCodeResult.launch(intent)
+ }
+
+ companion object {
+ internal const val TAG = "VLC/PinCode"
+ }
+}
+
+suspend fun FragmentActivity.checkPIN() : Boolean {
+ if (!Settings.safeMode) return true
+ val model : PermissionViewmodel by viewModels()
+ val fragment = PinCodeDelegate()
+ model.setupDeferred()
+ supportFragmentManager.beginTransaction().add(fragment, PinCodeDelegate.TAG).commitAllowingStateLoss()
+ return model.deferredGrant.await()
+}
+
More information about the Android
mailing list