From 407094165711e5b85ac402fbb442abf73fa22786 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Fri, 10 May 2019 16:42:41 -0700 Subject: [PATCH] No issue: Refactor dialogs to use nav graph --- .../mozilla/fenix/browser/BrowserFragment.kt | 33 ++++++------- .../collections/CreateCollectionFragment.kt | 4 -- .../org/mozilla/fenix/home/HomeFragment.kt | 14 ++---- .../QuickSettingsSheetDialogFragment.kt | 48 ++++--------------- app/src/main/res/navigation/nav_graph.xml | 36 ++++++++++++++ 5 files changed, 61 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 72d4424ee..17c30b5c8 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -58,7 +58,6 @@ import org.mozilla.fenix.DefaultThemeManager import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.R -import org.mozilla.fenix.collections.CreateCollectionFragment import org.mozilla.fenix.collections.CreateCollectionViewModel import org.mozilla.fenix.collections.SaveCollectionStep import org.mozilla.fenix.components.FenixSnackbar @@ -85,7 +84,6 @@ import org.mozilla.fenix.quickactionsheet.QuickActionAction import org.mozilla.fenix.quickactionsheet.QuickActionChange import org.mozilla.fenix.quickactionsheet.QuickActionComponent import org.mozilla.fenix.quickactionsheet.QuickActionState -import org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment import org.mozilla.fenix.utils.ItsNotBrokenSnack import org.mozilla.fenix.utils.Settings import kotlin.coroutines.CoroutineContext @@ -641,11 +639,10 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, val selectedSet = setOf(tabs) viewModel?.selectedTabs = selectedSet viewModel?.saveCollectionStep = SaveCollectionStep.SelectCollection - CreateCollectionFragment() - .show( - requireActivity().supportFragmentManager, - CreateCollectionFragment.createCollectionTag - ) + view?.let { + val directions = BrowserFragmentDirections.actionBrowserFragmentToCreateCollectionFragment() + Navigation.findNavController(it).navigate(directions) + } } } @@ -668,18 +665,16 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, val sitePermissions: SitePermissions? = storage.findSitePermissionsBy(host) launch(Main) { - val quickSettingsSheet = QuickSettingsSheetDialogFragment.newInstance( - url = session.url, - isSecured = session.securityInfo.secure, - isTrackingProtectionOn = session.trackerBlockingEnabled, - sitePermissions = sitePermissions, - gravity = getAppropriateLayoutGravity() - ) - quickSettingsSheet.sitePermissions = sitePermissions - quickSettingsSheet.show( - requireFragmentManager(), - QuickSettingsSheetDialogFragment.FRAGMENT_TAG - ) + view?.let { + val directions = BrowserFragmentDirections.actionBrowserFragmentToQuickSettingsSheetDialogFragment( + url = session.url, + isSecured = session.securityInfo.secure, + isTrackingProtectionOn = session.trackerBlockingEnabled, + sitePermissions = sitePermissions, + gravity = getAppropriateLayoutGravity() + ) + Navigation.findNavController(it).navigate(directions) + } } } } diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index 8170a6c52..1a2de4f3a 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -129,8 +129,4 @@ class CreateCollectionFragment : DialogFragment() { } } } - - companion object { - const val createCollectionTag = "createCollection" - } } diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index ca0ae25b9..953298e08 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -35,7 +35,6 @@ import org.mozilla.fenix.BrowsingModeManager import org.mozilla.fenix.DefaultThemeManager import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R -import org.mozilla.fenix.collections.CreateCollectionFragment import org.mozilla.fenix.collections.CreateCollectionViewModel import org.mozilla.fenix.collections.SaveCollectionStep import org.mozilla.fenix.components.metrics.Event @@ -494,16 +493,9 @@ class HomeFragment : Fragment(), CoroutineScope { viewModel?.selectedTabs = selectedSet viewModel?.saveCollectionStep = SaveCollectionStep.SelectTabs - CreateCollectionFragment().also { - it.onCollectionSaved = { - storedCollections.add(it) - emitCollectionChange() - } - - it.show( - requireActivity().supportFragmentManager, - CreateCollectionFragment.createCollectionTag - ) + view?.let { + val directions = HomeFragmentDirections.actionHomeFragmentToCreateCollectionFragment() + Navigation.findNavController(it).navigate(directions) } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt index fdcb3b70a..6fff6a599 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt @@ -38,28 +38,21 @@ import java.net.MalformedURLException import java.net.URL import kotlin.coroutines.CoroutineContext -private const val KEY_URL = "KEY_URL" -private const val KEY_IS_SECURED = "KEY_IS_SECURED" -private const val KEY_SITE_PERMISSIONS = "KEY_SITE_PERMISSIONS" -private const val KEY_IS_TP_ON = "KEY_IS_TP_ON" -private const val KEY_DIALOG_GRAVITY = "KEY_DIALOG_GRAVITY" private const val REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS = 4 @SuppressWarnings("TooManyFunctions") class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineScope { private val safeArguments get() = requireNotNull(arguments) - private val url: String by lazy { safeArguments.getString(KEY_URL) } - private val isSecured: Boolean by lazy { safeArguments.getBoolean(KEY_IS_SECURED) } - private val isTrackingProtectionOn: Boolean by lazy { safeArguments.getBoolean(KEY_IS_TP_ON) } - private val promptGravity: Int by lazy { safeArguments.getInt(KEY_DIALOG_GRAVITY) } + private val url: String by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).url } + private val isSecured: Boolean by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).isSecured } + private val isTrackingProtectionOn: Boolean by lazy { + QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).isTrackingProtectionOn + } + private val promptGravity: Int by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).gravity } private lateinit var quickSettingsComponent: QuickSettingsComponent private lateinit var job: Job - var sitePermissions: SitePermissions? - get() = safeArguments.getParcelable(KEY_SITE_PERMISSIONS) - set(value) { - safeArguments.putParcelable(KEY_SITE_PERMISSIONS, value) - } + private var sitePermissions: SitePermissions? = null override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job @@ -73,6 +66,7 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco container: ViewGroup?, savedInstanceState: Bundle? ): View { + sitePermissions = QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).sitePermissions val rootView = inflateRootView(container) quickSettingsComponent = QuickSettingsComponent( rootView as NestedScrollView, this, ActionBusFactory.get(this), @@ -127,32 +121,6 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco return this } - companion object { - const val FRAGMENT_TAG = "QUICK_SETTINGS_FRAGMENT_TAG" - - fun newInstance( - url: String, - isSecured: Boolean, - isTrackingProtectionOn: Boolean, - sitePermissions: SitePermissions?, - gravity: Int = BOTTOM - ): QuickSettingsSheetDialogFragment { - - val fragment = QuickSettingsSheetDialogFragment() - val arguments = fragment.arguments ?: Bundle() - - with(arguments) { - putString(KEY_URL, url) - putBoolean(KEY_IS_SECURED, isSecured) - putBoolean(KEY_IS_TP_ON, isTrackingProtectionOn) - putParcelable(KEY_SITE_PERMISSIONS, sitePermissions) - putInt(KEY_DIALOG_GRAVITY, gravity) - } - fragment.arguments = arguments - return fragment - } - } - override fun onRequestPermissionsResult( requestCode: Int, permissions: Array, diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 21bfedf90..a3429b629 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -32,6 +32,9 @@ + + + + + + + + + + + \ No newline at end of file