Skip to content

Commit

Permalink
prepare wallpaper screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 7, 2024
1 parent 075c60a commit 6a72fa1
Show file tree
Hide file tree
Showing 26 changed files with 486 additions and 814 deletions.
9 changes: 9 additions & 0 deletions composeApp/src/androidMain/kotlin/dev/datlag/aniflow/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.datlag.aniflow

import android.content.Context
import android.os.StrictMode
import androidx.multidex.MultiDexApplication
import coil3.ImageLoader
import coil3.SingletonImageLoader
Expand All @@ -27,6 +28,14 @@ class App : MultiDexApplication(), DIAware {
super.onCreate()

if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.permitDiskReads()
.penaltyLog()
.penaltyDialog()
.build()
)
Napier.base(DebugAntilog())
}
StateSaver.sekretLibraryLoaded = NativeLoader.loadLibrary("sekret")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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
Expand All @@ -16,11 +17,12 @@ 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.initial.InitialScreenComponent
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 org.kodein.di.DI
import org.kodein.di.instance
Expand Down Expand Up @@ -52,6 +54,12 @@ class RootComponent(
},
onProfile = {
navigation.push(RootConfig.Settings)
},
onWallpaper = {
navigation.replaceCurrent(RootConfig.Wallpaper)
},
onFavorites = {
navigation.replaceCurrent(RootConfig.Favorites)
}
)
is RootConfig.Details -> MediumScreenComponent(
Expand All @@ -64,6 +72,26 @@ class RootComponent(
componentContext = componentContext,
di = di
)
is RootConfig.Favorites -> FavoritesScreenComponent(
componentContext = componentContext,
di = di,
onWallpaper = {
navigation.replaceCurrent(RootConfig.Wallpaper)
},
onHome = {
navigation.replaceCurrent(RootConfig.Home)
}
)
is RootConfig.Wallpaper -> WallpaperScreenComponent(
componentContext = componentContext,
di = di,
onHome = {
navigation.replaceCurrent(RootConfig.Home)
},
onFavorites = {
navigation.replaceCurrent(RootConfig.Favorites)
}
)
}
}

Expand All @@ -75,40 +103,7 @@ class RootComponent(
stack = stack,
animation = predictiveBackAnimation(
backHandler = this.backHandler,
fallbackAnimation = stackAnimation { child ->
when (child.configuration) {
is RootConfig.Settings -> stackAnimator(tween()) { factor, _, content ->
content(
Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)

layout(placeable.width, placeable.height) {
placeable.placeRelative(y = -(placeable.height.toFloat() * factor).toInt(), x = 0)
}
}
)
}
is RootConfig.Home -> {
val current = stack.value.active

when (current.configuration) {
is RootConfig.Settings -> stackAnimator(tween()) { factor, _, content ->
content(
Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)

layout(placeable.width, placeable.height) {
placeable.placeRelative(y = -(placeable.height.toFloat() * factor).toInt(), x = 0)
}
}
)
}
else -> slide()
}
}
else -> slide()
}
},
fallbackAnimation = stackAnimation(fade()),
onBack = {
navigation.pop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ sealed class RootConfig {

@Serializable
data object Settings : RootConfig()

@Serializable
data object Favorites : RootConfig()

@Serializable
data object Wallpaper : RootConfig()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Wallpaper
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.rounded.Favorite
import androidx.compose.material.icons.rounded.FavoriteBorder
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.Wallpaper
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import dev.chrisbanes.haze.hazeChild
Expand All @@ -21,12 +28,19 @@ 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.ui.navigation.RootConfig
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

@OptIn(ExperimentalHazeMaterialsApi::class)
@Composable
fun HidingNavigationBar(
visible: Boolean,
selected: NavigationBarState,
onWallpaper: () -> Unit,
onHome: () -> Unit,
onFavorites: () -> Unit
) {
val density = LocalDensity.current

Expand Down Expand Up @@ -58,11 +72,32 @@ fun HidingNavigationBar(
contentColor = MaterialTheme.colorScheme.contentColorFor(NavigationBarDefaults.containerColor)
) {
NavigationBarItem(
onClick = { },
selected = true,
onClick = {
if (selected !is NavigationBarState.Wallpaper) {
onWallpaper()
}
},
selected = selected is NavigationBarState.Wallpaper,
icon = {
Icon(
imageVector = selected.wallpaperIcon,
contentDescription = null
)
},
label = {
Text(text = "Wallpapers")
}
)
NavigationBarItem(
onClick = {
if (selected !is NavigationBarState.Home) {
onHome()
}
},
selected = selected is NavigationBarState.Home,
icon = {
Icon(
imageVector = Icons.Filled.Home,
imageVector = selected.homeIcon,
contentDescription = null
)
},
Expand All @@ -71,11 +106,15 @@ fun HidingNavigationBar(
}
)
NavigationBarItem(
onClick = { },
selected = false,
onClick = {
if (selected !is NavigationBarState.Favorite) {
onFavorites()
}
},
selected = selected is NavigationBarState.Favorite,
icon = {
Icon(
imageVector = Icons.Default.FavoriteBorder,
imageVector = selected.favoriteIcon,
contentDescription = null
)
},
Expand All @@ -85,4 +124,56 @@ fun HidingNavigationBar(
)
}
}
}

@Serializable
sealed interface NavigationBarState {
@Transient
val unselectedIcon: ImageVector

@Transient
val selectedIcon: ImageVector
get() = unselectedIcon

val wallpaperIcon: ImageVector
get() = when (this) {
is Wallpaper -> selectedIcon
else -> Wallpaper.unselectedIcon
}

val homeIcon: ImageVector
get() = when (this) {
is Home -> selectedIcon
else -> Home.unselectedIcon
}

val favoriteIcon: ImageVector
get() = when (this) {
is Favorite -> selectedIcon
else -> Favorite.unselectedIcon
}

@Serializable
data object Wallpaper : NavigationBarState {
override val unselectedIcon: ImageVector
get() = Icons.Rounded.Wallpaper
}

@Serializable
data object Home : NavigationBarState {
override val unselectedIcon: ImageVector
get() = Icons.Outlined.Home

override val selectedIcon: ImageVector
get() = Icons.Rounded.Home
}

@Serializable
data object Favorite : NavigationBarState {
override val unselectedIcon: ImageVector
get() = Icons.Rounded.FavoriteBorder

override val selectedIcon: ImageVector
get() = Icons.Rounded.Favorite
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.datlag.aniflow.ui.navigation.screen.favorites

import dev.datlag.aniflow.ui.navigation.Component

interface FavoritesComponent : Component {

fun viewWallpaper()
fun viewHome()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.datlag.aniflow.ui.navigation.screen.favorites

import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import dev.datlag.aniflow.ui.navigation.screen.component.HidingNavigationBar
import dev.datlag.aniflow.ui.navigation.screen.component.NavigationBarState

@Composable
fun FavoritesScreen(component: FavoritesComponent) {
Scaffold(
bottomBar = {
HidingNavigationBar(
visible = true,
selected = NavigationBarState.Favorite,
onWallpaper = component::viewWallpaper,
onHome = component::viewHome,
onFavorites = { }
)
}
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.datlag.aniflow.ui.navigation.screen.favorites

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import com.arkivanov.decompose.ComponentContext
import dev.chrisbanes.haze.HazeState
import dev.datlag.aniflow.LocalHaze
import dev.datlag.aniflow.common.onRender
import org.kodein.di.DI

class FavoritesScreenComponent(
componentContext: ComponentContext,
override val di: DI,
private val onWallpaper: () -> Unit,
private val onHome: () -> Unit,
) : FavoritesComponent, ComponentContext by componentContext {

@Composable
override fun render() {
val haze = remember { HazeState() }

CompositionLocalProvider(
LocalHaze provides haze
) {
onRender {
FavoritesScreen(this)
}
}
}

override fun viewWallpaper() {
onWallpaper()
}

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

fun details(medium: Medium)
fun trace(byteArray: ByteArray)
Expand Down
Loading

0 comments on commit 6a72fa1

Please sign in to comment.