Skip to content

Commit

Permalink
move settings to bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 10, 2024
1 parent dd8a366 commit 679bf7e
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dev.datlag.aniflow.other.UserHelper
import dev.datlag.aniflow.ui.navigation.screen.favorites.FavoritesScreenComponent
import dev.datlag.aniflow.ui.navigation.screen.home.HomeScreenComponent
import dev.datlag.aniflow.ui.navigation.screen.medium.MediumScreenComponent
import dev.datlag.aniflow.ui.navigation.screen.settings.SettingsScreenComponent
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.SettingsDialogComponent
import dev.datlag.aniflow.ui.navigation.screen.nekos.NekosScreenComponent
import org.kodein.di.DI
import org.kodein.di.instance
Expand Down Expand Up @@ -43,14 +43,14 @@ class RootComponent(
onMediumDetails = {
navigation.push(RootConfig.Details(it))
},
onProfile = {
navigation.push(RootConfig.Settings)
},
onDiscover = {
// navigation.replaceCurrent(RootConfig.Wallpaper)
},
onFavorites = {
navigation.replaceCurrent(RootConfig.Favorites)
},
onNekos = {
navigation.bringToFront(RootConfig.Nekos)
}
)
is RootConfig.Details -> MediumScreenComponent(
Expand All @@ -59,13 +59,6 @@ class RootComponent(
initialMedium = rootConfig.medium,
onBack = navigation::pop
)
is RootConfig.Settings -> SettingsScreenComponent(
componentContext = componentContext,
di = di,
onNekos = {
navigation.bringToFront(RootConfig.Nekos)
}
)
is RootConfig.Favorites -> FavoritesScreenComponent(
componentContext = componentContext,
di = di,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ sealed class RootConfig {
constructor(id: Int) : this(Medium(id))
}

@Serializable
data object Settings : RootConfig()

@Serializable
data object Favorites : RootConfig()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.datlag.aniflow.ui.navigation.screen.home

import kotlinx.serialization.Serializable

@Serializable
sealed class DialogConfig {

@Serializable
data object Settings : DialogConfig()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.datlag.aniflow.ui.navigation.screen.home

import com.arkivanov.decompose.router.slot.ChildSlot
import com.arkivanov.decompose.value.Value
import dev.datlag.aniflow.anilist.AiringTodayRepository
import dev.datlag.aniflow.anilist.TrendingRepository
import dev.datlag.aniflow.anilist.model.Medium
Expand All @@ -8,6 +10,7 @@ import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.anilist.type.MediaType
import dev.datlag.aniflow.trace.TraceRepository
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.DialogComponent
import kotlinx.coroutines.flow.Flow

interface HomeComponent : Component {
Expand All @@ -21,6 +24,8 @@ interface HomeComponent : Component {

val traceState: Flow<TraceRepository.State>

val dialog: Value<ChildSlot<DialogConfig, DialogComponent>>

fun viewProfile()
fun viewAnime()
fun viewManga()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.option.OptionDialog
Expand Down Expand Up @@ -60,6 +61,10 @@ fun HomeScreen(component: HomeComponent) {
it?.let(component::trace)
}

val dialogState by component.dialog.subscribeAsState()

dialogState.child?.instance?.render()

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.slot.*
import com.arkivanov.decompose.value.Value
import dev.chrisbanes.haze.HazeState
import dev.datlag.aniflow.LocalHaze
import dev.datlag.aniflow.anilist.AiringTodayRepository
Expand All @@ -20,6 +22,8 @@ import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.other.UserHelper
import dev.datlag.aniflow.settings.Settings
import dev.datlag.aniflow.trace.TraceRepository
import dev.datlag.aniflow.ui.navigation.DialogComponent
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.SettingsDialogComponent
import dev.datlag.tooling.decompose.ioScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
Expand All @@ -32,9 +36,9 @@ class HomeScreenComponent(
componentContext: ComponentContext,
override val di: DI,
private val onMediumDetails: (Medium) -> Unit,
private val onProfile: () -> Unit,
private val onDiscover: () -> Unit,
private val onFavorites: () -> Unit
private val onFavorites: () -> Unit,
private val onNekos: () -> Unit
) : HomeComponent, ComponentContext by componentContext {

private val appSettings by instance<Settings.PlatformAppSettings>()
Expand Down Expand Up @@ -90,6 +94,21 @@ class HomeScreenComponent(
private val traceRepository by instance<TraceRepository>()
override val traceState: Flow<TraceRepository.State> = traceRepository.response

private val dialogNavigation = SlotNavigation<DialogConfig>()
override val dialog: Value<ChildSlot<DialogConfig, DialogComponent>> = childSlot(
source = dialogNavigation,
serializer = DialogConfig.serializer()
) { config, context ->
when (config) {
is DialogConfig.Settings -> SettingsDialogComponent(
componentContext = context,
di = di,
onNekos = onNekos,
onDismiss = dialogNavigation::dismiss
)
}
}

init {
traceRepository.clear()
}
Expand All @@ -108,7 +127,7 @@ class HomeScreenComponent(
}

override fun viewProfile() {
onProfile()
dialogNavigation.activate(DialogConfig.Settings)
}

override fun viewAnime() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.datlag.aniflow.ui.navigation.screen.settings
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings

import dev.datlag.aniflow.anilist.model.User
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.DialogComponent
import kotlinx.coroutines.flow.Flow
import dev.datlag.aniflow.settings.model.Color as SettingsColor
import dev.datlag.aniflow.settings.model.TitleLanguage as SettingsTitle
import dev.datlag.aniflow.settings.model.CharLanguage as SettingsChar

interface SettingsComponent : Component {
interface SettingsComponent : DialogComponent {
val user: Flow<User?>
val isLoggedIn: Flow<Boolean>
val loginUri: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
package dev.datlag.aniflow.ui.navigation.screen.settings
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material.icons.rounded.Code
import androidx.compose.material3.*
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalUriHandler
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.LocalEdgeToEdge
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.common.isFullyExpandedOrTargeted
import dev.datlag.aniflow.common.merge
import dev.datlag.aniflow.common.plus
import dev.datlag.aniflow.other.Constants
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.ui.navigation.screen.settings.component.*
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component.*
import dev.datlag.tooling.compose.onClick
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsScreen(component: SettingsComponent) {
Scaffold {
val padding = it.merge(PaddingValues(16.dp))
val sheetState = rememberModalBottomSheetState()
val (insets, bottomPadding) = if (LocalEdgeToEdge.current) {
WindowInsets(
left = 0,
top = 0,
right = 0,
bottom = 0
) to BottomSheetDefaults.windowInsets.only(WindowInsetsSides.Bottom).asPaddingValues()
} else {
BottomSheetDefaults.windowInsets to PaddingValues()
}

ModalBottomSheet(
onDismissRequest = component::dismiss,
windowInsets = insets,
sheetState = sheetState
) {
val listState = rememberLazyListState(
initialFirstVisibleItemIndex = StateSaver.List.settingsOverview,
initialFirstVisibleItemScrollOffset = StateSaver.List.settingsOverviewOffset
Expand All @@ -43,14 +60,16 @@ fun SettingsScreen(component: SettingsComponent) {
LazyColumn(
state = listState,
modifier = Modifier.fillMaxWidth(),
contentPadding = padding,
contentPadding = bottomPadding.merge(PaddingValues(16.dp)),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
UserSection(
userFlow = component.user,
loginUri = component.loginUri,
modifier = Modifier.fillParentMaxWidth()
dismissVisible = sheetState.isFullyExpandedOrTargeted(forceFullExpand = true),
modifier = Modifier.fillParentMaxWidth(),
onDismiss = component::dismiss
)
}
item {
Expand Down Expand Up @@ -159,7 +178,7 @@ fun SettingsScreen(component: SettingsComponent) {
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
imageVector = Icons.Default.Code,
imageVector = Icons.Rounded.Code,
contentDescription = null,
)
Text(text = "Developed by DatLag")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
Expand All @@ -7,18 +7,18 @@ import dev.datlag.aniflow.common.onRender
import dev.datlag.aniflow.other.UserHelper
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
import dev.datlag.aniflow.settings.model.Color as SettingsColor
import dev.datlag.aniflow.settings.model.TitleLanguage as SettingsTitle
import dev.datlag.aniflow.settings.model.CharLanguage as SettingsChar

class SettingsScreenComponent(
class SettingsDialogComponent(
componentContext: ComponentContext,
override val di: DI,
private val onNekos: () -> Unit
private val onNekos: () -> Unit,
private val onDismiss: () -> Unit
) : SettingsComponent, ComponentContext by componentContext {

private val appSettings by di.instance<Settings.PlatformAppSettings>()
Expand Down Expand Up @@ -73,4 +73,8 @@ class SettingsScreenComponent(
override fun nekos() {
onNekos()
}

override fun dismiss() {
onDismiss()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.datlag.aniflow.ui.navigation.screen.settings.component
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
Expand Down
Loading

0 comments on commit 679bf7e

Please sign in to comment.