Merge pull request #137 from kirmanak/ux

Some UI/UX improvements
This commit is contained in:
Kirill Kamakin
2023-04-07 14:51:54 +02:00
committed by GitHub
9 changed files with 37 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ interface RecipeRepo {
suspend fun refreshRecipes()
suspend fun updateIsRecipeFavorite(recipeSlug: String, isFavorite: Boolean): Result<Unit>
suspend fun updateIsRecipeFavorite(recipeSlug: String, isFavorite: Boolean): Result<Boolean>
suspend fun deleteRecipe(entity: RecipeSummaryEntity): Result<Unit>
}

View File

@@ -75,12 +75,13 @@ class RecipeRepoImpl @Inject constructor(
override suspend fun updateIsRecipeFavorite(
recipeSlug: String,
isFavorite: Boolean,
): Result<Unit> = runCatchingExceptCancel {
): Result<Boolean> = runCatchingExceptCancel {
logger.v { "updateIsRecipeFavorite() called with: recipeSlug = $recipeSlug, isFavorite = $isFavorite" }
dataSource.updateIsRecipeFavorite(recipeSlug, isFavorite)
val favorites = dataSource.getFavoriteRecipes()
storage.updateFavoriteRecipes(favorites)
pagingSourceFactory.invalidate()
favorites.contains(recipeSlug)
}.onFailure {
logger.e(it) { "Can't update recipe's is favorite status" }
}

View File

@@ -177,6 +177,15 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
logger.d { "onFavoriteClick: result is $it" }
if (it.isFailure) {
showLongToast(R.string.fragment_recipes_favorite_update_failed)
} else {
val name = event.recipeSummaryEntity.name
val isFavorite = it.getOrThrow()
val message = if (isFavorite) {
getString(R.string.fragment_recipes_favorite_added, name)
} else {
getString(R.string.fragment_recipes_favorite_removed, name)
}
showLongToast(message)
}
}
}

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M784,840L532,588Q502,612 463,626Q424,640 380,640Q271,640 195.5,564.5Q120,489 120,380Q120,271 195.5,195.5Q271,120 380,120Q489,120 564.5,195.5Q640,271 640,380Q640,424 626,463Q612,502 588,532L840,784L784,840ZM380,560Q455,560 507.5,507.5Q560,455 560,380Q560,305 507.5,252.5Q455,200 380,200Q305,200 252.5,252.5Q200,305 200,380Q200,455 252.5,507.5Q305,560 380,560Z" />
</vector>

View File

@@ -20,7 +20,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="0"
tools:itemCount="10"
tools:listitem="@layout/view_holder_recipe" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@@ -5,7 +5,7 @@
style="?materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/margin_small"
android:layout_marginVertical="@dimen/margin_medium"
android:layout_marginStart="@dimen/margin_medium"
android:layout_marginEnd="@dimen/margin_medium">

View File

@@ -9,28 +9,32 @@
<ImageView
android:id="@+id/navigation_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginVertical="@dimen/margin_small"
android:layout_marginStart="@dimen/margin_small"
android:contentDescription="@string/view_toolbar_navigation_icon_content_description"
android:src="@drawable/ic_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/search_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_margin="@dimen/margin_small"
android:background="@null"
android:drawableStart="@drawable/ic_search"
android:hint="@string/search_recipes_hint"
android:importantForAutofill="no"
android:inputType="textFilter"
android:textAppearance="?textAppearanceBodyLarge"
android:textAppearance="?textAppearanceTitleLarge"
android:textColor="?colorOnSurfaceVariant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/navigation_icon"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:text="Search request" />
</merge>

View File

@@ -63,4 +63,6 @@
<string name="view_holder_recipe_delete_content_description">Удалить рецепт</string>
<string name="fragment_recipes_delete_recipe_confirm_dialog_positive_btn">Подтвердить</string>
<string name="fragment_recipes_delete_recipe_confirm_dialog_negative_btn">Отмена</string>
<string name="fragment_recipes_favorite_added">%1$s добавлено в избранное</string>
<string name="fragment_recipes_favorite_removed">%1$s удалено из избранного</string>
</resources>

View File

@@ -66,4 +66,6 @@
<string name="view_holder_recipe_favorite_content_description">Item is favorite</string>
<string name="view_holder_recipe_non_favorite_content_description">Item is not favorite</string>
<string name="view_holder_recipe_delete_content_description">Delete recipe</string>
<string name="fragment_recipes_favorite_added">Added %1$s to favorites</string>
<string name="fragment_recipes_favorite_removed">Removed %1$s from favorites</string>
</resources>