From f6aeb5abb800439e35f75aef873a3bf22b008118 Mon Sep 17 00:00:00 2001 From: Jacob Rein Date: Fri, 17 Nov 2023 07:08:46 -0500 Subject: [PATCH] Found a way to show full list with the ListDetailPaneScaffold, so instead of opening the specific screens, for this test, the new screen will always be opened --- .../uiviews/BaseMainActivity.kt | 15 +--- .../uiviews/lists/OtakuListStuff.kt | 85 +++++++++++-------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt index 73700d325..216fc6176 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt @@ -62,7 +62,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.ExperimentalComposeUiApi @@ -160,8 +159,6 @@ abstract class BaseMainActivity : AppCompatActivity() { private var notificationCount by mutableIntStateOf(0) - private var showListDetail by mutableStateOf(true) - @OptIn( ExperimentalMaterial3Api::class, ExperimentalMaterial3WindowSizeClassApi::class @@ -366,7 +363,7 @@ abstract class BaseMainActivity : AppCompatActivity() { NavigationRailItem( imageVector = Icons.AutoMirrored.Default.List, label = stringResource(R.string.custom_lists_title), - screen = if (showListDetail) Screen.CustomListStuffScreen else Screen.CustomListScreen, + screen = Screen.CustomListStuffScreen, currentDestination = currentDestination, navController = navController, customRoute = "_home" @@ -503,11 +500,7 @@ abstract class BaseMainActivity : AppCompatActivity() { favoritesClick = { navController.navigate(Screen.FavoriteScreen.route) { launchSingleTop = true } }, historyClick = { navController.navigate(Screen.HistoryScreen.route) { launchSingleTop = true } }, globalSearchClick = { navController.navigate(Screen.GlobalSearchScreen.route) { launchSingleTop = true } }, - listClick = { - navController.navigate( - if (showListDetail) Screen.CustomListStuffScreen.route else Screen.CustomListScreen.route - ) { launchSingleTop = true } - }, + listClick = { navController.navigate(Screen.CustomListStuffScreen.route) { launchSingleTop = true } }, debugMenuClick = { navController.navigate(Screen.DebugScreen.route) { launchSingleTop = true } } ) } @@ -719,10 +712,6 @@ abstract class BaseMainActivity : AppCompatActivity() { .getAllNotificationCount() .onEach { notificationCount = it } .launchIn(lifecycleScope) - - settingsHandling.showListDetail - .onEach { showListDetail = it } - .launchIn(lifecycleScope) } private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: Screen) = this?.hierarchy?.any { diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListStuff.kt b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListStuff.kt index 48b1d909d..3487a8d51 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListStuff.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListStuff.kt @@ -92,6 +92,7 @@ import androidx.compose.material3.adaptive.ListDetailPaneScaffold import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole import androidx.compose.material3.adaptive.PaneAdaptedValue import androidx.compose.material3.adaptive.PaneScaffoldDirective +import androidx.compose.material3.adaptive.ThreePaneScaffoldScope import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldState @@ -117,6 +118,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.lifecycle.ViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import coil.compose.rememberAsyncImagePainter @@ -139,6 +141,7 @@ import com.programmersbox.uiviews.utils.InsetSmallTopAppBar import com.programmersbox.uiviews.utils.LoadingDialog import com.programmersbox.uiviews.utils.LocalCustomListDao import com.programmersbox.uiviews.utils.LocalNavController +import com.programmersbox.uiviews.utils.LocalSettingsHandling import com.programmersbox.uiviews.utils.LocalSourcesRepository import com.programmersbox.uiviews.utils.LocalSystemDateTimeFormat import com.programmersbox.uiviews.utils.M3CoverCard @@ -170,54 +173,67 @@ import java.io.FileOutputStream import java.io.IOException //TODO: Rename this to something that makes sense +// if I like it, modify the other files to accept what is needed for reusability @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable fun OtakuListStuff( listDao: ListDao = LocalCustomListDao.current, viewModel: OtakuListStuffViewModel = viewModel { OtakuListStuffViewModel(listDao) }, ) { + val showListDetail by LocalSettingsHandling.current + .showListDetail + .collectAsStateWithLifecycle(true) + val state = rememberListDetailPaneScaffoldState( scaffoldDirective = calculateStandardPaneScaffoldDirective(currentWindowAdaptiveInfo()) ) + val details: @Composable ThreePaneScaffoldScope.() -> Unit = { + AnimatedPane(modifier = Modifier) { pane -> + AnimatedContent( + targetState = viewModel.customItem, + label = "", + transitionSpec = { + (slideInHorizontally { -it } + fadeIn()) togetherWith (fadeOut() + slideOutHorizontally { -it }) + } + ) { targetState -> + if (targetState != null) { + DetailPart( + viewModel = viewModel, + navigateBack = { + viewModel.customItem = null + state.navigateBack() + }, + isHorizontal = pane == PaneAdaptedValue.Expanded + ) + BackHandler { + viewModel.customItem = null + state.navigateBack() + } + } else { + NoDetailSelected() + } + } + } + } + ListDetailPaneScaffold( scaffoldState = state, listPane = { AnimatedPane(modifier = Modifier.fillMaxSize()) { ListPart( viewModel = viewModel, - navigateDetail = { state.navigateTo(ListDetailPaneScaffoldRole.Detail) } + navigateDetail = { + if (showListDetail) + state.navigateTo(ListDetailPaneScaffoldRole.Detail) + else + state.navigateTo(ListDetailPaneScaffoldRole.Extra) + } ) } }, - detailPane = { - AnimatedPane(modifier = Modifier) { pane -> - AnimatedContent( - targetState = viewModel.customItem, - label = "", - transitionSpec = { - (slideInHorizontally { -it } + fadeIn()) togetherWith (fadeOut() + slideOutHorizontally { -it }) - } - ) { targetState -> - if (targetState != null) { - DetailPart( - viewModel = viewModel, - navigateBack = { - viewModel.customItem = null - state.navigateBack() - }, - isHorizontal = pane == PaneAdaptedValue.Expanded - ) - BackHandler { - viewModel.customItem = null - state.navigateBack() - } - } else { - NoDetailSelected() - } - } - } - } + detailPane = { if (showListDetail) details() }, + extraPane = { details() } ) } @@ -415,7 +431,7 @@ fun DetailPart( val customItem = viewModel.customItem val snackbarHostState = remember { SnackbarHostState() } - val logoDrawable = koinInject().logo + val logoDrawable = koinInject() val pickDocumentLauncher = rememberLauncherForActivityResult( ActivityResultContracts.CreateDocument("application/json") @@ -511,7 +527,7 @@ fun DetailPart( list = viewModel.listBySource, onRemove = viewModel::removeItems, onDismiss = { showDeleteModal = false }, - drawable = logoDrawable + drawable = logoDrawable.logo ) } @@ -522,15 +538,14 @@ fun DetailPart( bannerContent = { ListItem( leadingContent = { - val logo = koinInject().logoId CoilGradientImage( model = rememberAsyncImagePainter( model = ImageRequest.Builder(LocalContext.current) .data(it?.imageUrl) .lifecycle(LocalLifecycleOwner.current) .crossfade(true) - .placeholder(logo) - .error(logo) + .placeholder(logoDrawable.logoId) + .error(logoDrawable.logoId) .build() ), modifier = Modifier @@ -704,7 +719,7 @@ fun DetailPart( CustomItemVertical( items = item.value, title = item.key, - logo = logoDrawable, + logo = logoDrawable.logo, showLoadingDialog = { showLoadingDialog = it }, onError = { scope.launch {