tv: account for broken TVs with no file picker

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-09-22 23:54:01 +02:00
parent a978aac129
commit c536bbb7e9
2 changed files with 8 additions and 1 deletions
@@ -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())