Change LibraryFragment to Nav Fragment
Change LibraryFragment to extend NavHostFragment, so that the child fragments arent as extensively nested as they were before.
This commit is contained in:
@@ -2,40 +2,22 @@ package org.oxycblt.auxio.library
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
||||
|
||||
class LibraryFragment : Fragment() {
|
||||
class LibraryFragment : NavHostFragment() {
|
||||
|
||||
private var navController: NavController? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val binding = DataBindingUtil.inflate<FragmentLibraryBinding>(
|
||||
inflater, R.layout.fragment_library, container, false
|
||||
)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
requireActivity().onBackPressedDispatcher.addCallback(
|
||||
viewLifecycleOwner, callback
|
||||
this, callback
|
||||
)
|
||||
|
||||
val navHost = childFragmentManager.findFragmentById(R.id.nav_host) as? NavHostFragment
|
||||
navController = navHost?.navController
|
||||
navController.setGraph(R.navigation.nav_library)
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -55,7 +37,7 @@ class LibraryFragment : Fragment() {
|
||||
override fun handleOnBackPressed() {
|
||||
|
||||
// If at the root of the navigation, perform onBackPressed from the main activity.
|
||||
if (navController?.currentDestination?.id == navController?.graph?.startDestination) {
|
||||
if (navController.currentDestination?.id == navController.graph.startDestination) {
|
||||
// Disable the callback as it will get caught in an infinite loop otherwise.
|
||||
isEnabled = false
|
||||
|
||||
@@ -63,7 +45,7 @@ class LibraryFragment : Fragment() {
|
||||
|
||||
isEnabled = true
|
||||
} else {
|
||||
navController?.navigateUp()
|
||||
navController.navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package org.oxycblt.auxio
|
||||
package org.oxycblt.auxio.loading
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
@@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
||||
Reference in New Issue
Block a user