Skip to content

Commit

Permalink
refactor nekos location
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 9, 2024
1 parent 154c098 commit 8d06deb
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ sealed class RootConfig {
data object Favorites : RootConfig()

@Serializable
data object Wallpaper : RootConfig()
data object Nekos : RootConfig()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import kotlinx.serialization.Transient
fun HidingNavigationBar(
visible: Boolean,
selected: NavigationBarState,
onWallpaper: () -> Unit,
onDiscover: () -> Unit,
onHome: () -> Unit,
onFavorites: () -> Unit
) {
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import dev.datlag.aniflow.ui.navigation.Component

interface FavoritesComponent : Component {

fun viewWallpaper()
fun viewDiscover()
fun viewHome()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun FavoritesScreen(component: FavoritesComponent) {
HidingNavigationBar(
visible = true,
selected = NavigationBarState.Favorite,
onWallpaper = component::viewWallpaper,
onDiscover = component::viewDiscover,
onHome = component::viewHome,
onFavorites = { }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -29,8 +29,8 @@ class FavoritesScreenComponent(
}
}

override fun viewWallpaper() {
onWallpaper()
override fun viewDiscover() {
onDiscover()
}

override fun viewHome() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface HomeComponent : Component {
fun viewProfile()
fun viewAnime()
fun viewManga()
fun viewWallpaper()
fun viewDiscover()
fun viewFavorites()

fun details(medium: Medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -124,8 +124,8 @@ class HomeScreenComponent(
}
}

override fun viewWallpaper() {
onWallpaper()
override fun viewDiscover() {
onDiscover()
}

override fun viewFavorites() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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
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<Boolean>
val rating: StateFlow<Rating>

val state: Flow<NekosRepository.State>

fun viewHome()
fun viewFavorites()

fun back()
fun filter(rating: Rating)
}
Loading

0 comments on commit 8d06deb

Please sign in to comment.