Add settings button to home screen app bar

This commit is contained in:
Jarne Demeulemeester 2021-07-18 11:21:27 +02:00
parent d9b9b92b6c
commit 565336cbf6
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
3 changed files with 43 additions and 3 deletions

View file

@ -1,9 +1,7 @@
package dev.jdtech.jellyfin.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
@ -22,6 +20,25 @@ class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding
private val viewModel: HomeViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.home_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_settings -> {
navigateToSettingsFragment()
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -94,4 +111,10 @@ class HomeFragment : Fragment() {
)
)
}
private fun navigateToSettingsFragment() {
findNavController().navigate(
HomeFragmentDirections.actionNavigationHomeToNavigationSettings()
)
}
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings"
android:title="@string/title_settings"
app:showAsAction="always" />
</menu>

View file

@ -27,6 +27,13 @@
<action
android:id="@+id/action_navigation_home_to_episodeBottomSheetFragment"
app:destination="@id/episodeBottomSheetFragment" />
<action
android:id="@+id/action_navigation_home_to_navigation_settings"
app:destination="@id/navigation_settings"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment