mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] No issue: Refactor dialogs to use nav graph
This commit is contained in:
parent
38eaa83d43
commit
7c3da988a2
@ -58,7 +58,6 @@ import org.mozilla.fenix.DefaultThemeManager
|
|||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.IntentReceiverActivity
|
import org.mozilla.fenix.IntentReceiverActivity
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.collections.CreateCollectionFragment
|
|
||||||
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
||||||
import org.mozilla.fenix.collections.SaveCollectionStep
|
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||||
import org.mozilla.fenix.components.FenixSnackbar
|
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.QuickActionChange
|
||||||
import org.mozilla.fenix.quickactionsheet.QuickActionComponent
|
import org.mozilla.fenix.quickactionsheet.QuickActionComponent
|
||||||
import org.mozilla.fenix.quickactionsheet.QuickActionState
|
import org.mozilla.fenix.quickactionsheet.QuickActionState
|
||||||
import org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment
|
|
||||||
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
||||||
import org.mozilla.fenix.utils.Settings
|
import org.mozilla.fenix.utils.Settings
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@ -641,11 +639,10 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
|
|||||||
val selectedSet = setOf(tabs)
|
val selectedSet = setOf(tabs)
|
||||||
viewModel?.selectedTabs = selectedSet
|
viewModel?.selectedTabs = selectedSet
|
||||||
viewModel?.saveCollectionStep = SaveCollectionStep.SelectCollection
|
viewModel?.saveCollectionStep = SaveCollectionStep.SelectCollection
|
||||||
CreateCollectionFragment()
|
view?.let {
|
||||||
.show(
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToCreateCollectionFragment()
|
||||||
requireActivity().supportFragmentManager,
|
Navigation.findNavController(it).navigate(directions)
|
||||||
CreateCollectionFragment.createCollectionTag
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,18 +665,16 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
|
|||||||
val sitePermissions: SitePermissions? = storage.findSitePermissionsBy(host)
|
val sitePermissions: SitePermissions? = storage.findSitePermissionsBy(host)
|
||||||
|
|
||||||
launch(Main) {
|
launch(Main) {
|
||||||
val quickSettingsSheet = QuickSettingsSheetDialogFragment.newInstance(
|
view?.let {
|
||||||
url = session.url,
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToQuickSettingsSheetDialogFragment(
|
||||||
isSecured = session.securityInfo.secure,
|
url = session.url,
|
||||||
isTrackingProtectionOn = session.trackerBlockingEnabled,
|
isSecured = session.securityInfo.secure,
|
||||||
sitePermissions = sitePermissions,
|
isTrackingProtectionOn = session.trackerBlockingEnabled,
|
||||||
gravity = getAppropriateLayoutGravity()
|
sitePermissions = sitePermissions,
|
||||||
)
|
gravity = getAppropriateLayoutGravity()
|
||||||
quickSettingsSheet.sitePermissions = sitePermissions
|
)
|
||||||
quickSettingsSheet.show(
|
Navigation.findNavController(it).navigate(directions)
|
||||||
requireFragmentManager(),
|
}
|
||||||
QuickSettingsSheetDialogFragment.FRAGMENT_TAG
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,8 +129,4 @@ class CreateCollectionFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val createCollectionTag = "createCollection"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ import org.mozilla.fenix.BrowsingModeManager
|
|||||||
import org.mozilla.fenix.DefaultThemeManager
|
import org.mozilla.fenix.DefaultThemeManager
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.collections.CreateCollectionFragment
|
|
||||||
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
||||||
import org.mozilla.fenix.collections.SaveCollectionStep
|
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
@ -494,16 +493,9 @@ class HomeFragment : Fragment(), CoroutineScope {
|
|||||||
viewModel?.selectedTabs = selectedSet
|
viewModel?.selectedTabs = selectedSet
|
||||||
viewModel?.saveCollectionStep = SaveCollectionStep.SelectTabs
|
viewModel?.saveCollectionStep = SaveCollectionStep.SelectTabs
|
||||||
|
|
||||||
CreateCollectionFragment().also {
|
view?.let {
|
||||||
it.onCollectionSaved = {
|
val directions = HomeFragmentDirections.actionHomeFragmentToCreateCollectionFragment()
|
||||||
storedCollections.add(it)
|
Navigation.findNavController(it).navigate(directions)
|
||||||
emitCollectionChange()
|
|
||||||
}
|
|
||||||
|
|
||||||
it.show(
|
|
||||||
requireActivity().supportFragmentManager,
|
|
||||||
CreateCollectionFragment.createCollectionTag
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,28 +38,21 @@ import java.net.MalformedURLException
|
|||||||
import java.net.URL
|
import java.net.URL
|
||||||
import kotlin.coroutines.CoroutineContext
|
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
|
private const val REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS = 4
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions")
|
@SuppressWarnings("TooManyFunctions")
|
||||||
class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineScope {
|
class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineScope {
|
||||||
private val safeArguments get() = requireNotNull(arguments)
|
private val safeArguments get() = requireNotNull(arguments)
|
||||||
private val url: String by lazy { safeArguments.getString(KEY_URL) }
|
private val url: String by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).url }
|
||||||
private val isSecured: Boolean by lazy { safeArguments.getBoolean(KEY_IS_SECURED) }
|
private val isSecured: Boolean by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).isSecured }
|
||||||
private val isTrackingProtectionOn: Boolean by lazy { safeArguments.getBoolean(KEY_IS_TP_ON) }
|
private val isTrackingProtectionOn: Boolean by lazy {
|
||||||
private val promptGravity: Int by lazy { safeArguments.getInt(KEY_DIALOG_GRAVITY) }
|
QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).isTrackingProtectionOn
|
||||||
|
}
|
||||||
|
private val promptGravity: Int by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).gravity }
|
||||||
private lateinit var quickSettingsComponent: QuickSettingsComponent
|
private lateinit var quickSettingsComponent: QuickSettingsComponent
|
||||||
private lateinit var job: Job
|
private lateinit var job: Job
|
||||||
|
|
||||||
var sitePermissions: SitePermissions?
|
private var sitePermissions: SitePermissions? = null
|
||||||
get() = safeArguments.getParcelable(KEY_SITE_PERMISSIONS)
|
|
||||||
set(value) {
|
|
||||||
safeArguments.putParcelable(KEY_SITE_PERMISSIONS, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job
|
override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job
|
||||||
|
|
||||||
@ -73,6 +66,7 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
|
sitePermissions = QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).sitePermissions
|
||||||
val rootView = inflateRootView(container)
|
val rootView = inflateRootView(container)
|
||||||
quickSettingsComponent = QuickSettingsComponent(
|
quickSettingsComponent = QuickSettingsComponent(
|
||||||
rootView as NestedScrollView, this, ActionBusFactory.get(this),
|
rootView as NestedScrollView, this, ActionBusFactory.get(this),
|
||||||
@ -127,32 +121,6 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
|
|||||||
return this
|
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(
|
override fun onRequestPermissionsResult(
|
||||||
requestCode: Int,
|
requestCode: Int,
|
||||||
permissions: Array<out String>,
|
permissions: Array<out String>,
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_homeFragment_to_settingsFragment"
|
android:id="@+id/action_homeFragment_to_settingsFragment"
|
||||||
app:destination="@id/settingsFragment" />
|
app:destination="@id/settingsFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_homeFragment_to_createCollectionFragment"
|
||||||
|
app:destination="@id/createCollectionFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
@ -116,6 +119,12 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_bookmarkEditFragment"
|
android:id="@+id/action_browserFragment_to_bookmarkEditFragment"
|
||||||
app:destination="@id/bookmarkEditFragment" />
|
app:destination="@id/bookmarkEditFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_browserFragment_to_createCollectionFragment"
|
||||||
|
app:destination="@id/createCollectionFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_browserFragment_to_quickSettingsSheetDialogFragment"
|
||||||
|
app:destination="@id/quickSettingsSheetDialogFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
@ -300,4 +309,31 @@
|
|||||||
android:id="@+id/exceptionsFragment"
|
android:id="@+id/exceptionsFragment"
|
||||||
android:name="org.mozilla.fenix.exceptions.ExceptionsFragment"
|
android:name="org.mozilla.fenix.exceptions.ExceptionsFragment"
|
||||||
android:label="ExceptionsFragment" />
|
android:label="ExceptionsFragment" />
|
||||||
|
<dialog
|
||||||
|
android:id="@+id/createCollectionFragment"
|
||||||
|
android:name="org.mozilla.fenix.collections.CreateCollectionFragment"
|
||||||
|
android:label="fragment_create_collection"
|
||||||
|
tools:layout="@layout/fragment_create_collection" />
|
||||||
|
<dialog
|
||||||
|
android:id="@+id/quickSettingsSheetDialogFragment"
|
||||||
|
android:name="org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment"
|
||||||
|
android:label="QuickSettingsSheetDialogFragment" >
|
||||||
|
<argument
|
||||||
|
android:name="url"
|
||||||
|
app:argType="string" />
|
||||||
|
<argument
|
||||||
|
android:name="isSecured"
|
||||||
|
app:argType="boolean" />
|
||||||
|
<argument
|
||||||
|
android:name="isTrackingProtectionOn"
|
||||||
|
app:argType="boolean" />
|
||||||
|
<argument
|
||||||
|
android:name="sitePermissions"
|
||||||
|
app:argType="mozilla.components.feature.sitepermissions.SitePermissions"
|
||||||
|
app:nullable="true" />
|
||||||
|
<argument
|
||||||
|
android:name="gravity"
|
||||||
|
app:argType="integer"
|
||||||
|
android:defaultValue="80" />
|
||||||
|
</dialog>
|
||||||
</navigation>
|
</navigation>
|
Loading…
Reference in New Issue
Block a user