diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-03 00:47:17 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-15 12:52:17 +0000 |
| commit | 7ee745f779884571b9c89f906601800ced971c47 (patch) | |
| tree | f97404976faf3a23d36f58e69941237ffc0e2199 /android/src | |
| parent | 83b52e32a9ed85823cd606d3c31928933aadcd70 (diff) | |
| download | mullvadvpn-7ee745f779884571b9c89f906601800ced971c47.tar.xz mullvadvpn-7ee745f779884571b9c89f906601800ced971c47.zip | |
Hide list when split tunnelling is disabled
Diffstat (limited to 'android/src')
3 files changed, 39 insertions, 2 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/applist/AppListAdapter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/applist/AppListAdapter.kt index 769d39417e..eca49631e9 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/applist/AppListAdapter.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/applist/AppListAdapter.kt @@ -4,6 +4,7 @@ import android.content.Context import android.support.v7.widget.RecyclerView.Adapter import android.view.LayoutInflater import android.view.ViewGroup +import kotlin.properties.Delegates.observable import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.util.JobTracker @@ -12,13 +13,23 @@ class AppListAdapter(context: Context) : Adapter<AppListItemHolder>() { private val jobTracker = JobTracker() private val packageManager = context.packageManager + var enabled by observable(false) { _, oldValue, newValue -> + if (oldValue != newValue) { + if (newValue == true) { + notifyItemRangeInserted(0, appList.size) + } else { + notifyItemRangeRemoved(0, appList.size) + } + } + } + init { jobTracker.newBackgroundJob("populateAppList") { populateAppList(context) } } - override fun getItemCount() = appList.size + override fun getItemCount() = if (enabled) { appList.size } else { 0 } override fun onCreateViewHolder(parentView: ViewGroup, type: Int): AppListItemHolder { val inflater = LayoutInflater.from(parentView.context) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnellingFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnellingFragment.kt index a4e6bf2ded..91cee326b8 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnellingFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnellingFragment.kt @@ -15,6 +15,8 @@ class SplitTunnellingFragment : ServiceDependentFragment(OnNoService.GoToLaunchS private lateinit var appListAdapter: AppListAdapter private lateinit var titleController: CollapsibleTitleController + private lateinit var excludeApplications: View + override fun onAttach(context: Context) { super.onAttach(context) @@ -39,6 +41,7 @@ class SplitTunnellingFragment : ServiceDependentFragment(OnNoService.GoToLaunchS adapter = AdapterWithHeader(appListAdapter, R.layout.split_tunnelling_header).apply { onHeaderAvailable = { headerView -> + configureHeader(headerView) titleController.expandedTitleView = headerView.findViewById(R.id.expanded_title) } } @@ -52,4 +55,25 @@ class SplitTunnellingFragment : ServiceDependentFragment(OnNoService.GoToLaunchS override fun onSafelyDestroyView() { titleController.onDestroy() } + + private fun configureHeader(header: View) { + excludeApplications = header.findViewById(R.id.exclude_applications) + + header.findViewById<CellSwitch>(R.id.enabled_toggle).listener = { toggleState -> + when (toggleState) { + CellSwitch.State.ON -> enable() + CellSwitch.State.OFF -> disable() + } + } + } + + private fun enable() { + appListAdapter.enabled = true + excludeApplications.visibility = View.VISIBLE + } + + private fun disable() { + appListAdapter.enabled = false + excludeApplications.visibility = View.GONE + } } diff --git a/android/src/main/res/layout/split_tunnelling_header.xml b/android/src/main/res/layout/split_tunnelling_header.xml index 93be03e279..48d3e6e831 100644 --- a/android/src/main/res/layout/split_tunnelling_header.xml +++ b/android/src/main/res/layout/split_tunnelling_header.xml @@ -42,11 +42,13 @@ android:layout_height="32dp" android:layout_weight="0" /> </LinearLayout> - <LinearLayout android:layout_width="match_parent" + <LinearLayout android:id="@+id/exclude_applications" + android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:paddingHorizontal="16dp" android:background="@drawable/cell_button_background" + android:visibility="gone" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" |
