From ea5a4f46fbe954d0361704f8c88e7723e1c37978 Mon Sep 17 00:00:00 2001 From: Sungyong An Date: Sat, 9 Nov 2024 23:38:42 +0900 Subject: [PATCH] Remove all codes for genre filter (#305) --- .../core/designsystem/icon/MovieIcons.kt | 2 - .../src/main/res/values-ko/strings.xml | 1 - .../resources/src/main/res/values/strings.xml | 1 - .../soup/movie/model/settings/GenreFilter.kt | 26 ------- .../movie/data/repository/MovieRepository.kt | 1 - .../repository/impl/MovieRepositoryImpl.kt | 13 ---- .../soup/movie/data/settings/AppSettings.kt | 4 - .../data/settings/impl/AppSettingsImpl.kt | 31 +------- .../home/impl/domain/AppSettingsExt.kt | 4 +- .../feature/home/impl/domain/MovieFilter.kt | 11 +-- .../home/impl/filter/HomeFilterScreen.kt | 77 ------------------- .../home/impl/filter/HomeFilterUiModel.kt | 6 -- .../home/impl/filter/HomeFilterViewModel.kt | 42 ---------- 13 files changed, 6 insertions(+), 213 deletions(-) delete mode 100644 data/model/src/main/java/soup/movie/model/settings/GenreFilter.kt diff --git a/core/designsystem/src/main/java/soup/movie/core/designsystem/icon/MovieIcons.kt b/core/designsystem/src/main/java/soup/movie/core/designsystem/icon/MovieIcons.kt index 4b6388a61..0358bb8f1 100644 --- a/core/designsystem/src/main/java/soup/movie/core/designsystem/icon/MovieIcons.kt +++ b/core/designsystem/src/main/java/soup/movie/core/designsystem/icon/MovieIcons.kt @@ -19,7 +19,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.ArrowBack import androidx.compose.material.icons.automirrored.rounded.Subject import androidx.compose.material.icons.outlined.PrivacyTip -import androidx.compose.material.icons.rounded.Check import androidx.compose.material.icons.rounded.Close import androidx.compose.material.icons.rounded.FilterList import androidx.compose.material.icons.rounded.Info @@ -32,7 +31,6 @@ import soup.movie.core.designsystem.R object MovieIcons { val ArrowBack = Icons.AutoMirrored.Rounded.ArrowBack - val Check = Icons.Rounded.Check val Close = Icons.Rounded.Close val FilterList = Icons.Rounded.FilterList val Info = Icons.Rounded.Info diff --git a/core/resources/src/main/res/values-ko/strings.xml b/core/resources/src/main/res/values-ko/strings.xml index ae44beb23..5fddf5ae2 100644 --- a/core/resources/src/main/res/values-ko/strings.xml +++ b/core/resources/src/main/res/values-ko/strings.xml @@ -15,7 +15,6 @@ 영화 필터 극장 필터 연령 필터 - 장르 필터 ⏰ 영화가 개봉할 때, 알려드릴게요. diff --git a/core/resources/src/main/res/values/strings.xml b/core/resources/src/main/res/values/strings.xml index bff0e296f..4f8600b71 100644 --- a/core/resources/src/main/res/values/strings.xml +++ b/core/resources/src/main/res/values/strings.xml @@ -15,7 +15,6 @@ Movie Filter Theater Filter Age Filter - Genre Filter ⏰ I\'ll let you know when released. diff --git a/data/model/src/main/java/soup/movie/model/settings/GenreFilter.kt b/data/model/src/main/java/soup/movie/model/settings/GenreFilter.kt deleted file mode 100644 index 135657ffa..000000000 --- a/data/model/src/main/java/soup/movie/model/settings/GenreFilter.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2021 SOUP - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package soup.movie.model.settings - -class GenreFilter( - val blacklist: Set, -) { - - companion object { - - const val GENRE_ETC = "장르 없음" - } -} diff --git a/data/repository/api/src/main/java/soup/movie/data/repository/MovieRepository.kt b/data/repository/api/src/main/java/soup/movie/data/repository/MovieRepository.kt index bb0e37803..91007053c 100644 --- a/data/repository/api/src/main/java/soup/movie/data/repository/MovieRepository.kt +++ b/data/repository/api/src/main/java/soup/movie/data/repository/MovieRepository.kt @@ -28,7 +28,6 @@ interface MovieRepository { fun getPlanMovieList(): Flow> suspend fun updatePlanMovieList() suspend fun getMovieDetail(movieId: String): MovieDetailModel - suspend fun getGenreList(): List suspend fun searchMovie(query: String): List fun getFavoriteMovieList(): Flow> diff --git a/data/repository/impl/src/main/java/soup/movie/data/repository/impl/MovieRepositoryImpl.kt b/data/repository/impl/src/main/java/soup/movie/data/repository/impl/MovieRepositoryImpl.kt index dfdbcad79..70f63e864 100644 --- a/data/repository/impl/src/main/java/soup/movie/data/repository/impl/MovieRepositoryImpl.kt +++ b/data/repository/impl/src/main/java/soup/movie/data/repository/impl/MovieRepositoryImpl.kt @@ -89,19 +89,6 @@ class MovieRepositoryImpl @Inject constructor( } } - override suspend fun getGenreList(): List { - return try { - local.getAllMovieList() - .mapNotNull { it.genres } - .flatten() - .toSet() - .toList() - } catch (t: Throwable) { - Logger.w(t) - emptyList() - } - } - override suspend fun searchMovie(query: String): List { return local.getAllMovieList().asSequence() .filter { it.isMatchedWith(query) } diff --git a/data/settings/api/src/main/java/soup/movie/data/settings/AppSettings.kt b/data/settings/api/src/main/java/soup/movie/data/settings/AppSettings.kt index 93f3c702a..d9a02b90f 100644 --- a/data/settings/api/src/main/java/soup/movie/data/settings/AppSettings.kt +++ b/data/settings/api/src/main/java/soup/movie/data/settings/AppSettings.kt @@ -17,7 +17,6 @@ package soup.movie.data.settings import kotlinx.coroutines.flow.Flow import soup.movie.model.settings.AgeFilter -import soup.movie.model.settings.GenreFilter import soup.movie.model.settings.TheaterFilter interface AppSettings { @@ -28,9 +27,6 @@ interface AppSettings { suspend fun setAgeFilter(ageFilter: AgeFilter) fun getAgeFilterFlow(): Flow - suspend fun setGenreFilter(genreFilter: GenreFilter) - fun getGenreFilterFlow(): Flow - suspend fun setThemeOption(themeOption: String) suspend fun getThemeOption(): String fun getThemeOptionFlow(): Flow diff --git a/data/settings/impl/src/main/java/soup/movie/data/settings/impl/AppSettingsImpl.kt b/data/settings/impl/src/main/java/soup/movie/data/settings/impl/AppSettingsImpl.kt index 0a05eebb4..4cdaca6c8 100644 --- a/data/settings/impl/src/main/java/soup/movie/data/settings/impl/AppSettingsImpl.kt +++ b/data/settings/impl/src/main/java/soup/movie/data/settings/impl/AppSettingsImpl.kt @@ -35,7 +35,6 @@ import soup.movie.common.ApplicationScope import soup.movie.common.IoDispatcher import soup.movie.data.settings.AppSettings import soup.movie.model.settings.AgeFilter -import soup.movie.model.settings.GenreFilter import soup.movie.model.settings.TheaterFilter import javax.inject.Inject import javax.inject.Singleton @@ -61,7 +60,7 @@ class AppSettingsImpl @Inject constructor( init { coroutineScope.launch { - clearFavoriteTheaterList() + clearStaleData() } } @@ -96,22 +95,6 @@ class AppSettingsImpl @Inject constructor( } } - private val genreFilterKey = stringPreferencesKey("favorite_genre") - - override suspend fun setGenreFilter(genreFilter: GenreFilter) { - context.dataStore.edit { settings -> - settings[genreFilterKey] = - genreFilter.blacklist.joinToString(separator = SEPARATOR) - } - } - - override fun getGenreFilterFlow(): Flow { - return context.dataStore.data.map { preferences -> - val genreString = preferences[genreFilterKey].orEmpty() - GenreFilter(genreString.split(SEPARATOR).toSet()) - } - } - private val themeOptionKey = stringPreferencesKey("theme_option") override suspend fun setThemeOption(themeOption: String) { @@ -132,18 +115,12 @@ class AppSettingsImpl @Inject constructor( } } - private val favoriteTheaterListKey = stringPreferencesKey("favorite_theaters") - - private suspend fun clearFavoriteTheaterList() { + private suspend fun clearStaleData() { withContext(ioDispatcher) { context.dataStore.edit { settings -> - settings.remove(favoriteTheaterListKey) + settings.remove(stringPreferencesKey("favorite_theaters")) + settings.remove(stringPreferencesKey("favorite_genre")) } } } - - companion object { - - private const val SEPARATOR = "|" - } } diff --git a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/AppSettingsExt.kt b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/AppSettingsExt.kt index 7835b8e3e..341780277 100644 --- a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/AppSettingsExt.kt +++ b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/AppSettingsExt.kt @@ -23,12 +23,10 @@ fun AppSettings.getMovieFilterFlow(): Flow { return combine( getTheaterFilterFlow(), getAgeFilterFlow(), - getGenreFilterFlow(), - transform = { theaterFilter, ageFilter, genreFilter -> + transform = { theaterFilter, ageFilter -> MovieFilter( theaterFilter, ageFilter, - genreFilter, ) }, ) diff --git a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/MovieFilter.kt b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/MovieFilter.kt index c8d8fd056..922131f7a 100644 --- a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/MovieFilter.kt +++ b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/domain/MovieFilter.kt @@ -17,20 +17,16 @@ package soup.movie.feature.home.impl.domain import soup.movie.model.MovieModel import soup.movie.model.settings.AgeFilter -import soup.movie.model.settings.GenreFilter -import soup.movie.model.settings.GenreFilter.Companion.GENRE_ETC import soup.movie.model.settings.TheaterFilter class MovieFilter( private val theaterFilter: TheaterFilter, private val ageFilter: AgeFilter, - private val genreFilter: GenreFilter, ) { operator fun invoke(movie: MovieModel): Boolean { return movie.isFilterBy(theaterFilter) && - movie.isFilterBy(ageFilter) && - movie.isFilterBy(genreFilter) + movie.isFilterBy(ageFilter) } private fun MovieModel.isFilterBy(theaterFilter: TheaterFilter): Boolean { @@ -48,9 +44,4 @@ class MovieFilter( (ageFilter.has15() && age in 15..18) || (ageFilter.has19() && age >= 19) } - - private fun MovieModel.isFilterBy(genreFilter: GenreFilter): Boolean { - return genres?.any { it !in genreFilter.blacklist } - ?: (genres.isNullOrEmpty() && GENRE_ETC !in genreFilter.blacklist) - } } diff --git a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterScreen.kt b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterScreen.kt index a1803b14b..0e4759b5d 100644 --- a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterScreen.kt +++ b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterScreen.kt @@ -15,13 +15,10 @@ */ package soup.movie.feature.home.impl.filter -import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -32,24 +29,18 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.ChipDefaults import androidx.compose.material.Divider -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.FilterChip import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import soup.movie.core.designsystem.icon.MovieIcons import soup.movie.core.designsystem.theme.MovieTheme import soup.movie.resources.R @@ -67,15 +58,6 @@ fun HomeFilterScreen( HomeFilterDivider() HomeFilterAge(viewModel) } - item { - HomeFilterDivider() - HomeFilterGenre( - items = viewModel.genreFilterList, - onCheckedChange = { genreFilter, isChecked -> - viewModel.onGenreFilterClick(genreFilter.name, isChecked) - }, - ) - } } } @@ -220,62 +202,3 @@ private fun HomeFilterAgeText( .padding(vertical = 6.dp), ) } - -@OptIn( - ExperimentalMaterialApi::class, - ExperimentalLayoutApi::class, -) -@Composable -private fun HomeFilterGenre( - items: List, - onCheckedChange: (GenreFilterItem, Boolean) -> Unit, -) { - Column(modifier = Modifier.padding(vertical = 24.dp, horizontal = 16.dp)) { - HomeFilterCategory(text = stringResource(R.string.filter_category_genre)) - FlowRow( - modifier = Modifier.padding(top = 12.dp), - horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.Start), - ) { - items.forEach { genreFilter -> - GenreFilterChip( - genreFilter.name, - checked = genreFilter.isChecked, - onCheckedChange = { onCheckedChange(genreFilter, it) }, - ) - } - } - } -} - -@ExperimentalMaterialApi -@Composable -private fun GenreFilterChip( - text: String, - checked: Boolean, - onCheckedChange: (Boolean) -> Unit, - enabled: Boolean = true, -) { - FilterChip( - selected = checked, - onClick = { onCheckedChange(!checked) }, - selectedIcon = { - Image( - MovieIcons.Check, - contentDescription = null, - colorFilter = ColorFilter.tint(Color(0x88000000)), - ) - }, - enabled = enabled, - colors = ChipDefaults.filterChipColors( - selectedBackgroundColor = Color(0xEEDDDDDD), - selectedContentColor = Color(0x88000000), - backgroundColor = Color(0x33DDDDDD), - contentColor = Color(0x44000000), - ), - ) { - Text( - text = text, - fontWeight = FontWeight.Bold, - ) - } -} diff --git a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterUiModel.kt b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterUiModel.kt index 78c714000..df3afd9ec 100644 --- a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterUiModel.kt +++ b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterUiModel.kt @@ -31,9 +31,3 @@ data class AgeFilterUiModel( val has15: Boolean, val has19: Boolean, ) - -@Keep -class GenreFilterItem( - val name: String, - val isChecked: Boolean, -) diff --git a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterViewModel.kt b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterViewModel.kt index 34f8a9dcd..3e668e1ff 100644 --- a/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterViewModel.kt +++ b/feature/home/impl/src/main/java/soup/movie/feature/home/impl/filter/HomeFilterViewModel.kt @@ -15,9 +15,6 @@ */ package soup.movie.feature.home.impl.filter -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel @@ -35,7 +32,6 @@ import soup.movie.model.settings.AgeFilter.Companion.FLAG_AGE_12 import soup.movie.model.settings.AgeFilter.Companion.FLAG_AGE_15 import soup.movie.model.settings.AgeFilter.Companion.FLAG_AGE_19 import soup.movie.model.settings.AgeFilter.Companion.FLAG_AGE_ALL -import soup.movie.model.settings.GenreFilter import soup.movie.model.settings.TheaterFilter import soup.movie.model.settings.TheaterFilter.Companion.FLAG_THEATER_CGV import soup.movie.model.settings.TheaterFilter.Companion.FLAG_THEATER_LOTTE @@ -49,7 +45,6 @@ class HomeFilterViewModel @Inject constructor( ) : ViewModel() { private var theaterFilter: TheaterFilter? = null - private var lastGenreFilter: GenreFilter? = null private val _theaterUiModel = MutableStateFlow(null) val theaterUiModel: StateFlow = _theaterUiModel @@ -63,9 +58,6 @@ class HomeFilterViewModel @Inject constructor( started = SharingStarted.WhileSubscribed(5_000), ) - var genreFilterList by mutableStateOf>(emptyList()) - private set - init { viewModelScope.launch { appSettings.getTheaterFilterFlow() @@ -75,26 +67,6 @@ class HomeFilterViewModel @Inject constructor( _theaterUiModel.emit(it.toUiModel()) } } - viewModelScope.launch { - val allGenre = getGenreList() - appSettings.getGenreFilterFlow() - .collect { filter -> - lastGenreFilter = filter - genreFilterList = allGenre.map { - GenreFilterItem( - name = it, - isChecked = filter.blacklist.contains(it).not(), - ) - } - } - } - } - - private suspend fun getGenreList(): List { - return mutableListOf().apply { - addAll(repository.getGenreList()) - add(GenreFilter.GENRE_ETC) - } } private fun TheaterFilter.toUiModel(): TheaterFilterUiModel { @@ -162,18 +134,4 @@ class HomeFilterViewModel @Inject constructor( appSettings.setAgeFilter(AgeFilter(flags)) } } - - fun onGenreFilterClick(genre: String, isChecked: Boolean) { - val lastGenreSet = lastGenreFilter?.blacklist?.toMutableSet() ?: return - val changed = if (isChecked) { - lastGenreSet.remove(genre) - } else { - lastGenreSet.add(genre) - } - if (changed) { - viewModelScope.launch { - appSettings.setGenreFilter(GenreFilter(lastGenreSet)) - } - } - } }