-
-
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
16 changed files
with
526 additions
and
17 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
11 changes: 11 additions & 0 deletions
11
...commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperComponent.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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
package dev.datlag.aniflow.ui.navigation.screen.wallpaper | ||
|
||
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 { | ||
|
||
val adultContent: Flow<Boolean> | ||
val rating: StateFlow<Rating> | ||
|
||
val state: Flow<NekosRepository.State> | ||
|
||
fun viewHome() | ||
fun viewFavorites() | ||
|
||
fun filter(rating: Rating) | ||
} |
128 changes: 125 additions & 3 deletions
128
...rc/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/wallpaper/WallpaperScreen.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 |
---|---|---|
@@ -1,23 +1,145 @@ | ||
package dev.datlag.aniflow.ui.navigation.screen.wallpaper | ||
|
||
import androidx.compose.material3.Scaffold | ||
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.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.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.layout.ContentScale | ||
import androidx.compose.ui.unit.dp | ||
import coil3.compose.AsyncImage | ||
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState | ||
import com.maxkeppeler.sheets.option.OptionDialog | ||
import com.maxkeppeler.sheets.option.models.DisplayMode | ||
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.datlag.aniflow.LocalHaze | ||
import dev.datlag.aniflow.common.isScrollingUp | ||
import dev.datlag.aniflow.common.merge | ||
import dev.datlag.aniflow.nekos.NekosRepository | ||
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 io.github.aakira.napier.Napier | ||
|
||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun WallpaperScreen(component: WallpaperComponent) { | ||
val listState = rememberLazyStaggeredGridState() | ||
|
||
Scaffold( | ||
floatingActionButton = { | ||
val dialogState = rememberUseCaseState( | ||
visible = false | ||
) | ||
val adultContent by component.adultContent.collectAsStateWithLifecycle(false) | ||
val rating by component.rating.collectAsStateWithLifecycle() | ||
|
||
OptionDialog( | ||
state = dialogState, | ||
config = OptionConfig( | ||
mode = DisplayMode.LIST | ||
), | ||
selection = OptionSelection.Single( | ||
options = listOf( | ||
Option( | ||
titleText = "Safe", | ||
selected = rating is Rating.Safe, | ||
), | ||
Option( | ||
titleText = "Suggestive", | ||
selected = rating is Rating.Suggestive, | ||
), | ||
Option( | ||
titleText = "Borderline", | ||
selected = rating is Rating.Borderline, | ||
disabled = !adultContent | ||
), | ||
Option( | ||
titleText = "Explicit", | ||
selected = rating is Rating.Explicit, | ||
disabled = !adultContent | ||
) | ||
), | ||
onSelectOption = { option, _ -> | ||
val filterRating = when (option) { | ||
1 -> Rating.Suggestive | ||
2 -> Rating.Borderline | ||
3 -> Rating.Explicit | ||
else -> Rating.Safe | ||
} | ||
component.filter(filterRating) | ||
} | ||
) | ||
) | ||
|
||
ExtendedFloatingActionButton( | ||
onClick = { dialogState.show() }, | ||
expanded = listState.isScrollingUp(), | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Rounded.FilterList, | ||
contentDescription = null | ||
) | ||
}, | ||
text = { | ||
Text(text = "Filter") | ||
} | ||
) | ||
}, | ||
bottomBar = { | ||
HidingNavigationBar( | ||
visible = true, | ||
visible = listState.isScrollingUp(), | ||
selected = NavigationBarState.Wallpaper, | ||
onWallpaper = { }, | ||
onHome = component::viewHome, | ||
onFavorites = component::viewFavorites | ||
) | ||
} | ||
) { | ||
) { padding -> | ||
val state by component.state.collectAsStateWithLifecycle(NekosRepository.State.None) | ||
|
||
when (val current = state) { | ||
is NekosRepository.State.None -> Text(text = "Loading") | ||
is NekosRepository.State.Error -> Text(text = "Error") | ||
is NekosRepository.State.Success -> { | ||
LazyVerticalStaggeredGrid( | ||
state = listState, | ||
modifier = Modifier.haze(state = LocalHaze.current), | ||
columns = StaggeredGridCells.Adaptive(120.dp), | ||
contentPadding = padding.merge(PaddingValues(16.dp)), | ||
horizontalArrangement = Arrangement.spacedBy(16.dp), | ||
verticalItemSpacing = 16.dp | ||
) { | ||
items(current.response.items, key = { it.id }) { | ||
Card( | ||
modifier = Modifier.animateItemPlacement(), | ||
onClick = { | ||
Napier.e(it.toString()) | ||
} | ||
) { | ||
AsyncImage( | ||
modifier = Modifier.fillMaxSize(), | ||
model = it.imageUrl ?: it.sampleUrl, | ||
contentDescription = null, | ||
contentScale = ContentScale.Crop | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.