-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
276 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
.../main/java/ru/klauz42/yetanotheronlinestore/domain/usecases/GetFavoriteProductsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.klauz42.yetanotheronlinestore.domain.usecases | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import ru.klauz42.yetanotheronlinestore.domain.models.FavoritesRepository | ||
import ru.klauz42.yetanotheronlinestore.domain.models.entities.Product | ||
import javax.inject.Inject | ||
|
||
class GetFavoriteProductsUseCase @Inject constructor( | ||
private val repository: FavoritesRepository | ||
) { | ||
operator fun invoke(): Flow<List<Product>> { | ||
return repository.getFavorites() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ion/catalog/ProductMarginItemDecorator.kt → ...resentation/ProductMarginItemDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...presentation/catalog/ProductViewHolder.kt → ...nestore/presentation/ProductViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...c/main/java/ru/klauz42/yetanotheronlinestore/presentation/favorites/FavoritesViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ru.klauz42.yetanotheronlinestore.presentation.favorites | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.asLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import ru.klauz42.yetanotheronlinestore.domain.models.entities.Product | ||
import ru.klauz42.yetanotheronlinestore.domain.usecases.GetFavoriteProductsUseCase | ||
import ru.klauz42.yetanotheronlinestore.domain.usecases.GetFavoritesIdUseCase | ||
import ru.klauz42.yetanotheronlinestore.domain.usecases.SetLikedProductStatusUseCase | ||
import javax.inject.Inject | ||
|
||
class FavoritesViewModel @Inject constructor( | ||
getFavoritesUseCase: GetFavoriteProductsUseCase, | ||
private val setLikedProductStatusUseCase: SetLikedProductStatusUseCase, | ||
getFavoriteIds: GetFavoritesIdUseCase, | ||
) : ViewModel() { | ||
|
||
fun updateLikedStatus(id: String, isLiked: Boolean) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
setLikedProductStatusUseCase(id, isLiked) | ||
} | ||
} | ||
|
||
private val _productsLiveData = | ||
getFavoritesUseCase().asLiveData(viewModelScope.coroutineContext) | ||
val productsLiveData: LiveData<List<Product>> = _productsLiveData | ||
|
||
val favoriteIds = getFavoriteIds().asLiveData(viewModelScope.coroutineContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_selected="true"> | ||
<inset android:inset="3dp"> | ||
<shape android:shape="rectangle"> | ||
<solid android:color="@color/white" /> | ||
<corners android:radius="@dimen/button_large_corner_radius" /> | ||
</shape> | ||
</inset> | ||
</item> | ||
<item android:state_enabled="false"> | ||
<inset android:inset="3dp"> | ||
<shape android:shape="rectangle"> | ||
<solid android:color="@color/transparent" /> | ||
<corners android:radius="@dimen/button_large_corner_radius" /> | ||
</shape> | ||
</inset> | ||
</item> | ||
</selector> |
9 changes: 9 additions & 0 deletions
9
app/src/main/res/drawable/tab_layout_favorites_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_enabled="true"> | ||
<shape android:shape="rectangle"> | ||
<solid android:color="@color/text_edit_sign_in_bg_color"/> | ||
<corners android:radius="@dimen/text_input_sign_in_radius"/> | ||
</shape> | ||
</item> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.