Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepurple13 committed Nov 16, 2023
1 parent 0906802 commit 9797670
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -121,6 +121,7 @@ internal fun DetailActions(
dao: ItemDao,
onReverseChaptersClick: () -> Unit,
) {
val uriHandler = LocalUriHandler.current
var showLists by remember { mutableStateOf(false) }

if (showLists) {
Expand Down Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -272,7 +272,7 @@ private fun HistoryItem(
)
}
},
dismissContent = {
content = {
var showLoadingDialog by remember { mutableStateOf(false) }

LoadingDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -649,7 +649,7 @@ private fun CustomItem(
)
}
},
dismissContent = {
content = {
ElevatedCard(
onClick = {
sourceRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -592,7 +592,7 @@ private fun DateSort(
)
}
},
dismissContent = {
content = {
M3CoverCard(
imageUrl = i.imageUrl.orEmpty(),
name = i.notiTitle,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -721,7 +721,7 @@ private fun NotificationItem(
)
}
},
dismissContent = {
content = {
ElevatedCard(
onClick = {
toSource(item.source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -137,7 +137,8 @@ fun SettingScreen(
}
)
},
contentWindowInsets = ScaffoldDefaults.contentWindowInsets
contentWindowInsets = ScaffoldDefaults.contentWindowInsets,
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
) { p ->
Column(
modifier = Modifier
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) } }
)
}

Expand Down
26 changes: 25 additions & 1 deletion UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -280,10 +280,10 @@ private fun <T> 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
Expand Down Expand Up @@ -311,7 +311,7 @@ private fun <T> DeleteItemView(
)
}
},
dismissContent = {
content = {
val transition = updateTransition(targetState = isInList, label = "")
val outlineColor = MaterialTheme.colorScheme.outline
OutlinedCard(
Expand Down
Loading

0 comments on commit 9797670

Please sign in to comment.