-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(speakers): support adaptive layout.
- Loading branch information
1 parent
4b79c16
commit abf6da3
Showing
8 changed files
with
115 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...src/main/kotlin/org/gdglille/devfest/android/theme/m3/speakers/feature/SpeakerAdaptive.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.gdglille.devfest.android.theme.m3.speakers.feature | ||
|
||
import androidx.compose.material3.adaptive.AnimatedPane | ||
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi | ||
import androidx.compose.material3.adaptive.ListDetailPaneScaffold | ||
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole | ||
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldNavigator | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
|
||
@OptIn(ExperimentalMaterial3AdaptiveApi::class) | ||
@Composable | ||
fun SpeakerAdaptive( | ||
showBackInDetail: Boolean, | ||
onTalkClicked: (id: String) -> Unit, | ||
onLinkClicked: (url: String) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
val navigator = rememberListDetailPaneScaffoldNavigator() | ||
var selectedItem: String? by rememberSaveable { mutableStateOf(null) } | ||
ListDetailPaneScaffold( | ||
scaffoldState = navigator.scaffoldState, | ||
modifier = modifier, | ||
listPane = { | ||
AnimatedPane(Modifier) { | ||
SpeakersListCompactVM( | ||
onSpeakerClicked = { | ||
selectedItem = it | ||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) | ||
} | ||
) | ||
} | ||
}, | ||
detailPane = { | ||
AnimatedPane(modifier = Modifier) { | ||
selectedItem?.let { item -> | ||
SpeakerDetailOrientableVM( | ||
speakerId = item, | ||
onTalkClicked = onTalkClicked, | ||
onLinkClicked = onLinkClicked, | ||
navigationIcon = if (showBackInDetail) { | ||
@Composable { Back { | ||
if (navigator.canNavigateBack()) { | ||
navigator.navigateBack() | ||
} | ||
} } | ||
} else null | ||
) | ||
} | ||
} | ||
} | ||
) | ||
} |
69 changes: 31 additions & 38 deletions
69
...otlin/org/gdglille/devfest/android/theme/m3/speakers/feature/SpeakerDetailOrientableVM.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,58 @@ | ||
package org.gdglille.devfest.android.theme.m3.speakers.feature | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.material3.rememberTopAppBarState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import org.gdglille.devfest.android.theme.m3.speakers.screens.SpeakerDetailOrientable | ||
import org.gdglille.devfest.android.theme.m3.style.R | ||
import org.gdglille.devfest.android.theme.m3.style.appbars.TopAppBar | ||
import org.gdglille.devfest.android.theme.m3.style.Scaffold | ||
import org.gdglille.devfest.android.theme.m3.style.appbars.AppBarIcons | ||
import org.koin.androidx.compose.koinViewModel | ||
import org.koin.core.parameter.parametersOf | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun SpeakerDetailOrientableVM( | ||
speakerId: String, | ||
onTalkClicked: (id: String) -> Unit, | ||
onLinkClicked: (url: String) -> Unit, | ||
onBackClicked: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
viewModel: SpeakerDetailViewModel = koinViewModel(parameters = { parametersOf(speakerId) }) | ||
navigationIcon: @Composable (AppBarIcons.() -> Unit)? = null, | ||
isLandscape: Boolean = false, | ||
viewModel: SpeakerDetailViewModel = koinViewModel(key = speakerId, parameters = { parametersOf(speakerId) }) | ||
) { | ||
val context = LocalContext.current | ||
val uiState = viewModel.uiState.collectAsState() | ||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState()) | ||
Scaffold( | ||
modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection), | ||
topBar = { | ||
TopAppBar( | ||
title = stringResource(id = R.string.screen_speaker_detail), | ||
navigationIcon = { Back(onClick = onBackClicked) }, | ||
scrollBehavior = scrollBehavior | ||
title = stringResource(id = R.string.screen_speaker_detail), | ||
navigationIcon = navigationIcon, | ||
modifier = modifier | ||
) { | ||
when (uiState.value) { | ||
is SpeakerUiState.Loading -> SpeakerDetailOrientable( | ||
speaker = (uiState.value as SpeakerUiState.Loading).speaker, | ||
contentPadding = it, | ||
onTalkClicked = {}, | ||
onFavoriteClicked = {}, | ||
onLinkClicked = {}, | ||
isLandscape = isLandscape | ||
) | ||
}, | ||
content = { | ||
when (uiState.value) { | ||
is SpeakerUiState.Loading -> SpeakerDetailOrientable( | ||
speaker = (uiState.value as SpeakerUiState.Loading).speaker, | ||
contentPadding = it, | ||
onTalkClicked = {}, | ||
onFavoriteClicked = {}, | ||
onLinkClicked = {} | ||
) | ||
|
||
is SpeakerUiState.Failure -> Text(text = stringResource(id = R.string.text_error)) | ||
is SpeakerUiState.Success -> SpeakerDetailOrientable( | ||
speaker = (uiState.value as SpeakerUiState.Success).speaker, | ||
contentPadding = it, | ||
onTalkClicked = onTalkClicked, | ||
onFavoriteClicked = { | ||
viewModel.markAsFavorite(context, it) | ||
}, | ||
onLinkClicked = onLinkClicked, | ||
) | ||
} | ||
is SpeakerUiState.Failure -> Text(text = stringResource(id = R.string.text_error)) | ||
is SpeakerUiState.Success -> SpeakerDetailOrientable( | ||
speaker = (uiState.value as SpeakerUiState.Success).speaker, | ||
contentPadding = it, | ||
onTalkClicked = onTalkClicked, | ||
onFavoriteClicked = { | ||
viewModel.markAsFavorite(context, it) | ||
}, | ||
onLinkClicked = onLinkClicked, | ||
isLandscape = isLandscape | ||
) | ||
} | ||
) | ||
} | ||
} |
26 changes: 8 additions & 18 deletions
26
...in/kotlin/org/gdglille/devfest/android/theme/m3/speakers/feature/SpeakersListCompactVM.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters