@@ -46,6 +46,14 @@ import kotlinx.coroutines.withContext
46
46
import java.io.File
47
47
48
48
class TvMainActivity : AppCompatActivity () {
49
+ private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts .GetContent ()) { data ->
50
+ if (data == null ) return @registerForActivityResult
51
+ lifecycleScope.launch {
52
+ TunnelImporter .importTunnel(contentResolver, data) {
53
+ Toast .makeText(this @TvMainActivity, it, Toast .LENGTH_LONG ).show()
54
+ }
55
+ }
56
+ }
49
57
private var pendingTunnel: ObservableTunnel ? = null
50
58
private val permissionActivityResultLauncher = registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) {
51
59
val tunnel = pendingTunnel
@@ -145,16 +153,22 @@ class TvMainActivity : AppCompatActivity() {
145
153
}
146
154
147
155
binding.importButton.setOnClickListener {
148
- if (filesRoot.get()?.isEmpty() != false ) {
149
- navigateTo(myComputerFile)
150
- runOnUiThread {
151
- binding.filesList.requestFocus()
152
- }
153
- } else {
154
- files.clear()
155
- filesRoot.set(" " )
156
- runOnUiThread {
157
- binding.tunnelList.requestFocus()
156
+ try {
157
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .Q )
158
+ throw Exception ()
159
+ tunnelFileImportResultLauncher.launch(" */*" )
160
+ } catch (_: Throwable ) {
161
+ if (filesRoot.get()?.isEmpty() != false ) {
162
+ navigateTo(myComputerFile)
163
+ runOnUiThread {
164
+ binding.filesList.requestFocus()
165
+ }
166
+ } else {
167
+ files.clear()
168
+ filesRoot.set(" " )
169
+ runOnUiThread {
170
+ binding.tunnelList.requestFocus()
171
+ }
158
172
}
159
173
}
160
174
}
0 commit comments