Skip to content

Commit

Permalink
hide adult content if not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 27, 2024
1 parent 6967742 commit 241f1b7
Show file tree
Hide file tree
Showing 24 changed files with 482 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ data class Medium(
}

@Transient
val characters: Set<Character> = _characters.filterNot { it.id == 36309 }.sortedByDescending {
it.isFavorite.toInt()
}.toSet()
val characters: Set<Character> = _characters.filterNot { it.id == 36309 }.toSet()

@Transient
val isFavoriteBlocked: Boolean = _isFavoriteBlocked || type == MediaType.UNKNOWN__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import dev.datlag.aniflow.firebase.initialize
import dev.datlag.aniflow.other.BurningSeriesResolver
import dev.datlag.aniflow.other.Constants
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.settings.DataStoreUserSettings
import dev.datlag.aniflow.settings.Settings
import dev.datlag.aniflow.settings.UserSettingsSerializer
import dev.datlag.aniflow.settings.*
import io.github.aakira.napier.Napier
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
Expand Down Expand Up @@ -101,9 +99,24 @@ actual object PlatformModule {
)
)
}
bindSingleton {
val app: Context = instance()
DataStoreFactory.create(
storage = OkioStorage(
fileSystem = FileSystem.SYSTEM,
serializer = AppSettingsSerializer,
producePath = {
app.filesDir.toOkioPath().resolve("datastore").resolve("app.settings")
}
)
)
}
bindSingleton<Settings.PlatformUserSettings> {
DataStoreUserSettings(instance())
}
bindSingleton<Settings.PlatformAppSettings> {
DataStoreAppSettings(instance())
}
bindSingleton<BurningSeriesResolver> {
BurningSeriesResolver(context = instance())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ data object StateSaver {
var mediaOverview: Int = 0
var mediaOverviewOffset: Int = 0

var settingsOverview: Int = 0
var settingsOverviewOffset: Int = 0

data object Home {
var airingOverview: Int = 0
var airingOverviewOffset: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.datlag.aniflow.ui.navigation.screen.initial

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.ExperimentalDecomposeApi
Expand All @@ -14,6 +15,7 @@ import dev.datlag.aniflow.common.onRender
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.ContentHolderComponent
import dev.datlag.aniflow.ui.navigation.screen.initial.home.HomeScreenComponent
import dev.datlag.aniflow.ui.navigation.screen.initial.settings.SettingsScreenComponent
import org.kodein.di.DI

class InitialScreenComponent(
Expand All @@ -26,6 +28,10 @@ class InitialScreenComponent(
InitialComponent.PagerItem(
label = SharedRes.strings.home,
icon = Icons.Default.Home
),
InitialComponent.PagerItem(
label = SharedRes.strings.settings,
icon = Icons.Default.Settings
)
)

Expand All @@ -39,7 +45,8 @@ class InitialScreenComponent(
initialPages = {
Pages(
items = listOf(
View.Home
View.Home,
View.Settings
),
selectedIndex = 0
)
Expand Down Expand Up @@ -67,6 +74,10 @@ class InitialScreenComponent(
di = di,
onMediumDetails = onMediumDetails
)
is View.Settings -> SettingsScreenComponent(
componentContext = componentContext,
di = di
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ import kotlinx.serialization.Serializable
sealed class View {
@Serializable
data object Home : View()

@Serializable
data object Settings : View()
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ private fun SuccessContent(
items(data, key = { it.episode to it.media?.id }) { media ->
AiringCard(
airing = media,
modifier = Modifier.height(150.dp).fillParentMaxWidth(fraction = 0.9F),
modifier = Modifier
.height(150.dp)
.fillParentMaxWidth(fraction = 0.9F)
.animateItemPlacement(),
onClick = onClick
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.datlag.aniflow.ui.navigation.screen.initial.home.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -61,6 +62,7 @@ private fun Loading() {
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun SuccessContent(
data: List<SeasonQuery.Medium>,
Expand Down Expand Up @@ -89,7 +91,10 @@ private fun SuccessContent(
itemsIndexed(data, key = { _, it -> it.id }) { _, medium ->
MediumCard(
medium = Medium(medium),
modifier = Modifier.width(200.dp).height(280.dp),
modifier = Modifier
.width(200.dp)
.height(280.dp)
.animateItemPlacement(),
onClick = onClick
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.datlag.aniflow.ui.navigation.screen.initial.home.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -57,6 +58,7 @@ private fun Loading() {
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun SuccessContent(
data: List<TrendingQuery.Medium>,
Expand All @@ -76,7 +78,10 @@ private fun SuccessContent(
itemsIndexed(data, key = { _, it -> it.id }) { _, medium ->
MediumCard(
medium = Medium(medium),
modifier = Modifier.width(200.dp).height(280.dp),
modifier = Modifier
.width(200.dp)
.height(280.dp)
.animateItemPlacement(),
onClick = onClick
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.datlag.aniflow.ui.navigation.screen.initial.settings

import dev.datlag.aniflow.ui.navigation.Component
import kotlinx.coroutines.flow.Flow

interface SettingsComponent : Component {
val adultContent: Flow<Boolean>

fun changeAdultContent(value: Boolean)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package dev.datlag.aniflow.ui.navigation.screen.initial.settings

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.NoAdultContent
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import dev.chrisbanes.haze.haze
import dev.datlag.aniflow.LocalHaze
import dev.datlag.aniflow.LocalPaddingValues
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.common.plus
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.stringResource

@Composable
fun SettingsScreen(component: SettingsComponent) {
val padding = PaddingValues(16.dp)
val listState = rememberLazyListState(
initialFirstVisibleItemIndex = StateSaver.List.settingsOverview,
initialFirstVisibleItemScrollOffset = StateSaver.List.settingsOverviewOffset
)

LazyColumn(
state = listState,
modifier = Modifier.fillMaxWidth().haze(state = LocalHaze.current),
contentPadding = LocalPaddingValues.current?.plus(padding) ?: padding,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
Text(
text = "Settings",
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
}
item {
val adultContent by component.adultContent.collectAsStateWithLifecycle(false)

Row(
modifier = Modifier.fillParentMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
imageVector = Icons.Default.NoAdultContent,
contentDescription = null,
)
Text(
text = stringResource(SharedRes.strings.adult_content_setting),
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.weight(1F))
Switch(
checked = adultContent,
onCheckedChange = component::changeAdultContent,
thumbContent = {
if (adultContent) {
Icon(
modifier = Modifier.size(SwitchDefaults.IconSize),
imageVector = Icons.Default.Check,
contentDescription = null
)
}
}
)
}
}
}

DisposableEffect(listState) {
onDispose {
StateSaver.List.settingsOverview = listState.firstVisibleItemIndex
StateSaver.List.settingsOverviewOffset = listState.firstVisibleItemScrollOffset
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.datlag.aniflow.ui.navigation.screen.initial.settings

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import dev.datlag.aniflow.common.onRender
import dev.datlag.aniflow.settings.Settings
import dev.datlag.tooling.compose.ioDispatcher
import dev.datlag.tooling.decompose.ioScope
import kotlinx.coroutines.flow.*
import org.kodein.di.DI
import org.kodein.di.instance

class SettingsScreenComponent(
componentContext: ComponentContext,
override val di: DI
) : SettingsComponent, ComponentContext by componentContext {

private val appSettings by di.instance<Settings.PlatformAppSettings>()
override val adultContent: Flow<Boolean> = appSettings.adultContent.flowOn(ioDispatcher())

@Composable
override fun render() {
onRender {
SettingsScreen(this)
}
}

override fun changeAdultContent(value: Boolean) {
launchIO {
appSettings.setAdultContent(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import dev.datlag.aniflow.anilist.type.MediaStatus
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.ContentHolderComponent
import dev.datlag.aniflow.ui.navigation.DialogComponent
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow

interface MediumComponent : ContentHolderComponent {
val initialMedium: Medium

val mediumState: StateFlow<MediumStateMachine.State>
val isAdult: StateFlow<Boolean>
val isAdultAllowed: Flow<Boolean>

val bannerImage: StateFlow<String?>
val coverImage: StateFlow<Medium.CoverImage>
val title: StateFlow<Medium.Title>
Expand Down
Loading

0 comments on commit 241f1b7

Please sign in to comment.