Skip to content

Commit

Permalink
lib updates
Browse files Browse the repository at this point in the history
The list stuff is broken now so trying to figure that out
Setting up haze better
  • Loading branch information
jakepurple13 committed Dec 20, 2023
1 parent afffd4e commit 670a7dc
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 329 deletions.
2 changes: 1 addition & 1 deletion UIViews/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ dependencies {

implementation(libs.compose.collapsable)

implementation("androidx.compose.material3:material3-adaptive-navigation-suite:1.0.0-alpha01")
implementation("androidx.compose.material3:material3-adaptive-navigation-suite:1.0.0-alpha02")
implementation(libs.materialAdaptive)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import com.programmersbox.uiviews.utils.Screen
import com.programmersbox.uiviews.utils.SettingsHandling
import com.programmersbox.uiviews.utils.appVersion
import com.programmersbox.uiviews.utils.chromeCustomTabs
import com.programmersbox.uiviews.utils.components.GlassScaffold
import com.programmersbox.uiviews.utils.components.HazeScaffold
import com.programmersbox.uiviews.utils.currentDetailsUrl
import com.programmersbox.uiviews.utils.currentService
import com.programmersbox.uiviews.utils.dispatchIo
Expand Down Expand Up @@ -213,7 +213,7 @@ abstract class BaseMainActivity : AppCompatActivity() {
showAllItem = showAllItem,
currentDestination = currentDestination
)
GlassScaffold(
HazeScaffold(
bottomBar = {
BottomNav(
navController = navController,
Expand Down Expand Up @@ -569,7 +569,11 @@ abstract class BaseMainActivity : AppCompatActivity() {
Screen.CustomListScreen.route,
enterTransition = { slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Start) },
exitTransition = { slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.End) }
) { OtakuListScreen() }
) {
OtakuListScreen(
isHorizontal = windowSize.widthSizeClass == WindowWidthSizeClass.Expanded
)
}

composable(
Screen.ImportListScreen.route + "?uri={uri}"
Expand Down Expand Up @@ -621,7 +625,11 @@ abstract class BaseMainActivity : AppCompatActivity() {
Screen.CustomListScreen.route + "_home",
enterTransition = { slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Start) },
exitTransition = { slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.End) }
) { OtakuListScreen() }
) {
OtakuListScreen(
isHorizontal = windowSize.widthSizeClass == WindowWidthSizeClass.Expanded
)
}

