2020-10-06 08:46:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
|
|
|
* This is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
2020-07-28 19:18:34 +00:00
|
|
|
package code.name.monkey.retromusic.extensions
|
|
|
|
|
|
|
|
import androidx.annotation.IdRes
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.navigation.NavController
|
2020-08-11 18:29:44 +00:00
|
|
|
import androidx.navigation.findNavController
|
2020-07-28 19:18:34 +00:00
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
|
|
|
|
fun Fragment.navigate(@IdRes id: Int) = findNavController().navigate(id)
|
|
|
|
|
2020-08-11 18:29:44 +00:00
|
|
|
fun Fragment.findNavController(@IdRes id: Int): NavController {
|
2020-07-28 19:18:34 +00:00
|
|
|
val fragment = childFragmentManager.findFragmentById(id) as NavHostFragment
|
|
|
|
return fragment.navController
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:29:44 +00:00
|
|
|
fun Fragment.findActivityNavController(@IdRes id: Int): NavController {
|
|
|
|
return requireActivity().findNavController(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun AppCompatActivity.findNavController(@IdRes id: Int): NavController {
|
2020-07-28 19:18:34 +00:00
|
|
|
val fragment = supportFragmentManager.findFragmentById(id) as NavHostFragment
|
|
|
|
return fragment.navController
|
2020-10-06 08:46:04 +00:00
|
|
|
}
|