Skip to content

Commit

Permalink
Remove all codes for genre filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Nov 9, 2024
1 parent 208befd commit f16b83d
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion core/resources/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<string name="menu_filter">μ˜ν™” ν•„ν„°</string>
<string name="filter_category_theater">κ·Ήμž₯ ν•„ν„°</string>
<string name="filter_category_age">μ—°λ Ή ν•„ν„°</string>
<string name="filter_category_genre">μž₯λ₯΄ ν•„ν„°</string>

<string name="action_toast_opendate_alarm">⏰ μ˜ν™”κ°€ κ°œλ΄‰ν•  λ•Œ, μ•Œλ €λ“œλ¦΄κ²Œμš”.</string>

Expand Down
1 change: 0 additions & 1 deletion core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<string name="menu_filter">Movie Filter</string>
<string name="filter_category_theater">Theater Filter</string>
<string name="filter_category_age">Age Filter</string>
<string name="filter_category_genre">Genre Filter</string>

<string name="action_toast_opendate_alarm">⏰ I\'ll let you know when released.</string>

Expand Down
26 changes: 0 additions & 26 deletions data/model/src/main/java/soup/movie/model/settings/GenreFilter.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface MovieRepository {
fun getPlanMovieList(): Flow<List<MovieModel>>
suspend fun updatePlanMovieList()
suspend fun getMovieDetail(movieId: String): MovieDetailModel
suspend fun getGenreList(): List<String>
suspend fun searchMovie(query: String): List<MovieModel>

fun getFavoriteMovieList(): Flow<List<MovieModel>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ class MovieRepositoryImpl @Inject constructor(
}
}

override suspend fun getGenreList(): List<String> {
return try {
local.getAllMovieList()
.mapNotNull { it.genres }
.flatten()
.toSet()
.toList()
} catch (t: Throwable) {
Logger.w(t)
emptyList()
}
}

override suspend fun searchMovie(query: String): List<MovieModel> {
return local.getAllMovieList().asSequence()
.filter { it.isMatchedWith(query) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,9 +27,6 @@ interface AppSettings {
suspend fun setAgeFilter(ageFilter: AgeFilter)
fun getAgeFilterFlow(): Flow<AgeFilter>

suspend fun setGenreFilter(genreFilter: GenreFilter)
fun getGenreFilterFlow(): Flow<GenreFilter>

suspend fun setThemeOption(themeOption: String)
suspend fun getThemeOption(): String
fun getThemeOptionFlow(): Flow<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,7 +60,7 @@ class AppSettingsImpl @Inject constructor(

init {
coroutineScope.launch {
clearFavoriteTheaterList()
clearStaleData()
}
}

Expand Down Expand Up @@ -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<GenreFilter> {
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) {
Expand All @@ -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 = "|"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ fun AppSettings.getMovieFilterFlow(): Flow<MovieFilter> {
return combine(
getTheaterFilterFlow(),
getAgeFilterFlow(),
getGenreFilterFlow(),
transform = { theaterFilter, ageFilter, genreFilter ->
transform = { theaterFilter, ageFilter ->
MovieFilter(
theaterFilter,
ageFilter,
genreFilter,
)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -67,15 +58,6 @@ fun HomeFilterScreen(
HomeFilterDivider()
HomeFilterAge(viewModel)
}
item {
HomeFilterDivider()
HomeFilterGenre(
items = viewModel.genreFilterList,
onCheckedChange = { genreFilter, isChecked ->
viewModel.onGenreFilterClick(genreFilter.name, isChecked)
},
)
}
}
}

Expand Down Expand Up @@ -220,62 +202,3 @@ private fun HomeFilterAgeText(
.padding(vertical = 6.dp),
)
}

@OptIn(
ExperimentalMaterialApi::class,
ExperimentalLayoutApi::class,
)
@Composable
private fun HomeFilterGenre(
items: List<GenreFilterItem>,
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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ data class AgeFilterUiModel(
val has15: Boolean,
val has19: Boolean,
)

@Keep
class GenreFilterItem(
val name: String,
val isChecked: Boolean,
)
Loading

0 comments on commit f16b83d

Please sign in to comment.