Skip to content

Commit

Permalink
- Update Compose to 2024.09.03
Browse files Browse the repository at this point in the history
Updates Compose to version 2024.09.03 and
 introduces a FloatingActionButtonMenu for details screen.
This commit also wraps navigation calls in coroutines and updates the LoadingDialog to use ContainedLoadingIndicator.
Additionally, it modifies the bottom bar icons to use outlined versions when not selected and refines the blur effect in the reader and details screen.
  • Loading branch information
jacobrein committed Oct 4, 2024
1 parent 92a052a commit 725a82e
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.BrowseGallery
import androidx.compose.material.icons.outlined.History
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.BottomAppBarScrollBehavior
Expand Down Expand Up @@ -458,19 +461,19 @@ abstract class BaseMainActivity : AppCompatActivity() {

ScreenBottomItem(
screen = Screen.RecentScreen,
icon = Icons.Default.History,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.RecentScreen)) Icons.Default.History else Icons.Outlined.History,
label = R.string.recent
)
if (showAllItem) {
ScreenBottomItem(
screen = Screen.AllScreen,
icon = Icons.Default.BrowseGallery,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.AllScreen)) Icons.Default.BrowseGallery else Icons.Outlined.BrowseGallery,
label = R.string.all
)
}
ScreenBottomItem(
screen = Screen.Settings,
icon = Icons.Default.Settings,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.Settings)) Icons.Default.Settings else Icons.Outlined.Settings,
label = R.string.settings,
badge = { if (updateCheck()) Badge { Text("") } }
)
Expand Down Expand Up @@ -526,19 +529,19 @@ abstract class BaseMainActivity : AppCompatActivity() {

ScreenBottomItem(
screen = Screen.RecentScreen,
icon = Icons.Default.History,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.RecentScreen)) Icons.Default.History else Icons.Outlined.History,
label = R.string.recent
)
if (showAllItem) {
ScreenBottomItem(
screen = Screen.AllScreen,
icon = Icons.Default.BrowseGallery,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.AllScreen)) Icons.Default.BrowseGallery else Icons.Outlined.BrowseGallery,
label = R.string.all
)
}
ScreenBottomItem(
screen = Screen.Settings,
icon = Icons.Default.Settings,
icon = if (currentDestination.isTopLevelDestinationInHierarchy(Screen.Settings)) Icons.Default.Settings else Icons.Outlined.Settings,
label = R.string.settings,
badge = { if (updateCheck()) Badge { Text("") } }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
import androidx.compose.material.icons.automirrored.filled.Sort
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.BookmarkRemove
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close
Expand All @@ -34,24 +35,38 @@ import androidx.compose.material3.DrawerState
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FloatingActionButtonMenu
import androidx.compose.material3.FloatingActionButtonMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.ToggleFloatingActionButton
import androidx.compose.material3.ToggleFloatingActionButtonDefaults.animateIcon
import androidx.compose.material3.animateFloatingActionButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.semantics.traversalIndex
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
Expand Down Expand Up @@ -396,4 +411,117 @@ fun DetailBottomBar(
windowInsets = windowInsets,
modifier = modifier
)
}

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun DetailFloatingActionButtonMenu(
navController: NavController,
isVisible: Boolean,
onShowLists: () -> Unit,
info: InfoModel,
removeFromSaved: () -> Unit,
isSaved: Boolean,
canNotify: Boolean,
notifyAction: () -> Unit,
modifier: Modifier = Modifier,
isFavorite: Boolean,
onFavoriteClick: (Boolean) -> Unit,
) {
var fabMenuExpanded by rememberSaveable { mutableStateOf(false) }

BackHandler(fabMenuExpanded) { fabMenuExpanded = false }

FloatingActionButtonMenu(
expanded = fabMenuExpanded,
button = {
ToggleFloatingActionButton(
modifier = Modifier
.semantics {
traversalIndex = -1f
stateDescription = if (fabMenuExpanded) "Expanded" else "Collapsed"
contentDescription = "Toggle menu"
}
.animateFloatingActionButton(
visible = isVisible || fabMenuExpanded,
alignment = Alignment.BottomEnd,
scaleAnimationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
alphaAnimationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
),
checked = fabMenuExpanded,
onCheckedChange = { fabMenuExpanded = !fabMenuExpanded }
) {
val imageVector by remember {
derivedStateOf {
if (checkedProgress > 0.5f) Icons.Filled.Close else Icons.Filled.Add
}
}
Icon(
painter = rememberVectorPainter(imageVector),
contentDescription = null,
modifier = Modifier.animateIcon({ checkedProgress })
)
}
},
modifier = modifier,
) {
if (isSaved) {
FloatingActionButtonMenuItem(
onClick = {
fabMenuExpanded = false
removeFromSaved()
},
icon = { Icon(Icons.Default.BookmarkRemove, contentDescription = null) },
text = { Text(text = "Remove from Saved") },
)
}

FloatingActionButtonMenuItem(
onClick = {
fabMenuExpanded = false
onShowLists()
},
icon = { Icon(Icons.AutoMirrored.Filled.PlaylistAdd, contentDescription = null) },
text = { Text(text = "Add to List") },
)

FloatingActionButtonMenuItem(
onClick = {
fabMenuExpanded = false
navController.navigate(Screen.GlobalSearchScreen(info.title))
},
icon = { Icon(Icons.Default.Search, contentDescription = null) },
text = { Text(text = "Global Search by Name") },
)

FloatingActionButtonMenuItem(
onClick = {
fabMenuExpanded = false
onFavoriteClick(isFavorite)
},
icon = {
Icon(
if (isFavorite) Icons.Default.Favorite else Icons.Default.FavoriteBorder,
contentDescription = null,
)
},
text = { Text(stringResource(if (isFavorite) R.string.removeFromFavorites else R.string.addToFavorites)) },
)

if (isFavorite && LocalContext.current.shouldCheckFlow.collectAsStateWithLifecycle(initialValue = true).value) {
FloatingActionButtonMenuItem(
onClick = {
fabMenuExpanded = false
notifyAction()
},
icon = {
Icon(
if (canNotify) Icons.Default.NotificationsActive else Icons.Default.NotificationsOff,
null
)
},
text = { Text(if (canNotify) "Check for updates" else "Do not check for updates") },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowDropDownCircle
import androidx.compose.material3.BottomAppBarDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand All @@ -50,9 +50,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.toArgb
Expand Down Expand Up @@ -82,9 +80,11 @@ import com.programmersbox.uiviews.utils.NotificationLogo
import com.programmersbox.uiviews.utils.components.OtakuScaffold
import com.programmersbox.uiviews.utils.components.ToolTipWrapper
import com.programmersbox.uiviews.utils.components.minus
import com.programmersbox.uiviews.utils.isScrollingUp
import dev.chrisbanes.haze.HazeState
import dev.chrisbanes.haze.haze
import dev.chrisbanes.haze.hazeChild
import dev.chrisbanes.haze.materials.HazeMaterials
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
Expand All @@ -93,6 +93,7 @@ import me.tatarka.compose.collapsable.rememberCollapsableTopBehavior
import my.nanihadesuka.compose.InternalLazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@ExperimentalComposeUiApi
@ExperimentalMaterial3Api
@ExperimentalAnimationApi
Expand Down Expand Up @@ -124,12 +125,15 @@ fun DetailsView(

val settings = LocalSettingsHandling.current
val showBlur by settings.rememberShowBlur()
val isAmoledMode by settings.rememberIsAmoledMode()

val hostState = remember { SnackbarHostState() }

val notificationManager = LocalContext.current.notificationManager

val listState = rememberLazyListState()

val fabVisible = listState.isScrollingUp()//remember { derivedStateOf { listState.firstVisibleItemIndex == 0 } }

val listDao = LocalCustomListDao.current

val scope = rememberCoroutineScope()
Expand All @@ -150,7 +154,6 @@ fun DetailsView(
}
}

val bottomAppBarScrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior()
//val bottomAppBarScrollBehavior = LocalBottomAppBarScrollBehavior.current
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()

Expand Down Expand Up @@ -187,9 +190,6 @@ fun DetailsView(
}
}
) {
val backgroundColor = MaterialTheme.colorScheme.background

val surface = MaterialTheme.colorScheme.surface

val collapsableBehavior = rememberCollapsableTopBehavior(
enterAlways = false
Expand All @@ -203,7 +203,7 @@ fun DetailsView(
InsetSmallTopAppBar(
modifier = Modifier
.zIndex(2f)
.let { if (showBlur) it.hazeChild(hazeState) { this.backgroundColor = surface } else it },
.let { if (showBlur) it.hazeChild(hazeState, HazeMaterials.thin()) else it },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = if (showBlur)
Color.Transparent
Expand Down Expand Up @@ -299,13 +299,12 @@ fun DetailsView(
)
}
},
bottomBar = {
val notificationManager = LocalContext.current.notificationManager
DetailBottomBar(
floatingActionButton = {
DetailFloatingActionButtonMenu(
navController = navController,
isVisible = fabVisible,
onShowLists = { showLists = true },
info = info,
customActions = {},
removeFromSaved = {
scope.launch(Dispatchers.IO) {
dao.getNotificationItemFlow(info.url)
Expand All @@ -319,27 +318,9 @@ fun DetailsView(
isSaved = isSaved,
canNotify = canNotify,
notifyAction = notifyAction,
containerColor = when {
showBlur -> Color.Transparent
isAmoledMode -> MaterialTheme.colorScheme.surface
else -> BottomAppBarDefaults.containerColor
},
isFavorite = isFavorite,
onFavoriteClick = onFavoriteClick,
bottomAppBarScrollBehavior = bottomAppBarScrollBehavior,
modifier = Modifier
.padding(LocalNavHostPadding.current)
.drawWithCache {
onDrawBehind {
drawLine(
backgroundColor,
Offset(0f, 8f),
Offset(size.width, 8f),
4 * density
)
}
}
.let { if (showBlur) it.hazeChild(hazeState) { this.backgroundColor = surface } else it }
modifier = Modifier.padding(LocalNavHostPadding.current)
)
},
snackbarHost = {
Expand All @@ -362,7 +343,6 @@ fun DetailsView(
modifier = Modifier
.nestedScroll(collapsableBehavior.nestedScrollConnection)
.nestedScroll(scrollBehavior.nestedScrollConnection)
.nestedScroll(bottomAppBarScrollBehavior.nestedScrollConnection)
) { p ->
val modifiedPaddingValues = p - LocalNavHostPadding.current
var descriptionVisibility by remember { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fun OtakuListScreen(
onSearchBarActiveChange = { viewModel.searchBarActive = it },
navigateBack = {
viewModel.customItem = null
state.navigateBack()
scope.launch { state.navigateBack() }
},
addSecurityItem = {
scope.launch { listDao.updateBiometric(it, true) }
Expand All @@ -117,7 +117,7 @@ fun OtakuListScreen(
)
BackHandler {
viewModel.customItem = null
state.navigateBack()
scope.launch { state.navigateBack() }
}
} else {
NoDetailSelected()
Expand All @@ -127,10 +127,12 @@ fun OtakuListScreen(
}

val navigate = {
if (showListDetail)
state.navigateTo(ListDetailPaneScaffoldRole.Detail)
else
state.navigateTo(ListDetailPaneScaffoldRole.Extra)
scope.launch {
if (showListDetail)
state.navigateTo(ListDetailPaneScaffoldRole.Detail)
else
state.navigateTo(ListDetailPaneScaffoldRole.Extra)
}
}

val biometricPrompt = rememberBiometricPrompt(
Expand Down
Loading

0 comments on commit 725a82e

Please sign in to comment.