composable(
Screen.NotificationScreen.route + "_home",
Expand Down
167 changes: 64 additions & 103 deletions UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -72,13 +71,11 @@ import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand All @@ -101,8 +98,9 @@ import com.programmersbox.uiviews.utils.animate
import com.programmersbox.uiviews.utils.components.OtakuScaffold
import com.programmersbox.uiviews.utils.components.minus
import com.programmersbox.uiviews.utils.toComposeColor
import com.programmersbox.uiviews.utils.topBounds
import dev.chrisbanes.haze.HazeState
import dev.chrisbanes.haze.haze
import dev.chrisbanes.haze.hazeChild
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
Expand All @@ -127,6 +125,7 @@ fun DetailsView(
description: String,
onTranslateDescription: (MutableState<Boolean>) -> Unit,
) {
val hazeState = remember { HazeState() }
val dao = LocalItemDao.current
val swatchInfo = LocalSwatchInfo.current.colors
val genericInfo = LocalGenericInfo.current
Expand Down Expand Up @@ -213,7 +212,9 @@ fun DetailsView(
behavior = collapsableBehavior
) {
InsetSmallTopAppBar(
modifier = Modifier.zIndex(2f),
modifier = Modifier
.zIndex(2f)
.hazeChild(hazeState),
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
titleContentColor = topBarColor
Expand Down Expand Up @@ -339,6 +340,7 @@ fun DetailsView(
)
}
}
.hazeChild(hazeState)
)
},
snackbarHost = {
Expand All @@ -358,121 +360,80 @@ fun DetailsView(
)
}
},
floatingActionButton = {
/*AnimatedVisibility(
visible = isSaved,
enter = fadeIn() + slideInHorizontally { it / 2 },
exit = slideOutHorizontally { it / 2 } + fadeOut(),
label = "",
) {
val notificationManager = LocalContext.current.notificationManager
ExtendedFloatingActionButton(
onClick = {
scope.launch(Dispatchers.IO) {
dao.getNotificationItemFlow(info.url)
.firstOrNull()
?.let {
dao.deleteNotification(it)
notificationManager.cancelNotification(it)
}
}
},
text = { Text("Remove from Saved") },
icon = { Icon(Icons.Default.BookmarkRemove, null) },
containerColor = swatchInfo?.rgb?.toComposeColor() ?: FloatingActionButtonDefaults.containerColor,
contentColor = swatchInfo?.titleColor?.toComposeColor()
?: contentColorFor(FloatingActionButtonDefaults.containerColor),
expanded = listState.isScrollingUp()
)
}*/
},
modifier = Modifier
.drawBehind { drawRect(Brush.verticalGradient(listOf(c, b))) }
.nestedScroll(scrollBehavior.nestedScrollConnection)
.nestedScroll(collapsableBehavior.nestedScrollConnection)
.nestedScroll(bottomAppBarScrollBehavior.nestedScrollConnection)
) { p ->
val modifiedPaddingValues = p - LocalNavHostPadding.current
BoxWithConstraints {
var descriptionVisibility by remember { mutableStateOf(false) }
LazyColumn(
verticalArrangement = Arrangement.spacedBy(4.dp),
state = listState,
contentPadding = modifiedPaddingValues,
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 4.dp)
.haze(
area = arrayOf(
topBounds(p),
with(LocalDensity.current) {
val bottomPaddingPx = modifiedPaddingValues
.calculateBottomPadding()
.toPx()
Rect(
Offset(0f, maxHeight.toPx() - bottomPaddingPx),
Offset(maxWidth.toPx(), maxHeight.toPx())
var descriptionVisibility by remember { mutableStateOf(false) }
LazyColumn(
verticalArrangement = Arrangement.spacedBy(4.dp),
state = listState,
contentPadding = modifiedPaddingValues,
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 4.dp)
.haze(
hazeState,
backgroundColor = swatchInfo?.rgb
?.toComposeColor()
?.animate()?.value ?: MaterialTheme.colorScheme.surface
),
) {
if (info.description.isNotEmpty()) {
item {
Box {
val progress = remember { mutableStateOf(false) }

Text(
description,
modifier = Modifier
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(),
onClick = { descriptionVisibility = !descriptionVisibility },
onLongClick = { onTranslateDescription(progress) }
)
}
),
backgroundColor = swatchInfo?.rgb
?.toComposeColor()
?.animate()?.value ?: MaterialTheme.colorScheme.surface
),
) {
if (info.description.isNotEmpty()) {
item {
Box {
val progress = remember { mutableStateOf(false) }
.padding(horizontal = 4.dp)
.fillMaxWidth()
.animateContentSize(),
overflow = TextOverflow.Ellipsis,
maxLines = if (descriptionVisibility) Int.MAX_VALUE else 3,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface
)

Text(
description,
modifier = Modifier
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(),
onClick = { descriptionVisibility = !descriptionVisibility },
onLongClick = { onTranslateDescription(progress) }
)
.padding(horizontal = 4.dp)
.fillMaxWidth()
.animateContentSize(),
overflow = TextOverflow.Ellipsis,
maxLines = if (descriptionVisibility) Int.MAX_VALUE else 3,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface
if (progress.value) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center)
)

if (progress.value) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center)
)
}
}
}
}

