For #19258: Replace default Android back button with a custom icon.

upstream-sync
mcarare 3 years ago committed by Mihai Adrian Carare
parent 889cf2e718
commit 4dd4e35982

@ -82,6 +82,7 @@ import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
import org.mozilla.fenix.ext.measureNoInline
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.setNavigationIcon
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
@ -717,6 +718,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
setSupportActionBar(navigationToolbar)
// Add ids to this that we don't want to have a toolbar back button
setupNavigationToolbar()
setNavigationIcon(R.drawable.ic_back_button)
isToolbarInflated = true
}

@ -12,9 +12,12 @@ import android.app.role.RoleManager
import android.content.Intent
import android.os.Build
import android.provider.Settings
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.settings.SupportUtils
/**
@ -108,6 +111,20 @@ private fun Activity.navigateToDefaultBrowserAppsSettings() {
}
}
/**
* Sets the icon for the back (up) navigation button.
* @param icon The resource id of the icon.
*/
fun Activity.setNavigationIcon(
@DrawableRes icon: Int
) {
(this as? AppCompatActivity)?.supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
it.setHomeAsUpIndicator(icon)
it.setHomeActionContentDescription(R.string.action_bar_up_description)
}
}
const val REQUEST_CODE_BROWSER_ROLE = 1
const val SETTINGS_SELECT_OPTION_KEY = ":settings:fragment_args_key"
const val SETTINGS_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"

@ -35,6 +35,7 @@ fun Fragment.getPreferenceKey(@StringRes resourceId: Int): String = getString(re
*/
fun Fragment.showToolbar(title: String) {
(requireActivity() as AppCompatActivity).title = title
activity?.setNavigationIcon(R.drawable.ic_back_button)
(activity as NavHostActivity).getSupportActionBarAndInflateIfNecessary().show()
}

@ -44,5 +44,7 @@ open class LibraryPageView(
activity?.title = title
val toolbar = activity?.findViewById<Toolbar>(R.id.navigationToolbar)
toolbar?.setToolbarColors(foregroundColor, backgroundColor)
toolbar?.setNavigationIcon(R.drawable.ic_back_button)
toolbar?.navigationIcon?.setTint(foregroundColor)
}
}

@ -105,6 +105,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
view.historyLayout,
historyInteractor
)
showToolbar(getString(R.string.library_history))
return view
}
@ -161,7 +162,6 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.library_history))
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

@ -25,6 +25,7 @@ import org.mozilla.fenix.crashes.CrashListActivity
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.about.AboutItemType.LICENSING_INFO
import org.mozilla.fenix.settings.about.AboutItemType.PRIVACY_NOTICE
@ -53,7 +54,7 @@ class AboutFragment : Fragment(), AboutPageListener {
appName = getString(R.string.app_name)
headerAppName =
if (Config.channel.isRelease) getString(R.string.daylight_app_name) else appName
activity?.title = getString(R.string.preferences_about, appName)
showToolbar(getString(R.string.preferences_about, appName))
return rootView
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?primaryText"
android:pathData="M20.25,11.5H5.461L11.431,5.53C11.724,5.237 11.724,4.762 11.431,4.469C11.138,4.176 10.663,4.176 10.37,4.469L3,11.839V12.66L10.37,20.03C10.516,20.176 10.708,20.25 10.9,20.25C11.092,20.25 11.284,20.177 11.43,20.03C11.723,19.737 11.723,19.262 11.43,18.969L5.461,13H20.25C20.664,13 21,12.664 21,12.25C21,11.836 20.664,11.5 20.25,11.5Z" />
</vector>

@ -1713,4 +1713,7 @@
<!-- Content description radio buttons with a link to more information -->
<string name="radio_preference_info_content_description">Click for more details</string>
<!-- Content description for the action bar "up" button -->
<string name="action_bar_up_description">Navigate up</string>
</resources>

Loading…
Cancel
Save