Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #9506: Add possibility to navigate to a preference in settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Sep 7, 2020
1 parent 9122381 commit 2079429
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.settings

import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
Expand All @@ -15,6 +16,7 @@ import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDirections
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -27,8 +29,8 @@ import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.Config
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.application
Expand All @@ -45,6 +47,7 @@ import kotlin.system.exitProcess
@Suppress("LargeClass", "TooManyFunctions")
class SettingsFragment : PreferenceFragmentCompat() {

private val args by navArgs<SettingsFragmentArgs>()
private lateinit var accountUiView: AccountUiView

private val accountObserver = object : AccountObserver {
Expand Down Expand Up @@ -124,6 +127,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
updateMakeDefaultBrowserPreference()
}

@SuppressLint("RestrictedApi")
override fun onResume() {
super.onResume()

Expand All @@ -136,6 +140,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
requireView().findViewById<RecyclerView>(R.id.recycler_view)
?.hideInitialScrollBar(viewLifecycleOwner.lifecycleScope)

if (args.preferenceToScrollTo != null) {
scrollToPreference(args.preferenceToScrollTo)
}

// Consider finish of `onResume` to be the point at which we consider this fragment as 'created'.
creatingFragment = false
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@
android:id="@+id/settingsFragment"
android:name="org.mozilla.fenix.settings.SettingsFragment"
android:label="@string/settings_title">
<argument
android:name="preference_to_scroll_to"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<action
android:id="@+id/action_settingsFragment_to_dataChoicesFragment"
app:destination="@id/dataChoicesFragment"
Expand Down

0 comments on commit 2079429

Please sign in to comment.