This repository was archived by the owner on Jul 16, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork10
Compose migration#568
Draft
Goooler wants to merge27 commits intotrunkChoose a base branch fromcompose-migration
base:trunk
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
Show all changes
27 commits Select commitHold shift + click to select a range
1039f2b Add M3 theme
Gooolerb5ca9de Add DemoScaffold
Goooler659f5e5 Move VM initialization into Composable
Gooolerfef5663 Merge remote-tracking branch 'origin/trunk' into compose-migration
Goooler28e1805 Merge remote-tracking branch 'origin/trunk' into compose-migration
Goooler050fe24 Fix detekt
Goooler196cb36 Use modifier param
Gooolerab543b0 Add PaddingValues.copy
Goooler9facbb9 Migrate PullToRefresh to M3
Goooler9ff9ddb Cleanup asStateFlow
Gooolere478df0 Merge remote-tracking branch 'origin/trunk' into compose-migration
Goooler2fcaafe Merge branch 'refs/heads/trunk' into compose-migration
Gooolerca6d70c Launcher DemoApp by default
Gooolerb9c4622 Exported
Gooolerc49d772 List and anim
Goooler992489f Preview
Goooler8739913 Theme
Goooler5df5c37 Fix detekt
Goooler6374ea6 Adjust
Goooler944518d Merge remote-tracking branch 'refs/remotes/origin/trunk' into compose…
Goooler8ab111c Merge remote-tracking branch 'refs/remotes/origin/trunk' into compose…
Gooolere054f0e Merge remote-tracking branch 'refs/remotes/origin/trunk' into compose…
Goooler6f9a8a0 Merge branch 'refs/heads/trunk' into compose-migration
Gooolerc9da8ca Merge remote-tracking branch 'refs/remotes/origin/trunk' into compose…
Goooler76502c1 Merge branch 'refs/heads/trunk' into compose-migration
Goooler8546123 Merge branch 'trunk' into compose-migration
Goooler8d10b1c Merge branch 'refs/heads/trunk' into compose-migration
GooolerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 3 additions & 1 deletionbiz/detail/src/main/AndroidManifest.xml
This file contains hidden or 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
10 changes: 10 additions & 0 deletionsbiz/detail/src/main/kotlin/io/goooler/demoapp/detail/ui/Color.kt
This file contains hidden or 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,10 @@ | ||
| @file:Suppress("MagicNumber") | ||
| package io.goooler.demoapp.detail.ui | ||
| import androidx.compose.ui.graphics.Color | ||
| val Navy = Color(0xFF073042) | ||
| val Blue = Color(0xFF4285F4) | ||
| val LightBlue = Color(0xFFD7EFFE) | ||
| val Chartreuse = Color(0xFFEFF7CF) |
131 changes: 0 additions & 131 deletionsbiz/detail/src/main/kotlin/io/goooler/demoapp/detail/ui/DetailPage.kt
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
185 changes: 185 additions & 0 deletionsbiz/detail/src/main/kotlin/io/goooler/demoapp/detail/ui/DetailScreen.kt
This file contains hidden or 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,185 @@ | ||
| package io.goooler.demoapp.detail.ui | ||
| import androidx.compose.animation.animateContentSize | ||
| import androidx.compose.animation.core.Spring | ||
| import androidx.compose.animation.core.spring | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.filled.Share | ||
| import androidx.compose.material.icons.filled.Star | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.Card | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.pulltorefresh.PullToRefreshContainer | ||
| import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.collectAsState | ||
| 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.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.lifecycle.viewmodel.compose.viewModel | ||
| import io.goooler.demoapp.common.util.getQuantityString | ||
| import io.goooler.demoapp.common.util.showToast | ||
| import io.goooler.demoapp.detail.R | ||
| import io.goooler.demoapp.detail.model.RepoDetailModel | ||
| import io.goooler.demoapp.detail.vm.DetailViewModel | ||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun DetailScreenWithSwipeRefresh( | ||
| modifier: Modifier = Modifier, | ||
| vm: DetailViewModel = viewModel(), | ||
| ) { | ||
| val model by vm.repoDetailModel.collectAsState() | ||
| val isRefreshing by vm.isRefreshing.collectAsState() | ||
| val refreshState = rememberPullToRefreshState() | ||
| if (refreshState.isRefreshing) { | ||
| LaunchedEffect(true) { | ||
| // fetch something | ||
| vm.refresh() | ||
| if (!isRefreshing) { | ||
| refreshState.endRefresh() | ||
| } | ||
| } | ||
| } | ||
| Surface( | ||
| color = MaterialTheme.colorScheme.surface, | ||
| modifier = modifier.padding(horizontal = 10.dp), | ||
| ) { | ||
| Box(Modifier.nestedScroll(refreshState.nestedScrollConnection)) { | ||
| DetailList(model, vm::fork) | ||
| PullToRefreshContainer( | ||
| modifier = Modifier.align(Alignment.TopCenter), | ||
| state = refreshState, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| @Composable | ||
| private fun DetailList( | ||
| model: RepoDetailModel, | ||
| onForkClick: () -> Unit = {}, | ||
| ) { | ||
| LazyColumn { | ||
| @Suppress("MagicNumber") | ||
| val models = List(10) { model } | ||
| items(models) { model -> | ||
| DetailCard(model = model, onForkClick = onForkClick) | ||
| } | ||
| } | ||
| } | ||
| @Composable | ||
| private fun DetailCard( | ||
| model: RepoDetailModel, | ||
| modifier: Modifier = Modifier, | ||
| onForkClick: () -> Unit = {}, | ||
| ) { | ||
| var isDescExpanded by rememberSaveable { mutableStateOf(false) } | ||
| Card( | ||
| modifier = modifier.padding(8.dp), | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .padding(12.dp) | ||
| .animateContentSize( | ||
| animationSpec = spring( | ||
| dampingRatio = Spring.DampingRatioMediumBouncy, | ||
| stiffness = Spring.StiffnessLow, | ||
| ), | ||
| ), | ||
| ) { | ||
| Text( | ||
| text = model.fullName, | ||
| style = MaterialTheme.typography.titleLarge.copy( | ||
| fontWeight = FontWeight.SemiBold, | ||
| ), | ||
| maxLines = 1, | ||
| ) | ||
| Spacer(modifier = Modifier.height(5.dp)) | ||
| Text( | ||
| text = model.description, | ||
| style = MaterialTheme.typography.bodyLarge, | ||
| maxLines = if (isDescExpanded) Int.MAX_VALUE else 1, | ||
| modifier = Modifier.clickable { | ||
| isDescExpanded = !isDescExpanded | ||
| }, | ||
| ) | ||
| Spacer(modifier = Modifier.height(5.dp)) | ||
| Row { | ||
| Button( | ||
| modifier = Modifier.weight(1f), | ||
| onClick = { | ||
| R.plurals.detail_star_count_tip.getQuantityString(model.starsCount)?.showToast() | ||
| }, | ||
| ) { | ||
| Icon( | ||
| Icons.Filled.Star, | ||
| contentDescription = "Star", | ||
| modifier = Modifier.size(ButtonDefaults.IconSize), | ||
| ) | ||
| Spacer(Modifier.size(ButtonDefaults.IconSpacing)) | ||
| Text(model.starsCount.toString()) | ||
| } | ||
| Spacer(modifier = Modifier.width(20.dp)) | ||
| Button( | ||
| modifier = Modifier.weight(1f), | ||
| onClick = onForkClick, | ||
| ) { | ||
| Icon( | ||
| Icons.Filled.Share, | ||
| contentDescription = "Fork", | ||
| modifier = Modifier.size(ButtonDefaults.IconSize), | ||
| ) | ||
| Spacer(Modifier.size(ButtonDefaults.IconSpacing)) | ||
| Text(model.forksCount.toString()) | ||
| } | ||
| } | ||
| Spacer(modifier = Modifier.height(5.dp)) | ||
| } | ||
| } | ||
| } | ||
| @PreviewDemo | ||
| @Composable | ||
| private fun DetailListPreview() { | ||
| @Suppress("MagicNumber") | ||
| val model = RepoDetailModel( | ||
| "Compose/Demo", | ||
| "Jetpack Compose is Android’s modern toolkit for building native UI. " + | ||
| "It simplifies and accelerates UI development on Android. " + | ||
| "Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.", | ||
| "Apache", | ||
| 99, | ||
| 1, | ||
| 2, | ||
| ) | ||
| DetailList(model) | ||
| } |
18 changes: 9 additions & 9 deletionsbiz/detail/src/main/kotlin/io/goooler/demoapp/detail/ui/RepoDetailActivity.kt
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.