|
class NavigationManager { |
|
|
|
fun goToMainActivity(activity: Activity) { |
|
val intent = Intent(activity, MainActivity::class.java) |
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) |
|
activity.startActivity(intent) |
|
} |
|
|
|
fun popBackStack(navController: NavController) { |
|
navController.popBackStack() |
|
} |
|
|
|
fun navigateTo(destinationId: Int, navController: NavController) { |
|
navController.navigate(destinationId, null, navOptions { |
|
launchSingleTop = true |
|
restoreState = true |
|
popUpTo(navController.graph.findStartDestination().id) { |
|
saveState = true |
|
} |
|
}) |
|
} |
|
|
|
|
|
fun goToGallery(activity: Activity) { |
|
navigateTo(activity, R.id.tabGalleryFragment) |
|
} |
|
|
|
fun goToOrderDetails(view: View, orderId: OrderId) { |
|
val bundle = bundleOf(ORDER_ID to orderId) |
|
view.goTo(R.id.orderDetailsFragment, bundle) |
|
} |
|
|
|
private fun Fragment.goTo( |
|
@IdRes id: Int, bundle: Bundle? = null, navOptions: NavOptions? = null, |
|
navigatorExtras: Navigator.Extras? = null |
|
) { |
|
if (mayNavigate(id)) findNavController().navigate(id, bundle, navOptions, navigatorExtras) |
|
} |
|
|
|
companion object { |
|
const val PRODUCT_ID = "productId" |
|
const val ORDER_ID = "orderId" |
|
} |
|
} |
|
|
|
enum class DEEPLINK_QUERY(val type: String) { |
|
GALLERY_QUERY("gallery"), |
|
ORDERS_QUERY("orders"), |
|
CART_QUERY("cart"), |
|
} |