2019-01-24 22:07:52 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-01-23 23:48:15 +01:00
|
|
|
* 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/. */
|
2019-01-24 22:07:52 +01:00
|
|
|
|
2019-01-23 22:39:53 +01:00
|
|
|
package org.mozilla.fenix.ext
|
|
|
|
|
2019-06-06 21:40:10 +02:00
|
|
|
import androidx.annotation.IdRes
|
2019-08-21 17:38:14 +02:00
|
|
|
import androidx.annotation.StringRes
|
2019-11-25 21:36:47 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-06-06 21:40:10 +02:00
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.navigation.NavDirections
|
|
|
|
import androidx.navigation.NavOptions
|
|
|
|
import androidx.navigation.Navigator
|
|
|
|
import androidx.navigation.fragment.NavHostFragment.findNavController
|
2020-01-16 19:03:18 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_home.*
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
2019-01-23 22:39:53 +01:00
|
|
|
import org.mozilla.fenix.components.Components
|
|
|
|
|
2019-01-23 23:48:15 +01:00
|
|
|
/**
|
|
|
|
* Get the requireComponents of this application.
|
|
|
|
*/
|
2019-06-06 21:40:10 +02:00
|
|
|
val Fragment.requireComponents: Components
|
2019-01-30 17:36:14 +01:00
|
|
|
get() = requireContext().components
|
2019-06-06 21:40:10 +02:00
|
|
|
|
|
|
|
fun Fragment.nav(@IdRes id: Int?, directions: NavDirections) {
|
|
|
|
findNavController(this).nav(id, directions)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Fragment.nav(@IdRes id: Int?, directions: NavDirections, extras: Navigator.Extras) {
|
|
|
|
findNavController(this).nav(id, directions, extras)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Fragment.nav(@IdRes id: Int?, directions: NavDirections, options: NavOptions) {
|
|
|
|
findNavController(this).nav(id, directions, options)
|
|
|
|
}
|
2019-08-21 17:38:14 +02:00
|
|
|
|
|
|
|
fun Fragment.getPreferenceKey(@StringRes resourceId: Int): String = getString(resourceId)
|
2019-11-25 21:36:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the activity toolbar with the given [title].
|
|
|
|
* Throws if the fragment is not attached to an [AppCompatActivity].
|
|
|
|
*/
|
|
|
|
fun Fragment.showToolbar(title: String) {
|
|
|
|
(requireActivity() as AppCompatActivity).title = title
|
2020-01-16 19:03:18 +01:00
|
|
|
(activity as HomeActivity).getSupportActionBarAndInflateIfNecessary().show()
|
2019-11-25 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the activity toolbar.
|
|
|
|
* Throws if the fragment is not attached to an [AppCompatActivity].
|
|
|
|
*/
|
|
|
|
fun Fragment.hideToolbar() {
|
|
|
|
(requireActivity() as AppCompatActivity).supportActionBar?.hide()
|
|
|
|
}
|