From 97976700de22a88111f562dcda8497a2289b5119 Mon Sep 17 00:00:00 2001 From: Jacob Rein Date: Thu, 16 Nov 2023 09:42:21 -0500 Subject: [PATCH] Small cleanup --- .../uiviews/details/DetailsFragment.kt | 8 ++---- .../uiviews/details/DetailsUtils.kt | 5 ++-- .../uiviews/history/HistoryFragment.kt | 10 +++---- .../uiviews/lists/OtakuCustomListScreen.kt | 8 +++--- .../notifications/NotificationFragment.kt | 16 +++++------ .../uiviews/settings/InfoSettings.kt | 8 ++++-- .../uiviews/settings/SettingsFragment.kt | 28 ++++++------------- .../programmersbox/uiviews/utils/Screen.kt | 26 ++++++++++++++++- .../components/BottomSheetDeleteScaffold.kt | 10 +++---- .../animeworld/videos/ViewVideosFragment.kt | 12 ++++---- .../downloads/DownloadViewerFragment.kt | 8 +++--- .../mangaworld/reader/ReaderCompose.kt | 10 +++---- 12 files changed, 82 insertions(+), 67 deletions(-) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsFragment.kt index 37b04719e..5ca60da45 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsFragment.kt @@ -63,6 +63,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.util.fastAny @@ -90,7 +91,6 @@ import com.programmersbox.uiviews.utils.components.OtakuScaffold import com.programmersbox.uiviews.utils.findActivity import com.programmersbox.uiviews.utils.historySave import com.programmersbox.uiviews.utils.launchCatching -import com.programmersbox.uiviews.utils.navigateChromeCustomTabs import com.programmersbox.uiviews.utils.toComposeColor import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first @@ -112,7 +112,7 @@ fun DetailsScreen( genericInfo: GenericInfo = LocalGenericInfo.current, details: DetailsViewModel = viewModel { DetailsViewModel(createSavedStateHandle(), genericInfo, dao = dao, context = localContext) }, ) { - val navController = LocalNavController.current + val uriHandler = LocalUriHandler.current if (details.info == null) { Scaffold( @@ -147,9 +147,7 @@ fun DetailsScreen( IconButton( onClick = { - details.itemModel?.url?.let { - navController.navigateChromeCustomTabs(it) - } + details.itemModel?.url?.let { uriHandler.openUri(it) } } ) { Icon(Icons.Default.OpenInBrowser, null) } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt index 5c0a4b796..e49b4d30c 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/details/DetailsUtils.kt @@ -39,6 +39,7 @@ import androidx.compose.runtime.setValue import androidx.compose.runtime.staticCompositionLocalOf 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 @@ -52,7 +53,6 @@ import com.programmersbox.uiviews.R import com.programmersbox.uiviews.lists.ListChoiceScreen import com.programmersbox.uiviews.utils.Screen import com.programmersbox.uiviews.utils.launchCatching -import com.programmersbox.uiviews.utils.navigateChromeCustomTabs import com.programmersbox.uiviews.utils.showErrorToast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -121,6 +121,7 @@ internal fun DetailActions( dao: ItemDao, onReverseChaptersClick: () -> Unit, ) { + val uriHandler = LocalUriHandler.current var showLists by remember { mutableStateOf(false) } if (showLists) { @@ -184,7 +185,7 @@ internal fun DetailActions( DropdownMenuItem( onClick = { dropDownDismiss() - navController.navigateChromeCustomTabs(info.url) + uriHandler.openUri(info.url) }, text = { Text(stringResource(id = R.string.fallback_menu_item_open_in_browser)) }, leadingIcon = { Icon(Icons.Default.OpenInBrowser, null) } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/history/HistoryFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/history/HistoryFragment.kt index fcabe3a9c..8064dc099 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/history/HistoryFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/history/HistoryFragment.kt @@ -31,7 +31,7 @@ import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarResult import androidx.compose.material3.Surface -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBarDefaults @@ -237,10 +237,10 @@ private fun HistoryItem( } ) - SwipeToDismiss( + SwipeToDismissBox( state = dismissState, - background = { - val direction = dismissState.dismissDirection ?: return@SwipeToDismiss + backgroundContent = { + val direction = dismissState.dismissDirection ?: return@SwipeToDismissBox val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -272,7 +272,7 @@ private fun HistoryItem( ) } }, - dismissContent = { + content = { var showLoadingDialog by remember { mutableStateOf(false) } LoadingDialog( diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuCustomListScreen.kt b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuCustomListScreen.kt index dda9cb114..4e992771a 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuCustomListScreen.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuCustomListScreen.kt @@ -68,7 +68,7 @@ import androidx.compose.material3.SearchBarDefaults import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TextField @@ -620,11 +620,11 @@ private fun CustomItem( } ) - SwipeToDismiss( + SwipeToDismissBox( modifier = modifier, state = dismissState, directions = setOf(DismissDirection.EndToStart), - background = { + backgroundContent = { val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -649,7 +649,7 @@ private fun CustomItem( ) } }, - dismissContent = { + content = { ElevatedCard( onClick = { sourceRepository diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/notifications/NotificationFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/notifications/NotificationFragment.kt index bda92bc2b..7b198ef21 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/notifications/NotificationFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/notifications/NotificationFragment.kt @@ -53,7 +53,7 @@ import androidx.compose.material3.SheetValue import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarResult import androidx.compose.material3.Surface -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TimePicker @@ -559,10 +559,10 @@ private fun DateSort( } ) - SwipeToDismiss( + SwipeToDismissBox( state = dismissState, modifier = Modifier.weight(1f, false), - background = { + backgroundContent = { val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -592,7 +592,7 @@ private fun DateSort( ) } }, - dismissContent = { + content = { M3CoverCard( imageUrl = i.imageUrl.orEmpty(), name = i.notiTitle, @@ -685,10 +685,10 @@ private fun NotificationItem( } ) - SwipeToDismiss( + SwipeToDismissBox( state = dismissState, - background = { - val direction = dismissState.dismissDirection ?: return@SwipeToDismiss + backgroundContent = { + val direction = dismissState.dismissDirection ?: return@SwipeToDismissBox val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -721,7 +721,7 @@ private fun NotificationItem( ) } }, - dismissContent = { + content = { ElevatedCard( onClick = { toSource(item.source) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/settings/InfoSettings.kt b/UIViews/src/main/java/com/programmersbox/uiviews/settings/InfoSettings.kt index 932d50742..994b8b4d6 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/settings/InfoSettings.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/settings/InfoSettings.kt @@ -26,6 +26,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.lifecycle.viewmodel.compose.viewModel import com.google.accompanist.drawablepainter.rememberDrawablePainter @@ -62,6 +63,7 @@ fun InfoSettings( val navController = LocalNavController.current val scope = rememberCoroutineScope() val context = LocalContext.current + val uriHandler = LocalUriHandler.current SettingsScaffold(stringResource(R.string.more_info_category)) { PreferenceSetting( @@ -80,7 +82,7 @@ fun InfoSettings( modifier = Modifier.clickable( indication = rememberRipple(), interactionSource = remember { MutableInteractionSource() } - ) { navController.navigateChromeCustomTabs("https://github.com/jakepurple13/OtakuWorld/releases/latest") } + ) { uriHandler.openUri("https://github.com/jakepurple13/OtakuWorld/releases/latest") } ) PreferenceSetting( @@ -89,7 +91,7 @@ fun InfoSettings( modifier = Modifier.clickable( indication = rememberRipple(), interactionSource = remember { MutableInteractionSource() } - ) { navController.navigateChromeCustomTabs("https://discord.gg/MhhHMWqryg") } + ) { uriHandler.openUri("https://discord.gg/MhhHMWqryg") } ) PreferenceSetting( @@ -99,7 +101,7 @@ fun InfoSettings( modifier = Modifier.clickable( indication = rememberRipple(), interactionSource = remember { MutableInteractionSource() } - ) { navController.navigateChromeCustomTabs("https://ko-fi.com/V7V3D3JI") } + ) { uriHandler.openUri("https://ko-fi.com/V7V3D3JI") } ) val appUpdate by updateAppCheck.collectAsState(null) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/settings/SettingsFragment.kt b/UIViews/src/main/java/com/programmersbox/uiviews/settings/SettingsFragment.kt index ec7cbc9ed..74f2cfae5 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/settings/SettingsFragment.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/settings/SettingsFragment.kt @@ -53,6 +53,7 @@ import androidx.compose.ui.composed import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -67,6 +68,7 @@ import com.programmersbox.uiviews.BuildConfig import com.programmersbox.uiviews.R import com.programmersbox.uiviews.utils.BackButton import com.programmersbox.uiviews.utils.CategorySetting +import com.programmersbox.uiviews.utils.InsetLargeTopAppBar import com.programmersbox.uiviews.utils.InsetSmallTopAppBar import com.programmersbox.uiviews.utils.LifecycleHandle import com.programmersbox.uiviews.utils.LightAndDarkPreviews @@ -85,7 +87,6 @@ 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.currentService -import com.programmersbox.uiviews.utils.navigateChromeCustomTabs import com.programmersbox.uiviews.utils.showSourceChooser import com.programmersbox.uiviews.utils.showTranslationScreen import kotlinx.coroutines.launch @@ -122,12 +123,11 @@ fun SettingScreen( globalSearchClick: () -> Unit = {}, listClick: () -> Unit = {} ) { - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) + val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState()) OtakuScaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { - InsetSmallTopAppBar( + InsetLargeTopAppBar( title = { Text(stringResource(R.string.settings)) }, scrollBehavior = scrollBehavior, actions = { @@ -137,7 +137,8 @@ fun SettingScreen( } ) }, - contentWindowInsets = ScaffoldDefaults.contentWindowInsets + contentWindowInsets = ScaffoldDefaults.contentWindowInsets, + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), ) { p -> Column( modifier = Modifier @@ -171,6 +172,7 @@ private fun SettingsScreen( listClick: () -> Unit, ) { val navController = LocalNavController.current + val uriHandler = LocalUriHandler.current val source by LocalCurrentSource.current.asFlow().collectAsState(initial = null) if (BuildConfig.DEBUG) { @@ -275,21 +277,7 @@ private fun SettingsScreen( enabled = source != null, indication = rememberRipple(), interactionSource = remember { MutableInteractionSource() } - ) { - source?.baseUrl?.let { - navController.navigateChromeCustomTabs( - it, - { - anim { - enter = R.anim.slide_in_right - popEnter = R.anim.slide_in_right - exit = R.anim.slide_out_left - popExit = R.anim.slide_out_left - } - } - ) - } - } + ) { source?.baseUrl?.let { uriHandler.openUri(it) } } ) } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt b/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt index c9c69c9bb..450c09db4 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt @@ -16,6 +16,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.platform.UriHandler import androidx.navigation.NavController import androidx.navigation.NavHostController import com.programmersbox.extensionloader.SourceRepository @@ -30,6 +32,7 @@ import com.programmersbox.models.ApiService import com.programmersbox.models.ItemModel import com.programmersbox.uiviews.CurrentSourceRepository import com.programmersbox.uiviews.GenericInfo +import com.programmersbox.uiviews.R import org.koin.androidx.compose.KoinAndroidContext import org.koin.compose.koinInject import org.koin.core.annotation.KoinExperimentalAPI @@ -84,6 +87,8 @@ fun OtakuMaterialTheme( genericInfo: GenericInfo, content: @Composable () -> Unit, ) { + val defaultUriHandler = LocalUriHandler.current + KoinAndroidContext { val context = LocalContext.current val darkTheme = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES || @@ -126,7 +131,26 @@ fun OtakuMaterialTheme( LocalCustomListDao provides remember { ListDatabase.getInstance(context).listDao() }, LocalSystemDateTimeFormat provides remember { context.getSystemDateTimeFormat() }, LocalSourcesRepository provides koinInject(), - LocalCurrentSource provides koinInject() + LocalCurrentSource provides koinInject(), + LocalUriHandler provides remember { + object : UriHandler { + override fun openUri(uri: String) { + runCatching { + navController.navigateChromeCustomTabs( + uri, + { + anim { + enter = R.anim.slide_in_right + popEnter = R.anim.slide_in_right + exit = R.anim.slide_out_left + popExit = R.anim.slide_out_left + } + } + ) + }.onFailure { defaultUriHandler.openUri(uri) } + } + } + } ) { content() } } } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/BottomSheetDeleteScaffold.kt b/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/BottomSheetDeleteScaffold.kt index 7aa5f7a50..399d95c75 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/BottomSheetDeleteScaffold.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/BottomSheetDeleteScaffold.kt @@ -33,7 +33,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedCard import androidx.compose.material3.Scaffold import androidx.compose.material3.SheetValue -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBarDefaults @@ -280,10 +280,10 @@ private fun DeleteItemView( } ) - SwipeToDismiss( + SwipeToDismissBox( state = dismissState, - background = { - val direction = dismissState.dismissDirection ?: return@SwipeToDismiss + backgroundContent = { + val direction = dismissState.dismissDirection ?: return@SwipeToDismissBox val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -311,7 +311,7 @@ private fun DeleteItemView( ) } }, - dismissContent = { + content = { val transition = updateTransition(targetState = isInList, label = "") val outlineColor = MaterialTheme.colorScheme.outline OutlinedCard( diff --git a/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt b/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt index b9d95053e..01ee167d8 100644 --- a/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt +++ b/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt @@ -1,3 +1,5 @@ +@file:Suppress("INLINE_FROM_HIGHER_PLATFORM") + package com.programmersbox.animeworld.videos import android.Manifest @@ -42,7 +44,7 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.SheetValue import androidx.compose.material3.Surface -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.rememberBottomSheetScaffoldState @@ -381,10 +383,10 @@ private fun VideoContentView( } ) - SwipeToDismiss( + SwipeToDismissBox( state = dismissState, - background = { - val direction = dismissState.dismissDirection ?: return@SwipeToDismiss + backgroundContent = { + val direction = dismissState.dismissDirection ?: return@SwipeToDismissBox val color by animateColorAsState( when (dismissState.targetValue) { DismissValue.Default -> Color.Transparent @@ -416,7 +418,7 @@ private fun VideoContentView( ) } }, - dismissContent = { + content = { ElevatedCard( modifier = Modifier .fillMaxSize() diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt index 02ac9b4ee..22b917d4b 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt @@ -36,7 +36,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.ListItem import androidx.compose.material3.Surface -import androidx.compose.material3.SwipeToDismiss +import androidx.compose.material3.SwipeToDismissBox import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBarDefaults @@ -279,11 +279,11 @@ private fun ChapterItem(file: Map.Entry Color.Transparent @@ -308,7 +308,7 @@ private fun ChapterItem(file: Map.Entry= lastChapter) null else DismissDirection.StartToEnd ), - background = { - val direction = dismissState.dismissDirection ?: return@SwipeToDismiss + backgroundContent = { + val direction = dismissState.dismissDirection ?: return@SwipeToDismissBox val scale by animateFloatAsState(if (dismissState.targetValue == DismissValue.Default) 0.75f else 1f, label = "") val alignment = when (direction) { @@ -872,7 +872,7 @@ fun ChangeChapterSwipe( ) } }, - dismissContent = { + content = { OutlinedCard( modifier = Modifier .fillMaxWidth()