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 290e14a4..70165a26 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 { 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) diff --git a/ui/src/main/res/layout/tv_activity.xml b/ui/src/main/res/layout/tv_activity.xml index 4ca5f839..8a544258 100644 --- a/ui/src/main/res/layout/tv_activity.xml +++ b/ui/src/main/res/layout/tv_activity.xml @@ -4,9 +4,14 @@ xmlns:tools="http://schemas.android.com/tools"> + + + @@ -43,8 +48,20 @@ android:layout_height="wrap_content" android:layout_margin="16dp" android:text="@string/create_from_file" + android:visibility="@{isDeleting ? View.GONE : View.VISIBLE}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> + + + \ No newline at end of file diff --git a/ui/src/main/res/layout/tv_tunnel_list_item.xml b/ui/src/main/res/layout/tv_tunnel_list_item.xml index 4d2a943c..c5dd6c37 100644 --- a/ui/src/main/res/layout/tv_tunnel_list_item.xml +++ b/ui/src/main/res/layout/tv_tunnel_list_item.xml @@ -5,10 +5,16 @@ + + + + @@ -18,15 +24,16 @@ type="com.wireguard.android.model.ObservableTunnel" /> + + app:cardCornerRadius="12dp"> + + + diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 63703ad6..6f4d935a 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -101,6 +101,7 @@ Currently using dark (night) theme Use dark theme Delete + Select tunnel to delete Disable config exporting Disabling config exporting makes private keys less accessible DNS servers