Show confirmation dialog before deleting recipe
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package gq.kirmanak.mealient.ui.recipes
|
package gq.kirmanak.mealient.ui.recipes
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
@@ -13,6 +14,7 @@ import androidx.paging.LoadState
|
|||||||
import androidx.paging.PagingDataAdapter
|
import androidx.paging.PagingDataAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import by.kirich1409.viewbindingdelegate.viewBinding
|
import by.kirich1409.viewbindingdelegate.viewBinding
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import gq.kirmanak.mealient.R
|
import gq.kirmanak.mealient.R
|
||||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||||
@@ -144,13 +146,29 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
|
|||||||
|
|
||||||
private fun onDeleteClick(event: RecipeViewHolder.ClickEvent) {
|
private fun onDeleteClick(event: RecipeViewHolder.ClickEvent) {
|
||||||
logger.v { "onDeleteClick() called with: event = $event" }
|
logger.v { "onDeleteClick() called with: event = $event" }
|
||||||
viewModel.onDeleteConfirm(event.recipeSummaryEntity).observe(viewLifecycleOwner) {
|
val entity = event.recipeSummaryEntity
|
||||||
|
val message = getString(
|
||||||
|
R.string.fragment_recipes_delete_recipe_confirm_dialog_message, entity.name
|
||||||
|
)
|
||||||
|
val onPositiveClick = DialogInterface.OnClickListener { _, _ ->
|
||||||
|
viewModel.onDeleteConfirm(entity).observe(viewLifecycleOwner) {
|
||||||
logger.d { "onDeleteClick: result is $it" }
|
logger.d { "onDeleteClick: result is $it" }
|
||||||
if (it.isFailure) {
|
if (it.isFailure) {
|
||||||
showLongToast(R.string.fragment_recipes_delete_recipe_failed)
|
showLongToast(R.string.fragment_recipes_delete_recipe_failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val positiveBtnResId = R.string.fragment_recipes_delete_recipe_confirm_dialog_positive_btn
|
||||||
|
val titleResId = R.string.fragment_recipes_delete_recipe_confirm_dialog_title
|
||||||
|
val negativeBtnResId = R.string.fragment_recipes_delete_recipe_confirm_dialog_negative_btn
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle(titleResId)
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton(positiveBtnResId, onPositiveClick)
|
||||||
|
.setNegativeButton(negativeBtnResId) { _, _ -> }
|
||||||
|
.show()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun onFavoriteClick(event: RecipeViewHolder.ClickEvent) {
|
private fun onFavoriteClick(event: RecipeViewHolder.ClickEvent) {
|
||||||
logger.v { "onFavoriteClick() called with: event = $event" }
|
logger.v { "onFavoriteClick() called with: event = $event" }
|
||||||
|
|||||||
@@ -51,6 +51,10 @@
|
|||||||
<string name="fragment_recipes_load_failure_toast_no_connection">no connection</string>
|
<string name="fragment_recipes_load_failure_toast_no_connection">no connection</string>
|
||||||
<string name="fragment_recipes_favorite_update_failed">Favorite status update failed</string>
|
<string name="fragment_recipes_favorite_update_failed">Favorite status update failed</string>
|
||||||
<string name="fragment_recipes_delete_recipe_failed">Recipe removal failed</string>
|
<string name="fragment_recipes_delete_recipe_failed">Recipe removal failed</string>
|
||||||
|
<string name="fragment_recipes_delete_recipe_confirm_dialog_title">Delete recipe</string>
|
||||||
|
<string name="fragment_recipes_delete_recipe_confirm_dialog_message">Are you sure you want to delete %1$s? This cannot be undone.</string>
|
||||||
|
<string name="fragment_recipes_delete_recipe_confirm_dialog_positive_btn">Confirm</string>
|
||||||
|
<string name="fragment_recipes_delete_recipe_confirm_dialog_negative_btn">Cancel</string>
|
||||||
<string name="menu_navigation_drawer_change_url">Change URL</string>
|
<string name="menu_navigation_drawer_change_url">Change URL</string>
|
||||||
<string name="search_recipes_hint">Search recipes</string>
|
<string name="search_recipes_hint">Search recipes</string>
|
||||||
<string name="menu_navigation_drawer_header" translatable="false">@string/app_name</string>
|
<string name="menu_navigation_drawer_header" translatable="false">@string/app_name</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user