Skip to content

Commit

Permalink
Adding a bottombar to DetailsViewLandscape.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepurple13 committed Dec 20, 2023
1 parent bd4f6a9 commit fb3c5ad
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fun DetailsScreen(
details: DetailsViewModel = viewModel { DetailsViewModel(createSavedStateHandle(), genericInfo, dao = dao, context = localContext) },
) {
val uriHandler = LocalUriHandler.current
val showDownload by LocalSettingsHandling.current.showDownload.flow.collectAsStateWithLifecycle(initialValue = true)

if (details.info == null) {
Scaffold(
Expand Down Expand Up @@ -180,7 +181,8 @@ fun DetailsScreen(
chapters = details.chapters,
markAs = details::markAs,
description = details.description,
onTranslateDescription = details::translateDescription
onTranslateDescription = details::translateDescription,
showDownloadButton = showDownload
)
} else {
DetailsView(
Expand All @@ -193,7 +195,8 @@ fun DetailsScreen(
chapters = details.chapters,
markAs = details::markAs,
description = details.description,
onTranslateDescription = details::translateDescription
onTranslateDescription = details::translateDescription,
showDownloadButton = showDownload
)
}
}
Expand Down Expand Up @@ -291,12 +294,12 @@ fun ChapterItem(
read: List<ChapterWatched>,
chapters: List<ChapterModel>,
shareChapter: Boolean,
showDownload: Boolean,
markAs: (ChapterModel, Boolean) -> Unit,
) {
val historyDao = LocalHistoryDao.current
val swatchInfo = LocalSwatchInfo.current.colors
val navController = LocalNavController.current
val showDownload by LocalSettingsHandling.current.showDownload.flow.collectAsStateWithLifecycle(initialValue = true)
val genericInfo = LocalGenericInfo.current
val context = LocalContext.current
val scope = rememberCoroutineScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import android.content.Intent
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.systemBars
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.BookmarkRemove
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Delete
Expand All @@ -20,29 +24,36 @@ import androidx.compose.material.icons.filled.OpenInBrowser
import androidx.compose.material.icons.filled.Save
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.BottomAppBarScrollBehavior
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import com.programmersbox.favoritesdatabase.ItemDao
import com.programmersbox.favoritesdatabase.ListDao
Expand All @@ -54,6 +65,7 @@ import com.programmersbox.uiviews.lists.ListChoiceScreen
import com.programmersbox.uiviews.utils.Screen
import com.programmersbox.uiviews.utils.launchCatching
import com.programmersbox.uiviews.utils.showErrorToast
import com.programmersbox.uiviews.utils.toComposeColor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull
Expand Down Expand Up @@ -112,7 +124,7 @@ internal fun AddToList(
showListsChange: (Boolean) -> Unit,
info: InfoModel,
listDao: ListDao,
hostState: SnackbarHostState,
hostState: SnackbarHostState?,
scope: CoroutineScope,
context: Context,
) {
Expand All @@ -136,7 +148,7 @@ internal fun AddToList(
info.imageUrl,
info.source.serviceName
)
hostState.showSnackbar(
hostState?.showSnackbar(
context.getString(
if (result) {
R.string.added_to_list
Expand Down Expand Up @@ -293,4 +305,65 @@ internal fun DetailActions(
IconButton(onClick = { showDropDown = true }) {
Icon(Icons.Default.MoreVert, null, tint = topBarColor)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DetailBottomBar(
navController: NavController,
onShowLists: () -> Unit,
info: InfoModel,
customActions: @Composable () -> Unit,
removeFromSaved: () -> Unit,
isSaved: Boolean,
topBarColor: Color,
modifier: Modifier = Modifier,
containerColor: Color = Color.Transparent,
bottomAppBarScrollBehavior: BottomAppBarScrollBehavior? = null,
windowInsets: WindowInsets = WindowInsets(0.dp),
) {
BottomAppBar(
actions = {
ToolTipWrapper(
info = { Text("Add to List") }
) {
IconButton(
onClick = onShowLists,
) { Icon(Icons.AutoMirrored.Filled.PlaylistAdd, null) }
}

ToolTipWrapper(
info = { Text("Global Search by Name") }
) {
IconButton(
onClick = { Screen.GlobalSearchScreen.navigate(navController, info.title) },
) { Icon(Icons.Default.Search, null) }
}

customActions()
},
floatingActionButton = {
AnimatedVisibility(
visible = isSaved,
enter = slideInHorizontally { it },
exit = slideOutHorizontally { it },
label = "",
) {
val swatchInfo = LocalSwatchInfo.current.colors
ExtendedFloatingActionButton(
onClick = removeFromSaved,
text = { Text("Remove from Saved") },
icon = { Icon(Icons.Default.BookmarkRemove, null) },
containerColor = swatchInfo?.rgb?.toComposeColor() ?: FloatingActionButtonDefaults.containerColor,
contentColor = swatchInfo?.titleColor?.toComposeColor()
?: contentColorFor(FloatingActionButtonDefaults.containerColor),
)
}
},
containerColor = containerColor,
contentColor = topBarColor,
scrollBehavior = bottomAppBarScrollBehavior,
windowInsets = windowInsets,
modifier = modifier
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
package com.programmersbox.uiviews.details

import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.combinedClickable
Expand All @@ -25,18 +22,12 @@ import androidx.compose.foundation.lazy.rememberLazyListState
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.automirrored.filled.PlaylistAdd
import androidx.compose.material.icons.filled.ArrowDropDownCircle
import androidx.compose.material.icons.filled.BookmarkRemove
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.BottomAppBarDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand All @@ -52,7 +43,6 @@ import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.TooltipState
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.rememberDrawerState
import androidx.compose.material3.rememberTooltipState
import androidx.compose.material3.rememberTopAppBarState
Expand Down Expand Up @@ -93,7 +83,6 @@ import com.programmersbox.uiviews.utils.LocalItemDao
import com.programmersbox.uiviews.utils.LocalNavController
import com.programmersbox.uiviews.utils.LocalNavHostPadding
import com.programmersbox.uiviews.utils.NotificationLogo
import com.programmersbox.uiviews.utils.Screen
import com.programmersbox.uiviews.utils.animate
import com.programmersbox.uiviews.utils.components.OtakuScaffold
import com.programmersbox.uiviews.utils.components.minus
Expand Down Expand Up @@ -124,6 +113,7 @@ fun DetailsView(
logo: NotificationLogo,
description: String,
onTranslateDescription: (MutableState<Boolean>) -> Unit,
showDownloadButton: Boolean,
) {
val hazeState = remember { HazeState() }
val dao = LocalItemDao.current
Expand Down Expand Up @@ -258,24 +248,12 @@ fun DetailsView(
}
},
bottomBar = {
BottomAppBar(
actions = {
ToolTipWrapper(
info = { Text("Add to List") }
) {
IconButton(
onClick = { showLists = true },
) { Icon(Icons.AutoMirrored.Filled.PlaylistAdd, null) }
}

ToolTipWrapper(
info = { Text("Global Search by Name") }
) {
IconButton(
onClick = { Screen.GlobalSearchScreen.navigate(navController, info.title) },
) { Icon(Icons.Default.Search, null) }
}

val notificationManager = LocalContext.current.notificationManager
DetailBottomBar(
navController = navController,
onShowLists = { showLists = true },
info = info,
customActions = {
val expanded by remember { derivedStateOf { collapsableBehavior.state.collapsedFraction >= 0.5f } }

ToolTipWrapper(
Expand All @@ -297,37 +275,19 @@ fun DetailsView(
}
}
},
floatingActionButton = {
AnimatedVisibility(
visible = isSaved,
enter = slideInHorizontally { it },
exit = slideOutHorizontally { it },
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),
)
removeFromSaved = {
scope.launch(Dispatchers.IO) {
dao.getNotificationItemFlow(info.url)
.firstOrNull()
?.let {
dao.deleteNotification(it)
notificationManager.cancelNotification(it)
}
}
},
containerColor = Color.Transparent,
contentColor = topBarColor,
scrollBehavior = bottomAppBarScrollBehavior,
windowInsets = WindowInsets(0.dp),
isSaved = isSaved,
bottomAppBarScrollBehavior = bottomAppBarScrollBehavior,
topBarColor = topBarColor,
modifier = Modifier
.padding(LocalNavHostPadding.current)
.drawWithCache {
Expand Down Expand Up @@ -421,7 +381,8 @@ fun DetailsView(
read = chapters,
chapters = info.chapters,
shareChapter = shareChapter,
markAs = markAs
markAs = markAs,
showDownload = showDownloadButton
)
}
}
Expand All @@ -440,7 +401,7 @@ fun DetailsView(

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ToolTipWrapper(
internal fun ToolTipWrapper(
info: @Composable () -> Unit,
modifier: Modifier = Modifier,
tooltipState: TooltipState = rememberTooltipState(),
Expand Down
Loading

0 comments on commit fb3c5ad

Please sign in to comment.