summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-09-23 14:37:15 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-23 17:56:37 +0200
commit15da17b5952a76a52089a5d7b503e60b43a7ca50 (patch)
tree0125b563ff70a83d0a5023b811bf089ee8f4b8bb /ui/src/main/java
parentb3c43e428f98a3b9b32e404ca7ff958d2f05b03b (diff)
tv: use system picker for API 29+
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java')
-rw-r--r--ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt34
1 files changed, 24 insertions, 10 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
index 004d26e0..32fbe387 100644
--- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
@@ -46,6 +46,14 @@ import kotlinx.coroutines.withContext
import java.io.File
class TvMainActivity : AppCompatActivity() {
+ private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { data ->
+ if (data == null) return@registerForActivityResult
+ lifecycleScope.launch {
+ TunnelImporter.importTunnel(contentResolver, data) {
+ Toast.makeText(this@TvMainActivity, it, Toast.LENGTH_LONG).show()
+ }
+ }
+ }
private var pendingTunnel: ObservableTunnel? = null
private val permissionActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
val tunnel = pendingTunnel
@@ -145,16 +153,22 @@ class TvMainActivity : AppCompatActivity() {
}
binding.importButton.setOnClickListener {
- if (filesRoot.get()?.isEmpty() != false) {
- navigateTo(myComputerFile)
- runOnUiThread {
- binding.filesList.requestFocus()
- }
- } else {
- files.clear()
- filesRoot.set("")
- runOnUiThread {
- binding.tunnelList.requestFocus()
+ try {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
+ throw Exception()
+ tunnelFileImportResultLauncher.launch("*/*")
+ } catch (_: Throwable) {
+ if (filesRoot.get()?.isEmpty() != false) {
+ navigateTo(myComputerFile)
+ runOnUiThread {
+ binding.filesList.requestFocus()
+ }
+ } else {
+ files.clear()
+ filesRoot.set("")
+ runOnUiThread {
+ binding.tunnelList.requestFocus()
+ }
}
}
}