Replace deep links with global actions
This commit is contained in:
@@ -5,15 +5,16 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDirections
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import by.kirich1409.viewbindingdelegate.viewBinding
|
||||
import com.google.android.material.shape.CornerFamily
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import gq.kirmanak.mealient.NavGraphDirections
|
||||
import gq.kirmanak.mealient.R
|
||||
import gq.kirmanak.mealient.databinding.MainActivityBinding
|
||||
import gq.kirmanak.mealient.extensions.observeOnce
|
||||
@@ -64,12 +65,12 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
|
||||
private fun onNavigationItemSelected(menuItem: MenuItem): Boolean {
|
||||
logger.v { "onNavigationItemSelected() called with: menuItem = $menuItem" }
|
||||
menuItem.isChecked = true
|
||||
val deepLink = when (menuItem.itemId) {
|
||||
R.id.add_recipe -> ADD_RECIPE_DEEP_LINK
|
||||
R.id.recipes_list -> RECIPES_LIST_DEEP_LINK
|
||||
val directions = when (menuItem.itemId) {
|
||||
R.id.add_recipe -> NavGraphDirections.actionGlobalAddRecipeFragment()
|
||||
R.id.recipes_list -> NavGraphDirections.actionGlobalRecipesFragment()
|
||||
else -> throw IllegalArgumentException("Unknown menu item id: ${menuItem.itemId}")
|
||||
}
|
||||
navigateDeepLink(deepLink)
|
||||
navigateTo(directions)
|
||||
binding.drawer.close()
|
||||
return true
|
||||
}
|
||||
@@ -109,7 +110,7 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
|
||||
logger.v { "onOptionsItemSelected() called with: item = $item" }
|
||||
val result = when (item.itemId) {
|
||||
R.id.login -> {
|
||||
navigateDeepLink(AUTH_DEEP_LINK)
|
||||
navigateTo(NavGraphDirections.actionGlobalAuthenticationFragment())
|
||||
true
|
||||
}
|
||||
R.id.logout -> {
|
||||
@@ -121,14 +122,8 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun navigateDeepLink(deepLink: String) {
|
||||
logger.v { "navigateDeepLink() called with: deepLink = $deepLink" }
|
||||
navController.navigate(deepLink.toUri())
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val AUTH_DEEP_LINK = "mealient://authenticate"
|
||||
private const val ADD_RECIPE_DEEP_LINK = "mealient://recipe/add"
|
||||
private const val RECIPES_LIST_DEEP_LINK = "mealient://recipe/list"
|
||||
private fun navigateTo(directions: NavDirections) {
|
||||
logger.v { "navigateTo() called with: directions = $directions" }
|
||||
navController.navigate(directions)
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,8 @@
|
||||
android:id="@+id/authenticationFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.auth.AuthenticationFragment"
|
||||
android:label="AuthenticationFragment"
|
||||
tools:layout="@layout/fragment_authentication">
|
||||
<deepLink
|
||||
android:id="@+id/deepLink"
|
||||
app:uri="mealient://authenticate" />
|
||||
</fragment>
|
||||
tools:layout="@layout/fragment_authentication" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/recipesFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.recipes.RecipesFragment"
|
||||
@@ -22,10 +19,8 @@
|
||||
<action
|
||||
android:id="@+id/action_recipesFragment_to_recipeInfoFragment"
|
||||
app:destination="@id/recipeInfoFragment" />
|
||||
<deepLink
|
||||
android:id="@+id/deepLink"
|
||||
app:uri="mealient://recipe/list" />
|
||||
</fragment>
|
||||
|
||||
<dialog
|
||||
android:id="@+id/recipeInfoFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.recipes.info.RecipeInfoFragment"
|
||||
@@ -35,6 +30,7 @@
|
||||
android:name="recipe_id"
|
||||
app:argType="string" />
|
||||
</dialog>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/disclaimerFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.disclaimer.DisclaimerFragment"
|
||||
@@ -46,6 +42,7 @@
|
||||
app:popUpTo="@id/nav_graph"
|
||||
app:popUpToInclusive="true" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/baseURLFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.baseurl.BaseURLFragment"
|
||||
@@ -57,13 +54,22 @@
|
||||
app:popUpTo="@id/nav_graph"
|
||||
app:popUpToInclusive="true" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/addRecipeFragment"
|
||||
android:name="gq.kirmanak.mealient.ui.add.AddRecipeFragment"
|
||||
android:label="fragment_add_recipe"
|
||||
tools:layout="@layout/fragment_add_recipe">
|
||||
<deepLink
|
||||
android:id="@+id/deepLink"
|
||||
app:uri="mealient://recipe/add" />
|
||||
</fragment>
|
||||
tools:layout="@layout/fragment_add_recipe" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_global_authenticationFragment"
|
||||
app:destination="@id/authenticationFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_global_recipesFragment"
|
||||
app:destination="@id/recipesFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_global_addRecipeFragment"
|
||||
app:destination="@id/addRecipeFragment" />
|
||||
</navigation>
|
||||
Reference in New Issue
Block a user