2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Bug 1824379 - Ensure logins fragments share the same Store

We'll cache the same LoginsFragmentStore instance to a new nested navigation
graphs and in that allow multiple related screen to use the same data.
This commit is contained in:
Mugurell 2023-03-28 09:44:03 +03:00 committed by mergify[bot]
parent 0df448b78d
commit 066cdb7146
7 changed files with 96 additions and 90 deletions

View File

@ -4,9 +4,9 @@
package org.mozilla.fenix.components
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.get
import mozilla.components.lib.state.Store
@ -20,9 +20,9 @@ class StoreProvider<T : Store<*, *>>(
) : ViewModel() {
companion object {
fun <T : Store<*, *>> get(fragment: Fragment, createStore: () -> T): T {
fun <T : Store<*, *>> get(owner: ViewModelStoreOwner, createStore: () -> T): T {
val factory = StoreProviderFactory(createStore)
val viewModel: StoreProvider<T> = ViewModelProvider(fragment, factory).get()
val viewModel: StoreProvider<T> = ViewModelProvider(owner, factory).get()
return viewModel.store
}
}

View File

@ -63,11 +63,12 @@ class AddLoginFragment : Fragment(R.layout.fragment_add_login), MenuProvider {
_binding = FragmentAddLoginBinding.bind(view)
loginsFragmentStore = StoreProvider.get(this) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
loginsFragmentStore =
StoreProvider.get(findNavController().getBackStackEntry(R.id.savedLogins)) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
interactor = AddLoginInteractor(
SavedLoginsStorageController(

View File

@ -70,11 +70,12 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login), MenuProvider {
oldLogin = args.savedLoginItem
loginsFragmentStore = StoreProvider.get(this) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
loginsFragmentStore =
StoreProvider.get(findNavController().getBackStackEntry(R.id.savedLogins)) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
interactor = EditLoginInteractor(
SavedLoginsStorageController(

View File

@ -73,11 +73,12 @@ class LoginDetailFragment : SecureFragment(R.layout.fragment_login_detail), Menu
): View? {
val view = inflater.inflate(R.layout.fragment_login_detail, container, false)
_binding = FragmentLoginDetailBinding.bind(view)
savedLoginsStore = StoreProvider.get(this) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
savedLoginsStore =
StoreProvider.get(findNavController().getBackStackEntry(R.id.savedLogins)) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
loginDetailsBindingDelegate = LoginDetailsBindingDelegate(binding)
return view
@ -130,7 +131,7 @@ class LoginDetailFragment : SecureFragment(R.layout.fragment_login_detail), Menu
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requireActivity().onBackPressedDispatcher.addCallback(this) {
val directions = LoginDetailFragmentDirections.actionLoginDetailFragmentToSavedLoginsFragment()
val directions = LoginDetailFragmentDirections.actionLoginDetailFragmentToSavedLogins()
findNavController().navigate(directions)
}
}

View File

@ -22,6 +22,7 @@ import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import mozilla.components.concept.menu.MenuController
import mozilla.components.concept.menu.Orientation
import mozilla.components.lib.state.ext.consumeFrom
@ -35,6 +36,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.redirectToReAuth
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.home.SharedViewModel
import org.mozilla.fenix.settings.logins.LoginsAction
import org.mozilla.fenix.settings.logins.LoginsFragmentStore
import org.mozilla.fenix.settings.logins.LoginsListState
@ -74,11 +76,12 @@ class SavedLoginsFragment : SecureFragment(), MenuProvider {
val view = inflater.inflate(R.layout.fragment_saved_logins, container, false)
val binding = FragmentSavedLoginsBinding.bind(view)
savedLoginsStore = StoreProvider.get(this) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
savedLoginsStore =
StoreProvider.get(findNavController().getBackStackEntry(R.id.savedLogins)) {
LoginsFragmentStore(
createInitialLoginsListState(requireContext().settings()),
)
}
loginsListController =
LoginsListController(

View File

@ -447,7 +447,7 @@
android:label="@string/preferences_passwords_logins_and_passwords">
<action
android:id="@+id/action_savedLoginsAuthFragment_to_loginsListFragment"
app:destination="@id/savedLoginsFragment"
app:destination="@id/savedLogins"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
@ -475,80 +475,18 @@
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/savedLoginsFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.SavedLoginsFragment"
tools:layout="@layout/fragment_saved_logins">
<action
android:id="@+id/action_savedLoginsFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment" />
<action
android:id="@+id/action_savedLoginsFragment_to_addLoginFragment"
app:destination="@id/addLoginFragment"
app:popUpTo="@id/addLoginFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_savedLoginsFragment_to_browserFragment"
app:destination="@id/browserFragment"
app:popUpTo="@id/settingsFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/loginExceptionsFragment"
android:name="org.mozilla.fenix.exceptions.login.LoginExceptionsFragment"
android:label="@string/preferences_passwords_exceptions"
tools:layout="@layout/fragment_exceptions" />
<fragment
android:id="@+id/loginDetailFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.LoginDetailFragment"
tools:layout="@layout/fragment_login_detail">
<argument
android:name="savedLoginId"
app:argType="string"
app:nullable="false" />
<action
android:id="@+id/action_loginDetailFragment_to_editLoginFragment"
app:destination="@id/editLoginFragment"
app:popUpTo="@id/editLoginFragment"
app:popUpToInclusive="true" />
</fragment>
<action
android:id="@+id/action_loginDetailFragment_to_savedLoginsFragment"
app:destination="@id/savedLoginsFragment"
android:id="@+id/action_loginDetailFragment_to_savedLogins"
app:destination="@id/savedLogins"
app:popUpTo="@id/savedLoginsFragment"
app:popUpToInclusive="true"/>
<fragment
android:id="@+id/editLoginFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.EditLoginFragment"
android:label="@string/edit"
tools:layout="@layout/fragment_edit_login">
<argument
android:name="savedLoginItem"
app:argType="org.mozilla.fenix.settings.logins.SavedLogin"
app:nullable="false" />
<action
android:id="@+id/action_editLoginFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment"
app:popUpTo="@id/loginDetailFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/addLoginFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.AddLoginFragment"
android:label="@string/add_login"
tools:layout="@layout/fragment_add_login">
<action
android:id="@+id/action_addLoginFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment"
app:popUpTo="@id/savedLoginsFragment"
app:popUpToInclusive="false" />
</fragment>
<fragment
android:id="@+id/settingsFragment"
android:name="org.mozilla.fenix.settings.SettingsFragment"
@ -1436,4 +1374,66 @@
app:popExitAnim="@anim/slide_out_right" />
</fragment>
</navigation>
<navigation
android:id="@+id/savedLogins"
app:startDestination="@id/savedLoginsFragment">
<fragment
android:id="@+id/savedLoginsFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.SavedLoginsFragment"
tools:layout="@layout/fragment_saved_logins">
<action
android:id="@+id/action_savedLoginsFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment" />
<action
android:id="@+id/action_savedLoginsFragment_to_addLoginFragment"
app:destination="@id/addLoginFragment"
app:popUpTo="@id/addLoginFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_savedLoginsFragment_to_browserFragment"
app:destination="@id/browserFragment"
app:popUpTo="@id/settingsFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/addLoginFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.AddLoginFragment"
android:label="@string/add_login"
tools:layout="@layout/fragment_add_login">
<action
android:id="@+id/action_addLoginFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment"
app:popUpTo="@id/savedLoginsFragment"
app:popUpToInclusive="false" />
</fragment>
<fragment
android:id="@+id/loginDetailFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.LoginDetailFragment"
tools:layout="@layout/fragment_login_detail">
<argument
android:name="savedLoginId"
app:argType="string"
app:nullable="false" />
<action
android:id="@+id/action_loginDetailFragment_to_editLoginFragment"
app:destination="@id/editLoginFragment"
app:popUpTo="@id/editLoginFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/editLoginFragment"
android:name="org.mozilla.fenix.settings.logins.fragment.EditLoginFragment"
android:label="@string/edit"
tools:layout="@layout/fragment_edit_login">
<argument
android:name="savedLoginItem"
app:argType="org.mozilla.fenix.settings.logins.SavedLogin"
app:nullable="false" />
<action
android:id="@+id/action_editLoginFragment_to_loginDetailFragment"
app:destination="@id/loginDetailFragment"
app:popUpTo="@id/loginDetailFragment"
app:popUpToInclusive="true" />
</fragment>
</navigation>
</navigation>

View File

@ -904,7 +904,7 @@
<ID>UndocumentedPublicFunction:StartupTypeTelemetry.kt$StartupTypeTelemetry$fun attachOnHomeActivityOnCreate(lifecycle: Lifecycle)</ID>
<ID>UndocumentedPublicFunction:StorageStatsMetrics.kt$StorageStatsMetrics$// I couldn't get runBlockingTest to work correctly so I moved the functionality under test to // a synchronous function. @VisibleForTesting(otherwise = PRIVATE) @WorkerThread // queryStatsForUid fun reportSync(context: Context)</ID>
<ID>UndocumentedPublicFunction:StorageStatsMetrics.kt$StorageStatsMetrics$@OptIn(DelicateCoroutinesApi::class) // GlobalScope usage fun report(context: Context)</ID>
<ID>UndocumentedPublicFunction:StoreProvider.kt$StoreProvider.Companion$fun &lt;T : Store&lt;*, *&gt;&gt; get(fragment: Fragment, createStore: () -&gt; T): T</ID>
<ID>UndocumentedPublicFunction:StoreProvider.kt$StoreProvider.Companion$fun &lt;T : Store&lt;*, *&gt;&gt; get(owner: ViewModelStoreOwner, createStore: () -&gt; T): T</ID>
<ID>UndocumentedPublicFunction:StudiesView.kt$StudiesView$@Suppress("TooGenericExceptionCaught", "ApplySharedPref") fun bind()</ID>
<ID>UndocumentedPublicFunction:SupportUtils.kt$SupportUtils$fun createAuthCustomTabIntent(context: Context, url: String): Intent</ID>
<ID>UndocumentedPublicFunction:SupportUtils.kt$SupportUtils$fun createCustomTabIntent(context: Context, url: String): Intent</ID>