diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-05 21:37:45 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-06 02:40:49 -0600 |
commit | 7db0fa915ef909ad33b9b29754e1fd1e7ed260a9 (patch) | |
tree | 77742b284864e2d875fc8b4be56842282e0e2746 /ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt | |
parent | tunnel: support IncludedApplications as whitelist (diff) | |
download | wireguard-android-7db0fa915ef909ad33b9b29754e1fd1e7ed260a9.tar.xz wireguard-android-7db0fa915ef909ad33b9b29754e1fd1e7ed260a9.zip |
AppListDialogFragment: support both inclusion and exclusion
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt index 2e1e4531..dc1b8aa2 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt @@ -23,7 +23,7 @@ import com.wireguard.android.Application import com.wireguard.android.R import com.wireguard.android.backend.Tunnel import com.wireguard.android.databinding.TunnelEditorFragmentBinding -import com.wireguard.android.fragment.AppListDialogFragment.AppExclusionListener +import com.wireguard.android.fragment.AppListDialogFragment.AppSelectionListener import com.wireguard.android.model.ObservableTunnel import com.wireguard.android.util.BiometricAuthenticator import com.wireguard.android.util.ErrorMessages @@ -35,7 +35,7 @@ import com.wireguard.config.Config /** * Fragment for editing a WireGuard configuration. */ -class TunnelEditorFragment : BaseFragment(), AppExclusionListener { +class TunnelEditorFragment : BaseFragment(), AppSelectionListener { private var haveShownKeys = false private var binding: TunnelEditorFragmentBinding? = null private var tunnel: ObservableTunnel? = null @@ -88,11 +88,20 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { super.onDestroyView() } - override fun onExcludedAppsSelected(excludedApps: List<String>) { - requireNotNull(binding) { "Tried to set excluded apps while no view was loaded" } - binding!!.config!!.`interface`.excludedApplications.apply { - clear() - addAll(excludedApps) + override fun onSelectedAppsSelected(selectedApps: List<String>, isExcluded: Boolean) { + requireNotNull(binding) { "Tried to set excluded/included apps while no view was loaded" } + if (isExcluded) { + binding!!.config!!.`interface`.includedApplications.clear() + binding!!.config!!.`interface`.excludedApplications.apply { + clear() + addAll(selectedApps) + } + } else { + binding!!.config!!.`interface`.excludedApplications.clear() + binding!!.config!!.`interface`.includedApplications.apply { + clear() + addAll(selectedApps) + } } } @@ -150,10 +159,16 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { } @Suppress("UNUSED_PARAMETER") - fun onRequestSetExcludedApplications(view: View?) { + fun onRequestSetExcludedIncludedApplications(view: View?) { if (binding != null) { - val excludedApps = ArrayList(binding!!.config!!.`interface`.excludedApplications) - val fragment = AppListDialogFragment.newInstance(excludedApps, this) + var isExcluded = true + var selectedApps = ArrayList(binding!!.config!!.`interface`.excludedApplications) + if (selectedApps.isEmpty()) { + selectedApps = ArrayList(binding!!.config!!.`interface`.includedApplications) + if (selectedApps.isNotEmpty()) + isExcluded = false + } + val fragment = AppListDialogFragment.newInstance(selectedApps, isExcluded, this) fragment.show(parentFragmentManager, null) } } |