-
-
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
24 changed files
with
482 additions
and
153 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
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
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
10 changes: 10 additions & 0 deletions
10
...Main/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/settings/SettingsComponent.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,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) | ||
} |
88 changes: 88 additions & 0 deletions
88
...monMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/settings/SettingsScreen.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,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 | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...otlin/dev/datlag/aniflow/ui/navigation/screen/initial/settings/SettingsScreenComponent.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,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) | ||
} | ||
} | ||
} |
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.