diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-04-06 15:48:12 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-04-06 19:56:46 +0530 |
commit | 2c625f56fdebd0877d5c7dfca5261c0b594d588e (patch) | |
tree | 1def1d693b5d3056a48b33c4b08725ca734c6733 /ui/src/main/java/com/wireguard/android/fragment | |
parent | 7db0fa915ef909ad33b9b29754e1fd1e7ed260a9 (diff) |
ui: misc cleanups to AppListDialogFragment
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/fragment')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/AddTunnelsSheet.kt | 6 | ||||
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt | 22 |
2 files changed, 14 insertions, 14 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/AddTunnelsSheet.kt b/ui/src/main/java/com/wireguard/android/fragment/AddTunnelsSheet.kt index fe3eca3f..17bdac04 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/AddTunnelsSheet.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/AddTunnelsSheet.kt @@ -12,13 +12,13 @@ import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.widget.FrameLayout -import androidx.fragment.app.Fragment import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.zxing.integration.android.IntentIntegrator import com.wireguard.android.R import com.wireguard.android.activity.TunnelCreatorActivity +import com.wireguard.android.util.requireTargetFragment import com.wireguard.android.util.resolveAttribute class AddTunnelsSheet : BottomSheetDialogFragment() { @@ -81,10 +81,6 @@ class AddTunnelsSheet : BottomSheetDialogFragment() { behavior?.removeBottomSheetCallback(bottomSheetCallback) } - private fun requireTargetFragment(): Fragment { - return requireNotNull(targetFragment) { "A target fragment should always be set" } - } - private fun onRequestCreateConfig() { startActivity(Intent(activity, TunnelCreatorActivity::class.java)) } diff --git a/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt index 4fdebd16..35bd3ce9 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.kt @@ -21,11 +21,12 @@ import com.wireguard.android.databinding.AppListDialogFragmentBinding import com.wireguard.android.databinding.ObservableKeyedArrayList import com.wireguard.android.model.ApplicationData import com.wireguard.android.util.ErrorMessages +import com.wireguard.android.util.requireTargetFragment class AppListDialogFragment : DialogFragment() { - private val appData: ObservableKeyedArrayList<String, ApplicationData> = ObservableKeyedArrayList() + private val appData = ObservableKeyedArrayList<String, ApplicationData>() private var currentlySelectedApps = emptyList<String>() - private var initiallyExcluded: Boolean = false + private var initiallyExcluded = false private var button: Button? = null private var tabs: TabLayout? = null @@ -65,6 +66,7 @@ class AppListDialogFragment : DialogFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + require(requireTargetFragment() is AppSelectionListener) { "${requireTargetFragment()} must implement AppSelectionListener" } currentlySelectedApps = (arguments?.getStringArrayList(KEY_SELECTED_APPS) ?: emptyList()) initiallyExcluded = arguments?.getBoolean(KEY_IS_EXCLUDED) ?: true } @@ -86,12 +88,14 @@ class AppListDialogFragment : DialogFragment() { binding.executePendingBindings() alertDialogBuilder.setView(binding.root) tabs = binding.tabs - tabs!!.selectTab(binding.tabs.getTabAt(if (initiallyExcluded) 0 else 1)) - tabs!!.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { - override fun onTabReselected(tab: TabLayout.Tab?) = Unit - override fun onTabUnselected(tab: TabLayout.Tab?) = Unit - override fun onTabSelected(tab: TabLayout.Tab?) = setButtonText() - }) + tabs?.apply { + selectTab(binding.tabs.getTabAt(if (initiallyExcluded) 0 else 1)) + addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabReselected(tab: TabLayout.Tab?) = Unit + override fun onTabUnselected(tab: TabLayout.Tab?) = Unit + override fun onTabSelected(tab: TabLayout.Tab?) = setButtonText() + }) + } alertDialogBuilder.setPositiveButton(" ") { _, _ -> setSelectionAndDismiss() } alertDialogBuilder.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() } alertDialogBuilder.setNeutralButton(R.string.toggle_all) { _, _ -> } @@ -119,7 +123,7 @@ class AppListDialogFragment : DialogFragment() { selectedApps.add(data.packageName) } } - (targetFragment as AppSelectionListener?)!!.onSelectedAppsSelected(selectedApps, tabs?.selectedTabPosition == 0) + (requireTargetFragment() as AppSelectionListener).onSelectedAppsSelected(selectedApps, tabs?.selectedTabPosition == 0) dismiss() } |