tv: use system picker for API 29+
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b3c43e428f
commit
15da17b595
@ -46,6 +46,14 @@ import kotlinx.coroutines.withContext
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class TvMainActivity : AppCompatActivity() {
|
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 var pendingTunnel: ObservableTunnel? = null
|
||||||
private val permissionActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
private val permissionActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
val tunnel = pendingTunnel
|
val tunnel = pendingTunnel
|
||||||
@ -145,16 +153,22 @@ class TvMainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.importButton.setOnClickListener {
|
binding.importButton.setOnClickListener {
|
||||||
if (filesRoot.get()?.isEmpty() != false) {
|
try {
|
||||||
navigateTo(myComputerFile)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
runOnUiThread {
|
throw Exception()
|
||||||
binding.filesList.requestFocus()
|
tunnelFileImportResultLauncher.launch("*/*")
|
||||||
}
|
} catch (_: Throwable) {
|
||||||
} else {
|
if (filesRoot.get()?.isEmpty() != false) {
|
||||||
files.clear()
|
navigateTo(myComputerFile)
|
||||||
filesRoot.set("")
|
runOnUiThread {
|
||||||
runOnUiThread {
|
binding.filesList.requestFocus()
|
||||||
binding.tunnelList.requestFocus()
|
}
|
||||||
|
} else {
|
||||||
|
files.clear()
|
||||||
|
filesRoot.set("")
|
||||||
|
runOnUiThread {
|
||||||
|
binding.tunnelList.requestFocus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user