aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/main/java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-09-22 16:28:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-22 23:53:44 +0200
commit9df8e5e239a298d1b17ce2486af5277b53c35411 (patch)
tree41c970e8b228982a559a5ee8a3bd8676f1a71a44 /ui/src/main/java
parenttv: wire in stats (diff)
downloadwireguard-android-9df8e5e239a298d1b17ce2486af5277b53c35411.tar.xz
wireguard-android-9df8e5e239a298d1b17ce2486af5277b53c35411.zip
tv: add ugly deletion mode
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, 26 insertions, 8 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 290e14a..70165a2 100644
--- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
@@ -13,6 +13,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.forEach
import androidx.databinding.DataBindingUtil
+import androidx.databinding.ObservableBoolean
import androidx.lifecycle.lifecycleScope
import com.wireguard.android.Application
import com.wireguard.android.R
@@ -65,19 +66,33 @@ class TvMainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = TvActivityBinding.inflate(layoutInflater)
lifecycleScope.launch { binding.tunnels = Application.getTunnelManager().getTunnels() }
+ val isDeleting = ObservableBoolean()
+ binding.isDeleting = isDeleting
binding.rowConfigurationHandler = object : ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler<TvTunnelListItemBinding, ObservableTunnel> {
override fun onConfigureRow(binding: TvTunnelListItemBinding, item: ObservableTunnel, position: Int) {
- binding.root.setOnClickListener() {
+ binding.isDeleting = isDeleting
+ binding.root.setOnClickListener {
lifecycleScope.launch {
- if (Application.getBackend() is GoBackend) {
- val intent = GoBackend.VpnService.prepare(binding.root.context)
- if (intent != null) {
- pendingTunnel = item
- permissionActivityResultLauncher.launch(intent)
- return@launch
+ if (isDeleting.get()) {
+ try {
+ item.deleteAsync()
+ } catch (e: Throwable) {
+ val error = ErrorMessages[e]
+ val message = getString(R.string.config_delete_error, error)
+ Toast.makeText(this@TvMainActivity, message, Toast.LENGTH_LONG).show()
+ Log.e(TAG, message, e)
}
+ } else {
+ if (Application.getBackend() is GoBackend) {
+ val intent = GoBackend.VpnService.prepare(binding.root.context)
+ if (intent != null) {
+ pendingTunnel = item
+ permissionActivityResultLauncher.launch(intent)
+ return@launch
+ }
+ }
+ setTunnelStateWithPermissionsResult(item)
}
- setTunnelStateWithPermissionsResult(item)
}
}
}
@@ -85,6 +100,9 @@ class TvMainActivity : AppCompatActivity() {
binding.importButton.setOnClickListener {
tunnelFileImportResultLauncher.launch("*/*")
}
+ binding.deleteButton.setOnClickListener {
+ isDeleting.set(!isDeleting.get())
+ }
binding.executePendingBindings()
setContentView(binding.root)