Skip to content

Commit

Permalink
Changelog:
Browse files Browse the repository at this point in the history
Fix exploration Screen
  • Loading branch information
gab-stargazer committed Dec 10, 2023
1 parent 1d79c39 commit 17edbf9
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lelestacia.hayate.feature.anime.exploration.ui

internal object Constant {
const val AIRING_ANIME_TYPE_KEY = "airing_anime_type"

const val POPULAR_ANIME_TYPE_KEY = "popular_anime_type"
const val POPULAR_ANIME_FILTER_KEY = "popular_anime_filter"
const val POPULAR_ANIME_RATING_KEY = "popular_anime_rating"

const val UPCOMING_ANIME_TYPE_KEY = "upcoming_anime_type"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
Expand Down Expand Up @@ -117,8 +118,10 @@ internal object InternalExploreModuleAPI : FeatureApi {
text = title,
style = MaterialTheme.typography.titleSmall.copy(
fontWeight = FontWeight.Bold,
fontFamily = quickSandFamily
)
fontFamily = quickSandFamily,
),
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lelestacia.hayate.feature.anime.exploration.ui.viewmodel

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
Expand All @@ -9,6 +10,7 @@ import com.lelestacia.hayate.feature.anime.core.domain.model.Anime
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.airing.AiringAnimeEvent
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.airing.AiringAnimeState
import com.lelestacia.hayate.feature.anime.exploration.domain.usecases.AnimeUseCases
import com.lelestacia.hayate.feature.anime.exploration.ui.Constant.AIRING_ANIME_TYPE_KEY
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand All @@ -22,12 +24,21 @@ import javax.inject.Inject

@HiltViewModel
internal class AiringViewModel @Inject constructor(
private val animeUseCases: AnimeUseCases
private val animeUseCases: AnimeUseCases,
private val savedStateHandle: SavedStateHandle
) : BaseViewModel() {

private val animeType: MutableStateFlow<AnimeType?> = MutableStateFlow(null)
private val animeType: StateFlow<AnimeType?> = savedStateHandle
.getStateFlow(
key = AIRING_ANIME_TYPE_KEY,
initialValue = null
)

private val _state: MutableStateFlow<AiringAnimeState> = MutableStateFlow(AiringAnimeState())
private val _state: MutableStateFlow<AiringAnimeState> = MutableStateFlow(
AiringAnimeState(
animeType = savedStateHandle[AIRING_ANIME_TYPE_KEY]
)
)
val state: StateFlow<AiringAnimeState> = _state.asStateFlow()

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -40,9 +51,7 @@ internal class AiringViewModel @Inject constructor(
fun onEvent(event: AiringAnimeEvent) = viewModelScope.launch {
when (event) {
is AiringAnimeEvent.OnAnimeFilterChanged -> {
animeType.update {
event.filter
}
savedStateHandle[AIRING_ANIME_TYPE_KEY] = event.filter

_state.update {
it.gridState.scrollToItem(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lelestacia.hayate.feature.anime.exploration.ui.viewmodel

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
Expand All @@ -11,6 +12,9 @@ import com.lelestacia.hayate.feature.anime.core.domain.model.Anime
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.popular.PopularAnimeEvent
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.popular.PopularAnimeState
import com.lelestacia.hayate.feature.anime.exploration.domain.usecases.AnimeUseCases
import com.lelestacia.hayate.feature.anime.exploration.ui.Constant.POPULAR_ANIME_FILTER_KEY
import com.lelestacia.hayate.feature.anime.exploration.ui.Constant.POPULAR_ANIME_RATING_KEY
import com.lelestacia.hayate.feature.anime.exploration.ui.Constant.POPULAR_ANIME_TYPE_KEY
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand All @@ -27,12 +31,25 @@ import javax.inject.Inject

@HiltViewModel
internal class PopularViewModel @Inject constructor(
private val animeUseCases: AnimeUseCases
private val animeUseCases: AnimeUseCases,
private val savedStateHandle: SavedStateHandle
) : BaseViewModel() {

private val animeType: MutableStateFlow<AnimeType?> = MutableStateFlow(null)
private val animeFilter: MutableStateFlow<AnimeFilter?> = MutableStateFlow(null)
private val animeRating: MutableStateFlow<AnimeRating?> = MutableStateFlow(null)
private val animeType: StateFlow<AnimeType?> = savedStateHandle
.getStateFlow(
key = POPULAR_ANIME_TYPE_KEY,
initialValue = null
)
private val animeFilter: StateFlow<AnimeFilter?> = savedStateHandle
.getStateFlow(
key = POPULAR_ANIME_FILTER_KEY,
initialValue = null
)
private val animeRating: StateFlow<AnimeRating?> = savedStateHandle
.getStateFlow(
key = POPULAR_ANIME_RATING_KEY,
initialValue = null
)

private val filter: Flow<PopularAnimeFilter> =
combine(
Expand All @@ -52,7 +69,13 @@ internal class PopularViewModel @Inject constructor(
)

private val _state: MutableStateFlow<PopularAnimeState> =
MutableStateFlow(PopularAnimeState())
MutableStateFlow(
PopularAnimeState(
animeType = savedStateHandle[POPULAR_ANIME_TYPE_KEY],
animeFilter = savedStateHandle[POPULAR_ANIME_FILTER_KEY],
animeRating = savedStateHandle[POPULAR_ANIME_RATING_KEY]
)
)
val state: StateFlow<PopularAnimeState> = _state.asStateFlow()

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -67,11 +90,7 @@ internal class PopularViewModel @Inject constructor(
fun onEvent(event: PopularAnimeEvent) = viewModelScope.launch {
when (event) {
is PopularAnimeEvent.OnAnimeFilterChanged -> {
animeFilter.update {
// NOTE:
// Theres no Need to copy and stuff since its only 1 value
event.filter
}
savedStateHandle[POPULAR_ANIME_FILTER_KEY] = event.filter

_state.update {
it.gridState.scrollToItem(0)
Expand Down Expand Up @@ -99,11 +118,7 @@ internal class PopularViewModel @Inject constructor(
}

is PopularAnimeEvent.OnAnimeTypeChanged -> {
animeType.update {
// NOTE:
// Theres no Need to copy and stuff since its only 1 value
event.type
}
savedStateHandle[POPULAR_ANIME_TYPE_KEY] = event.type

_state.update {
it.gridState.scrollToItem(0)
Expand All @@ -123,11 +138,7 @@ internal class PopularViewModel @Inject constructor(
}

is PopularAnimeEvent.OnAnimeRatingChanged -> {
animeRating.update {
// NOTE:
// Theres no Need to copy and stuff since its only 1 value
event.rating
}
savedStateHandle[POPULAR_ANIME_RATING_KEY] = event.rating

_state.update {
it.gridState.scrollToItem(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lelestacia.hayate.feature.anime.exploration.ui.viewmodel

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
Expand All @@ -9,6 +10,7 @@ import com.lelestacia.hayate.feature.anime.core.domain.model.Anime
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.upcoming.UpcomingAnimeEvent
import com.lelestacia.hayate.feature.anime.exploration.domain.presenter.upcoming.UpcomingAnimeState
import com.lelestacia.hayate.feature.anime.exploration.domain.usecases.AnimeUseCases
import com.lelestacia.hayate.feature.anime.exploration.ui.Constant.UPCOMING_ANIME_TYPE_KEY
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand All @@ -22,13 +24,22 @@ import javax.inject.Inject

@HiltViewModel
internal class UpcomingViewModel @Inject constructor(
private val animeUseCases: AnimeUseCases
private val animeUseCases: AnimeUseCases,
private val savedStateHandle: SavedStateHandle
) : BaseViewModel() {

private val animeType: MutableStateFlow<AnimeType?> = MutableStateFlow(null)
private val animeType: StateFlow<AnimeType?> = savedStateHandle
.getStateFlow(
key = UPCOMING_ANIME_TYPE_KEY,
initialValue = null
)

private val _state: MutableStateFlow<UpcomingAnimeState> =
MutableStateFlow(UpcomingAnimeState())
MutableStateFlow(
UpcomingAnimeState(
animeType = savedStateHandle[UPCOMING_ANIME_TYPE_KEY]
)
)
val state: StateFlow<UpcomingAnimeState> = _state.asStateFlow()

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -41,9 +52,7 @@ internal class UpcomingViewModel @Inject constructor(
fun onEvent(event: UpcomingAnimeEvent) = viewModelScope.launch {
when (event) {
is UpcomingAnimeEvent.OnAnimeFilterChanged -> {
animeType.update {
event.filter
}
savedStateHandle[UPCOMING_ANIME_TYPE_KEY] = event.filter

_state.update {
it.gridState.scrollToItem(0)
Expand Down

0 comments on commit 17edbf9

Please sign in to comment.