diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-22 18:17:11 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-22 23:54:01 +0200 |
commit | c536bbb7e9105045349af5fc597bae9d5b1001de (patch) | |
tree | 01c295c79143c3d73a406c58add83fcc13eb1484 /ui/src/main | |
parent | a978aac129b972cf8b7e2191104ec5057a4b084b (diff) |
tv: account for broken TVs with no file picker
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt | 8 | ||||
-rw-r--r-- | ui/src/main/res/values/strings.xml | 1 |
2 files changed, 8 insertions, 1 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 7e3d425d..7b93f563 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt @@ -5,6 +5,7 @@ package com.wireguard.android.activity +import android.content.ActivityNotFoundException import android.os.Bundle import android.util.Log import android.view.View @@ -31,6 +32,7 @@ import kotlinx.coroutines.launch 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() @@ -98,7 +100,11 @@ class TvMainActivity : AppCompatActivity() { } } binding.importButton.setOnClickListener { - tunnelFileImportResultLauncher.launch("*/*") + try { + tunnelFileImportResultLauncher.launch("*/*") + } catch (e: ActivityNotFoundException) { + Toast.makeText(this@TvMainActivity, getString(R.string.tv_error), Toast.LENGTH_LONG).show() + } } binding.deleteButton.setOnClickListener { isDeleting.set(!isDeleting.get()) diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 6f4d935a..0bcadbca 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -102,6 +102,7 @@ <string name="dark_theme_title">Use dark theme</string> <string name="delete">Delete</string> <string name="tv_delete">Select tunnel to delete</string> + <string name="tv_error">Your TV does not have a file picker</string> <string name="disable_config_export_title">Disable config exporting</string> <string name="disable_config_export_description">Disabling config exporting makes private keys less accessible</string> <string name="dns_servers">DNS servers</string> |