From 8d06debe3a9b9e1441858579378f721bab63499c Mon Sep 17 00:00:00 2001 From: DatLag Date: Thu, 9 May 2024 15:35:31 +0200 Subject: [PATCH] refactor nekos location --- .../datlag/aniflow/common/ExtendCompose.kt | 25 ++++---- .../aniflow/ui/navigation/RootComponent.kt | 33 ++++------- .../aniflow/ui/navigation/RootConfig.kt | 2 +- .../screen/component/HidingNavigationBar.kt | 41 +++++-------- .../screen/favorites/FavoritesComponent.kt | 2 +- .../screen/favorites/FavoritesScreen.kt | 2 +- .../favorites/FavoritesScreenComponent.kt | 6 +- .../navigation/screen/home/HomeComponent.kt | 2 +- .../ui/navigation/screen/home/HomeScreen.kt | 2 +- .../screen/home/HomeScreenComponent.kt | 6 +- .../NekosComponent.kt} | 8 +-- .../NekosScreen.kt} | 59 +++++++++++++++---- .../NekosScreenComponent.kt} | 19 +++--- .../screen/settings/SettingsComponent.kt | 1 + .../screen/settings/SettingsScreen.kt | 36 +++++++++++ .../settings/SettingsScreenComponent.kt | 7 ++- .../moko-resources/base/strings.xml | 1 + .../kotlin/dev/datlag/aniflow/nekos/Nekos.kt | 2 +- 18 files changed, 153 insertions(+), 101 deletions(-) rename composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/{wallpaper/WallpaperComponent.kt => nekos/NekosComponent.kt} (71%) rename composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/{wallpaper/WallpaperScreen.kt => nekos/NekosScreen.kt} (74%) rename composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/{wallpaper/WallpaperScreenComponent.kt => nekos/NekosScreenComponent.kt} (77%) diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/common/ExtendCompose.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/common/ExtendCompose.kt index 35ecb95..f22469a 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/common/ExtendCompose.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/common/ExtendCompose.kt @@ -64,16 +64,19 @@ fun PaddingValues.merge(other: PaddingValues): PaddingValues { ) } -fun Modifier.localPadding(additional: PaddingValues = PaddingValues(0.dp)) = composed { - this.padding(LocalPaddingValues.current?.plus(additional) ?: additional) +@Composable +fun Modifier.localPadding(additional: PaddingValues = PaddingValues(0.dp)): Modifier { + return this.padding(LocalPaddingValues.current?.plus(additional) ?: additional) } -fun Modifier.localPadding(all: Dp) = composed { - this.localPadding(PaddingValues(all)) +@Composable +fun Modifier.localPadding(all: Dp): Modifier { + return this.localPadding(PaddingValues(all)) } -fun Modifier.localPadding(horizontal: Dp, vertical: Dp = 0.dp) = composed { - this.localPadding(PaddingValues(horizontal = horizontal, vertical = vertical)) +@Composable +fun Modifier.localPadding(horizontal: Dp, vertical: Dp = 0.dp): Modifier { + return this.localPadding(PaddingValues(horizontal = horizontal, vertical = vertical)) } @Composable @@ -100,12 +103,14 @@ fun LocalPadding(top: Dp = 0.dp, start: Dp = 0.dp, bottom: Dp = 0.dp, end: Dp = ) ?: PaddingValues(top = top, start = start, bottom = bottom, end = end) } -fun Modifier.mergedLocalPadding(other: PaddingValues, additional: PaddingValues = PaddingValues(0.dp)) = composed { - this.padding((LocalPaddingValues.current?.merge(other) ?: other).plus(additional)) +@Composable +fun Modifier.mergedLocalPadding(other: PaddingValues, additional: PaddingValues = PaddingValues(0.dp)): Modifier { + return this.padding((LocalPaddingValues.current?.merge(other) ?: other).plus(additional)) } -fun Modifier.mergedLocalPadding(other: PaddingValues, additional: Dp) = composed { - this.mergedLocalPadding(other, PaddingValues(additional)) +@Composable +fun Modifier.mergedLocalPadding(other: PaddingValues, additional: Dp): Modifier { + return this.mergedLocalPadding(other, PaddingValues(additional)) } @Composable diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt index e3f5566..157b761 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt @@ -1,29 +1,20 @@ package dev.datlag.aniflow.ui.navigation -import androidx.compose.animation.core.tween -import androidx.compose.foundation.gestures.Orientation import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.layout import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.ExperimentalDecomposeApi import com.arkivanov.decompose.extensions.compose.stack.Children import com.arkivanov.decompose.extensions.compose.stack.animation.fade import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.predictiveBackAnimation -import com.arkivanov.decompose.extensions.compose.stack.animation.slide import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation -import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimator import com.arkivanov.decompose.router.stack.* import dev.datlag.aniflow.common.onRender -import dev.datlag.aniflow.model.ifValueOrNull 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.SettingsScreen import dev.datlag.aniflow.ui.navigation.screen.settings.SettingsScreenComponent -import dev.datlag.aniflow.ui.navigation.screen.wallpaper.WallpaperScreenComponent -import io.github.aakira.napier.Napier +import dev.datlag.aniflow.ui.navigation.screen.nekos.NekosScreenComponent import org.kodein.di.DI import org.kodein.di.instance @@ -55,8 +46,8 @@ class RootComponent( onProfile = { navigation.push(RootConfig.Settings) }, - onWallpaper = { - navigation.replaceCurrent(RootConfig.Wallpaper) + onDiscover = { + // navigation.replaceCurrent(RootConfig.Wallpaper) }, onFavorites = { navigation.replaceCurrent(RootConfig.Favorites) @@ -70,27 +61,25 @@ class RootComponent( ) is RootConfig.Settings -> SettingsScreenComponent( componentContext = componentContext, - di = di + di = di, + onNekos = { + navigation.bringToFront(RootConfig.Nekos) + } ) is RootConfig.Favorites -> FavoritesScreenComponent( componentContext = componentContext, di = di, - onWallpaper = { - navigation.replaceCurrent(RootConfig.Wallpaper) + onDiscover = { + // navigation.replaceCurrent(RootConfig.Wallpaper) }, onHome = { navigation.replaceCurrent(RootConfig.Home) } ) - is RootConfig.Wallpaper -> WallpaperScreenComponent( + is RootConfig.Nekos -> NekosScreenComponent( componentContext = componentContext, di = di, - onHome = { - navigation.replaceCurrent(RootConfig.Home) - }, - onFavorites = { - navigation.replaceCurrent(RootConfig.Favorites) - } + onBack = navigation::pop ) } } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt index 38a9df0..6ab07c1 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt @@ -21,5 +21,5 @@ sealed class RootConfig { data object Favorites : RootConfig() @Serializable - data object Wallpaper : RootConfig() + data object Nekos : RootConfig() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/component/HidingNavigationBar.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/component/HidingNavigationBar.kt index 7d0b9b6..65d92fd 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/component/HidingNavigationBar.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/component/HidingNavigationBar.kt @@ -40,7 +40,7 @@ import kotlinx.serialization.Transient fun HidingNavigationBar( visible: Boolean, selected: NavigationBarState, - onWallpaper: () -> Unit, + onDiscover: () -> Unit, onHome: () -> Unit, onFavorites: () -> Unit ) { @@ -73,8 +73,8 @@ fun HidingNavigationBar( containerColor = Color.Transparent, contentColor = MaterialTheme.colorScheme.contentColorFor(NavigationBarDefaults.containerColor) ) { - val isWallpaper = remember(selected) { - selected is NavigationBarState.Wallpaper + val isDiscover = remember(selected) { + selected is NavigationBarState.Discover } val isHome = remember(selected) { selected is NavigationBarState.Home @@ -85,27 +85,19 @@ fun HidingNavigationBar( NavigationBarItem( onClick = { - if (!isWallpaper) { - onWallpaper() + if (!isDiscover) { + onDiscover() } }, - selected = isWallpaper, + selected = isDiscover, icon = { - Image( - modifier = Modifier.size(24.dp), - painter = painterResource( - if (isWallpaper) { - SharedRes.images.cat_filled - } else { - SharedRes.images.cat_rounded - } - ), - contentDescription = null, - colorFilter = ColorFilter.tint(LocalContentColor.current) + Icon( + imageVector = selected.discoverIcon, + contentDescription = null ) }, label = { - Text(text = "Nekos") + Text(text = "Discover") } ) NavigationBarItem( @@ -155,10 +147,10 @@ sealed interface NavigationBarState { val selectedIcon: ImageVector get() = unselectedIcon - val wallpaperIcon: ImageVector + val discoverIcon: ImageVector get() = when (this) { - is Wallpaper -> selectedIcon - else -> Wallpaper.unselectedIcon + is Discover -> selectedIcon + else -> Discover.unselectedIcon } val homeIcon: ImageVector @@ -174,12 +166,9 @@ sealed interface NavigationBarState { } @Serializable - data object Wallpaper : NavigationBarState { + data object Discover : NavigationBarState { override val unselectedIcon: ImageVector - get() = Icons.Rounded.Wallpaper - - override val selectedIcon: ImageVector - get() = Icons.Rounded.Image + get() = Icons.Rounded.Search } @Serializable diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesComponent.kt index 82f11f0..b577263 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesComponent.kt @@ -4,6 +4,6 @@ import dev.datlag.aniflow.ui.navigation.Component interface FavoritesComponent : Component { - fun viewWallpaper() + fun viewDiscover() fun viewHome() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreen.kt index 302de11..d4831e9 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreen.kt @@ -12,7 +12,7 @@ fun FavoritesScreen(component: FavoritesComponent) { HidingNavigationBar( visible = true, selected = NavigationBarState.Favorite, - onWallpaper = component::viewWallpaper, + onDiscover = component::viewDiscover, onHome = component::viewHome, onFavorites = { } ) diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreenComponent.kt index 253b917..72cde08 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreenComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/favorites/FavoritesScreenComponent.kt @@ -12,7 +12,7 @@ import org.kodein.di.DI class FavoritesScreenComponent( componentContext: ComponentContext, override val di: DI, - private val onWallpaper: () -> Unit, + private val onDiscover: () -> Unit, private val onHome: () -> Unit, ) : FavoritesComponent, ComponentContext by componentContext { @@ -29,8 +29,8 @@ class FavoritesScreenComponent( } } - override fun viewWallpaper() { - onWallpaper() + override fun viewDiscover() { + onDiscover() } override fun viewHome() { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeComponent.kt index 0069afc..b51b1b7 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeComponent.kt @@ -22,7 +22,7 @@ interface HomeComponent : Component { fun viewProfile() fun viewAnime() fun viewManga() - fun viewWallpaper() + fun viewDiscover() fun viewFavorites() fun details(medium: Medium) diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt index b504b1c..4f9841d 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreen.kt @@ -137,7 +137,7 @@ fun HomeScreen(component: HomeComponent) { HidingNavigationBar( visible = listState.isScrollingUp() && listState.canScrollForward, selected = NavigationBarState.Home, - onWallpaper = component::viewWallpaper, + onDiscover = component::viewDiscover, onHome = { }, onFavorites = component::viewFavorites ) diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreenComponent.kt index 74886e3..151c9f4 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreenComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/home/HomeScreenComponent.kt @@ -31,7 +31,7 @@ class HomeScreenComponent( override val di: DI, private val onMediumDetails: (Medium) -> Unit, private val onProfile: () -> Unit, - private val onWallpaper: () -> Unit, + private val onDiscover: () -> Unit, private val onFavorites: () -> Unit ) : HomeComponent, ComponentContext by componentContext { @@ -124,8 +124,8 @@ class HomeScreenComponent( } } - override fun viewWallpaper() { - onWallpaper() + override fun viewDiscover() { + onDiscover() } override fun viewFavorites() { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosComponent.kt similarity index 71% rename from composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperComponent.kt rename to composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosComponent.kt index 13520bc..5e4b149 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosComponent.kt @@ -1,4 +1,4 @@ -package dev.datlag.aniflow.ui.navigation.screen.wallpaper +package dev.datlag.aniflow.ui.navigation.screen.nekos import dev.datlag.aniflow.nekos.NekosRepository import dev.datlag.aniflow.nekos.model.Rating @@ -6,15 +6,13 @@ import dev.datlag.aniflow.ui.navigation.Component import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow -interface WallpaperComponent : Component { +interface NekosComponent : Component { val adultContent: Flow val rating: StateFlow val state: Flow - fun viewHome() - fun viewFavorites() - + fun back() fun filter(rating: Rating) } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreen.kt similarity index 74% rename from composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreen.kt rename to composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreen.kt index 6ee9150..db33622 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreen.kt @@ -1,20 +1,25 @@ -package dev.datlag.aniflow.ui.navigation.screen.wallpaper +package dev.datlag.aniflow.ui.navigation.screen.nekos import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells import androidx.compose.foundation.lazy.staggeredgrid.items import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.rounded.ArrowBackIos +import androidx.compose.material.icons.rounded.ArrowBackIos import androidx.compose.material.icons.rounded.FilterList import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp import coil3.compose.AsyncImage import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState @@ -24,7 +29,11 @@ import com.maxkeppeler.sheets.option.models.Option import com.maxkeppeler.sheets.option.models.OptionConfig import com.maxkeppeler.sheets.option.models.OptionSelection import dev.chrisbanes.haze.haze +import dev.chrisbanes.haze.hazeChild +import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi +import dev.chrisbanes.haze.materials.HazeMaterials import dev.datlag.aniflow.LocalHaze +import dev.datlag.aniflow.SharedRes import dev.datlag.aniflow.common.isScrollingUp import dev.datlag.aniflow.common.merge import dev.datlag.aniflow.nekos.NekosRepository @@ -32,14 +41,44 @@ import dev.datlag.aniflow.nekos.model.Rating import dev.datlag.aniflow.ui.navigation.screen.component.HidingNavigationBar import dev.datlag.aniflow.ui.navigation.screen.component.NavigationBarState import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle +import dev.icerock.moko.resources.compose.stringResource import io.github.aakira.napier.Napier -@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) +@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class) @Composable -fun WallpaperScreen(component: WallpaperComponent) { +fun NekosScreen(component: NekosComponent) { val listState = rememberLazyStaggeredGridState() Scaffold( + topBar = { + TopAppBar( + navigationIcon = { + IconButton( + onClick = { + component.back() + } + ) { + Icon( + imageVector = Icons.AutoMirrored.Rounded.ArrowBackIos, + contentDescription = null + ) + } + }, + title = { + Text(text = stringResource(SharedRes.strings.nekos_api)) + }, + colors = TopAppBarDefaults.largeTopAppBarColors( + containerColor = Color.Transparent, + scrolledContainerColor = Color.Transparent, + ), + modifier = Modifier.hazeChild( + state = LocalHaze.current, + style = HazeMaterials.thin( + containerColor = MaterialTheme.colorScheme.surface, + ) + ).fillMaxWidth() + ) + }, floatingActionButton = { val dialogState = rememberUseCaseState( visible = false @@ -98,15 +137,6 @@ fun WallpaperScreen(component: WallpaperComponent) { Text(text = "Filter") } ) - }, - bottomBar = { - HidingNavigationBar( - visible = listState.isScrollingUp(), - selected = NavigationBarState.Wallpaper, - onWallpaper = { }, - onHome = component::viewHome, - onFavorites = component::viewFavorites - ) } ) { padding -> val state by component.state.collectAsStateWithLifecycle(NekosRepository.State.None) @@ -115,6 +145,8 @@ fun WallpaperScreen(component: WallpaperComponent) { is NekosRepository.State.None -> Text(text = "Loading") is NekosRepository.State.Error -> Text(text = "Error") is NekosRepository.State.Success -> { + val uriHandler = LocalUriHandler.current + LazyVerticalStaggeredGrid( state = listState, modifier = Modifier.haze(state = LocalHaze.current), @@ -128,7 +160,8 @@ fun WallpaperScreen(component: WallpaperComponent) { modifier = Modifier.animateItemPlacement(), onClick = { Napier.e(it.toString()) - } + uriHandler.openUri(it.imageUrl ?: it.sampleUrl ?: "") + }, ) { AsyncImage( modifier = Modifier.fillMaxSize(), diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreenComponent.kt similarity index 77% rename from composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreenComponent.kt rename to composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreenComponent.kt index e8a5088..dce20df 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreenComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/nekos/NekosScreenComponent.kt @@ -1,4 +1,4 @@ -package dev.datlag.aniflow.ui.navigation.screen.wallpaper +package dev.datlag.aniflow.ui.navigation.screen.nekos import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider @@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.StateFlow import org.kodein.di.DI import org.kodein.di.instance -class WallpaperScreenComponent( +class NekosScreenComponent( componentContext: ComponentContext, override val di: DI, - private val onHome: () -> Unit, - private val onFavorites: () -> Unit, -) : WallpaperComponent, ComponentContext by componentContext { + private val onBack: () -> Unit, +) : NekosComponent, ComponentContext by componentContext { private val appSettings by instance() override val adultContent: Flow = appSettings.adultContent @@ -37,17 +36,13 @@ class WallpaperScreenComponent( LocalHaze provides haze ) { onRender { - WallpaperScreen(this) + NekosScreen(this) } } } - override fun viewHome() { - onHome() - } - - override fun viewFavorites() { - onFavorites() + override fun back() { + onBack() } override fun filter(rating: Rating) { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsComponent.kt index 7973392..d0a93e7 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsComponent.kt @@ -22,4 +22,5 @@ interface SettingsComponent : Component { fun changeTitleLanguage(value: SettingsTitle?) fun changeCharLanguage(value: SettingsChar?) fun logout() + fun nekos() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreen.kt index 6c844ec..b028fd8 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreen.kt @@ -1,5 +1,6 @@ package dev.datlag.aniflow.ui.navigation.screen.settings +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn @@ -28,6 +29,7 @@ import dev.datlag.aniflow.ui.navigation.screen.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 @Composable fun SettingsScreen(component: SettingsComponent) { @@ -163,6 +165,40 @@ fun SettingsScreen(component: SettingsComponent) { Text(text = "Developed by DatLag") } } + item { + var clicked by remember { mutableStateOf(0) } + + Row( + modifier = Modifier + .fillParentMaxWidth() + .defaultMinSize(minHeight = ButtonDefaults.MinHeight) + .clip(MaterialTheme.shapes.medium) + .onClick { + if (clicked >= 99) { + component.nekos() + } else { + clicked++ + } + }, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + Image( + modifier = Modifier.size(24.dp), + painter = painterResource(SharedRes.images.cat_filled), + contentDescription = null, + colorFilter = ColorFilter.tint(LocalContentColor.current) + ) + Text(text = stringResource(SharedRes.strings.nekos_api)) + AnimatedVisibility( + visible = clicked >= 1, + ) { + Badge { + Text(text = "$clicked") + } + } + } + } } DisposableEffect(listState) { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreenComponent.kt index b8a474b..748f01e 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreenComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/settings/SettingsScreenComponent.kt @@ -17,7 +17,8 @@ import dev.datlag.aniflow.settings.model.CharLanguage as SettingsChar class SettingsScreenComponent( componentContext: ComponentContext, - override val di: DI + override val di: DI, + private val onNekos: () -> Unit ) : SettingsComponent, ComponentContext by componentContext { private val appSettings by di.instance() @@ -68,4 +69,8 @@ class SettingsScreenComponent( userHelper.logout() } } + + override fun nekos() { + onNekos() + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/moko-resources/base/strings.xml b/composeApp/src/commonMain/moko-resources/base/strings.xml index 396f293..a94486b 100644 --- a/composeApp/src/commonMain/moko-resources/base/strings.xml +++ b/composeApp/src/commonMain/moko-resources/base/strings.xml @@ -57,4 +57,5 @@ Explicit Profile Favorites + Nekos API diff --git a/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/Nekos.kt b/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/Nekos.kt index f9df2ce..376fac5 100644 --- a/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/Nekos.kt +++ b/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/Nekos.kt @@ -6,7 +6,7 @@ import dev.datlag.aniflow.nekos.model.ImagesResponse interface Nekos { - @GET("images") + @GET("images/random") suspend fun images( @Query("rating") rating: String, @Query("offset") offset: Int? = null,