Skip to content

Commit

Permalink
Found a way to show full list with the ListDetailPaneScaffold, so ins…
Browse files Browse the repository at this point in the history
…tead of opening the specific screens, for this test, the new screen will always be opened
  • Loading branch information
jakepurple13 committed Nov 17, 2023
1 parent ab8265b commit f6aeb5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 } }
)
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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() }
)
}

Expand Down Expand Up @@ -415,7 +431,7 @@ fun DetailPart(
val customItem = viewModel.customItem
val snackbarHostState = remember { SnackbarHostState() }

val logoDrawable = koinInject<AppLogo>().logo
val logoDrawable = koinInject<AppLogo>()

val pickDocumentLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.CreateDocument("application/json")
Expand Down Expand Up @@ -511,7 +527,7 @@ fun DetailPart(
list = viewModel.listBySource,
onRemove = viewModel::removeItems,
onDismiss = { showDeleteModal = false },
drawable = logoDrawable
drawable = logoDrawable.logo
)
}

Expand All @@ -522,15 +538,14 @@ fun DetailPart(
bannerContent = {
ListItem(
leadingContent = {
val logo = koinInject<AppLogo>().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
Expand Down Expand Up @@ -704,7 +719,7 @@ fun DetailPart(
CustomItemVertical(
items = item.value,
title = item.key,
logo = logoDrawable,
logo = logoDrawable.logo,
showLoadingDialog = { showLoadingDialog = it },
onError = {
scope.launch {
Expand Down

0 comments on commit f6aeb5a

Please sign in to comment.