items(info.chapters.let { if (reverseChapters) it.reversed() else it }) { c ->
ChapterItem(
infoModel = info,
c = c,
read = chapters,
chapters = info.chapters,
shareChapter = shareChapter,
markAs = markAs
)
}
}
Box(Modifier.padding(modifiedPaddingValues)) {
InternalLazyColumnScrollbar(
thickness = 8.dp,
padding = 2.dp,
listState = listState,
thumbColor = swatchInfo?.bodyColor?.toComposeColor() ?: MaterialTheme.colorScheme.primary,
thumbSelectedColor = (swatchInfo?.bodyColor?.toComposeColor() ?: MaterialTheme.colorScheme.primary).copy(alpha = .6f),

items(info.chapters.let { if (reverseChapters) it.reversed() else it }) { c ->
ChapterItem(
infoModel = info,
c = c,
read = chapters,
chapters = info.chapters,
shareChapter = shareChapter,
markAs = markAs
)
}
}
Box(Modifier.padding(modifiedPaddingValues)) {
InternalLazyColumnScrollbar(
thickness = 8.dp,
padding = 2.dp,
listState = listState,
thumbColor = swatchInfo?.bodyColor?.toComposeColor() ?: MaterialTheme.colorScheme.primary,
thumbSelectedColor = (swatchInfo?.bodyColor?.toComposeColor() ?: MaterialTheme.colorScheme.primary).copy(alpha = .6f),
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
Expand Down Expand Up @@ -100,8 +99,9 @@ import com.programmersbox.uiviews.utils.components.ListBottomScreen
import com.programmersbox.uiviews.utils.components.ListBottomSheetItemModel
import com.programmersbox.uiviews.utils.components.OtakuScaffold
import com.programmersbox.uiviews.utils.navigateToDetails
import com.programmersbox.uiviews.utils.topBounds
import dev.chrisbanes.haze.HazeState
import dev.chrisbanes.haze.haze
import dev.chrisbanes.haze.hazeChild
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.koin.compose.koinInject
Expand All @@ -117,6 +117,7 @@ fun FavoriteUi(
sourceRepository: SourceRepository = LocalSourcesRepository.current,
viewModel: FavoriteViewModel = viewModel { FavoriteViewModel(dao, sourceRepository) },
) {
val hazeState = remember { HazeState() }
val navController = LocalNavController.current
val context = LocalContext.current

Expand Down Expand Up @@ -234,7 +235,7 @@ fun FavoriteUi(
OtakuScaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = {
Column {
Column(Modifier.hazeChild(hazeState)) {
var active by rememberSaveable { mutableStateOf(false) }

fun closeSearchBar() {
Expand Down Expand Up @@ -401,35 +402,33 @@ fun FavoriteUi(
}
}
} else {
BoxWithConstraints {
FavoritesGrid(
paddingValues = p,
groupedSources = viewModel.groupedSources,
sourceRepository = sourceRepository,
navController = navController,
moreInfoClick = {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
val result = snackbarHostState.showSnackbar(
"Something went wrong. Source might not be installed",
duration = SnackbarDuration.Long,
actionLabel = "More Options",
withDismissAction = true
)
showDbModel = when (result) {
SnackbarResult.Dismissed -> null
SnackbarResult.ActionPerformed -> it
}
FavoritesGrid(
paddingValues = p,
groupedSources = viewModel.groupedSources,
sourceRepository = sourceRepository,
navController = navController,
moreInfoClick = {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
val result = snackbarHostState.showSnackbar(
"Something went wrong. Source might not be installed",
duration = SnackbarDuration.Long,
actionLabel = "More Options",
withDismissAction = true
)
showDbModel = when (result) {
SnackbarResult.Dismissed -> null
SnackbarResult.ActionPerformed -> it
}
},
onShowBanner = { showBanner = it },
logo = logo,
modifier = Modifier.haze(
topBounds(p),
backgroundColor = MaterialTheme.colorScheme.surface
)
}
},
onShowBanner = { showBanner = it },
logo = logo,
modifier = Modifier.haze(
hazeState,
backgroundColor = MaterialTheme.colorScheme.surface
)
}
)
}
}
}
Expand Down
Loading

0 comments on commit 670a7dc

Please sign in to comment.