-
Notifications
You must be signed in to change notification settings - Fork 145
Migrate home screen drawer to Compose #3554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
fddf518
chore: cleanup and tooling updates
gino-m 655775a
feat: add HomeDrawer component and ViewModel logic
gino-m d886942
chore: remove build output file
gino-m da3f1ae
Clean up PR
gino-m 4ea3ae3
refactor(home): migrate drawer to Compose and remove XML
gino-m 8748d6d
Restore deleted files
gino-m 6f4f819
fix(home): add system bars padding to drawer
gino-m c151380
refactor: clean up unused imports and reformat Compose state observat…
gino-m 6cf23b4
feat: move version text display from a clickable drawer item to a sta…
gino-m 8cd3af2
Update app/src/main/java/org/groundplatform/android/ui/home/HomeDrawe…
gino-m fa98dbf
Update app/src/main/java/org/groundplatform/android/ui/home/HomeDrawe…
gino-m 67c1ff6
Fix checkCode issues: Refactor HomeDrawer/HomeScreenFragment, fix for…
gino-m 98f7551
Refactor HomeDrawer and fix HomeScreenFragmentTest
gino-m 562c1ab
Fix checkCode issues and test regressions
gino-m 067e9a4
Fix ktfmt formatting issues
gino-m fc623c2
Refactor HomeDrawer to use HomeDrawerAction interface
gino-m 09cd0e5
Make user parameter non-null in HomeDrawer
gino-m a1d4e16
refactor: remove unnecessary comments from `openSignOutWarningDialog`…
gino-m ae5a8f9
Refactor HomeDrawerState into ViewModel
gino-m 5f7c642
test: assert build version string with BuildConfig.VERSION_NAME in Ho…
gino-m 96da66d
Replace Glide with Coil AsyncImage in HomeDrawer
gino-m 1bc876c
Fix duplicate coil-compose in libs.versions.toml
gino-m 5640cae
Address PR #3554 feedback
gino-m 8bef94a
Merge master into refactor/home-drawer and resolve conflicts
gino-m d2421c4
Merge branch 'master' into refactor/home-drawer
gino-m c9a5878
Fix UI Home Drawer regressions
gino-m e55ec8b
Fix UI Home Drawer dividers
gino-m 60fc4ef
Remove unused style
gino-m 9fbf637
Refactor version constant
gino-m a365307
Merge branch 'master' of https://github.com/google/ground-android int…
gino-m b8a3c66
Fix UI Home Drawer typography and padding
gino-m 14a663f
Fix exact CSS layout spacings and typography
gino-m 0924cff
Complete typography with explicit Google Sans and Manrope fonts per CSS
gino-m ea707c0
Suppress LongMethod detekt check on SurveySelector
gino-m e7a9587
Restore user photo size to 32dp
gino-m bdd1b36
Restore Font Weights for Survey Selector and Nav Items per original CSS
gino-m 1ddb7a3
Merge branch 'master' into refactor/home-drawer
gino-m 2ad1971
Use typography instead of font literals
gino-m 89162a6
Merge branch 'refactor/home-drawer' of https://github.com/google/grou…
gino-m d9702d5
Use existing Typography styles
gino-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
281 changes: 281 additions & 0 deletions
281
app/src/main/java/org/groundplatform/android/ui/home/HomeDrawer.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,281 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.ui.home | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.systemBarsPadding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.shape.CircleShape | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.automirrored.filled.ExitToApp | ||
| import androidx.compose.material.icons.filled.Build | ||
| import androidx.compose.material.icons.filled.Settings | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.NavigationDrawerItem | ||
| import androidx.compose.material3.NavigationDrawerItemDefaults | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.platform.testTag | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.unit.sp | ||
| import org.groundplatform.android.R | ||
| import org.groundplatform.android.model.Survey | ||
| import org.groundplatform.android.model.User | ||
| import org.groundplatform.android.ui.theme.AppTheme | ||
|
|
||
| @Composable | ||
| fun HomeDrawer( | ||
|
gino-m marked this conversation as resolved.
|
||
| user: User, | ||
| survey: Survey?, | ||
| versionText: String, | ||
| onAction: (HomeDrawerAction) -> Unit, | ||
| ) { | ||
| Column( | ||
| modifier = | ||
| Modifier.fillMaxWidth() | ||
| .background(MaterialTheme.colorScheme.surface) | ||
| .systemBarsPadding() | ||
| .verticalScroll(rememberScrollState()) | ||
| ) { | ||
| AppInfoHeader(user = user, onAction = onAction) | ||
| SurveySelector(survey = survey, onSwitchSurvey = { onAction(HomeDrawerAction.OnSwitchSurvey) }) | ||
| HorizontalDivider() | ||
| DrawerItems(onAction, versionText) | ||
| } | ||
| } | ||
|
|
||
| private val NAV_ITEMS = | ||
| listOf( | ||
| DrawerItem( | ||
| labelId = R.string.offline_map_imagery, | ||
| icon = IconSource.Drawable(R.drawable.ic_offline_pin), | ||
| action = HomeDrawerAction.OnNavigateToOfflineAreas, | ||
| ), | ||
| DrawerItem( | ||
| labelId = R.string.sync_status, | ||
| icon = IconSource.Drawable(R.drawable.ic_sync), | ||
| action = HomeDrawerAction.OnNavigateToSyncStatus, | ||
| ), | ||
| DrawerItem( | ||
| labelId = R.string.settings, | ||
| icon = IconSource.Vector(Icons.Default.Settings), | ||
| action = HomeDrawerAction.OnNavigateToSettings, | ||
| ), | ||
| DrawerItem( | ||
| labelId = R.string.about, | ||
| icon = IconSource.Drawable(R.drawable.info_outline), | ||
| action = HomeDrawerAction.OnNavigateToAbout, | ||
| ), | ||
| DrawerItem( | ||
| labelId = R.string.terms_of_service, | ||
| icon = IconSource.Drawable(R.drawable.feed), | ||
| action = HomeDrawerAction.OnNavigateToTerms, | ||
| ), | ||
| DrawerItem( | ||
| labelId = R.string.sign_out, | ||
| icon = IconSource.Vector(Icons.AutoMirrored.Filled.ExitToApp), | ||
| action = HomeDrawerAction.OnSignOut, | ||
| ), | ||
| ) | ||
|
|
||
| @Composable | ||
| private fun DrawerItems(onAction: (HomeDrawerAction) -> Unit, versionText: String) { | ||
| NAV_ITEMS.forEach { item -> DrawerNavigationItem(item, onAction) } | ||
|
|
||
| DrawerVersionFooter(versionText) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun DrawerNavigationItem(item: DrawerItem, onAction: (HomeDrawerAction) -> Unit) { | ||
| val label = stringResource(item.labelId) | ||
| NavigationDrawerItem( | ||
| label = { Text(label) }, | ||
| selected = false, | ||
| onClick = { onAction(item.action) }, | ||
| icon = { | ||
| val description = null | ||
| when (item.icon) { | ||
| is IconSource.Vector -> Icon(item.icon.imageVector, contentDescription = description) | ||
| is IconSource.Drawable -> | ||
| Icon(painterResource(item.icon.id), contentDescription = description) | ||
| } | ||
| }, | ||
| modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding).testTag(label), | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun DrawerVersionFooter(versionText: String) { | ||
| Row( | ||
| modifier = | ||
| Modifier.fillMaxWidth() | ||
| .padding(NavigationDrawerItemDefaults.ItemPadding) | ||
| .padding(start = 16.dp, end = 24.dp, top = 12.dp, bottom = 12.dp), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| Icon( | ||
| imageVector = Icons.Default.Build, | ||
| contentDescription = null, | ||
| tint = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| Spacer(Modifier.width(12.dp)) | ||
| Text( | ||
| text = versionText, | ||
| style = MaterialTheme.typography.labelLarge, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private data class DrawerItem( | ||
| @androidx.annotation.StringRes val labelId: Int, | ||
| val icon: IconSource, | ||
| val action: HomeDrawerAction, | ||
| ) | ||
|
|
||
| @Composable | ||
| private fun AppInfoHeader(user: User, onAction: (HomeDrawerAction) -> Unit) { | ||
| Column( | ||
| modifier = | ||
| Modifier.fillMaxWidth() | ||
| .background(MaterialTheme.colorScheme.surfaceVariant) | ||
| .padding(vertical = 24.dp, horizontal = 16.dp) | ||
| ) { | ||
| Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { | ||
| Image( | ||
| painter = painterResource(R.drawable.ground_logo), | ||
| contentDescription = null, | ||
| modifier = Modifier.size(24.dp), | ||
| ) | ||
| Spacer(Modifier.width(8.dp)) | ||
| Column(modifier = Modifier.weight(1f)) { | ||
| Text( | ||
| text = stringResource(R.string.app_name), | ||
| fontSize = 18.sp, | ||
| fontWeight = FontWeight.Medium, | ||
| ) | ||
| } | ||
| if (user.photoUrl != null) { | ||
| coil.compose.AsyncImage( | ||
| model = user.photoUrl, | ||
| contentDescription = null, | ||
| modifier = | ||
| Modifier.size(32.dp).clip(CircleShape).clickable { | ||
| onAction(HomeDrawerAction.OnUserDetails) | ||
| }, | ||
| contentScale = androidx.compose.ui.layout.ContentScale.Crop, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun SurveySelector(survey: Survey?, onSwitchSurvey: () -> Unit) { | ||
| Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) { | ||
| Row(verticalAlignment = Alignment.CenterVertically) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.ic_content_paste), | ||
| contentDescription = stringResource(R.string.current_survey), | ||
| modifier = Modifier.size(14.dp), | ||
| tint = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| Spacer(Modifier.width(4.dp)) | ||
| Text( | ||
| text = stringResource(R.string.current_survey), | ||
| style = MaterialTheme.typography.labelSmall, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| } | ||
| Spacer(Modifier.height(8.dp)) | ||
|
|
||
| if (survey == null) { | ||
| Text(stringResource(R.string.no_survey_selected)) | ||
| } else { | ||
| Text( | ||
| text = survey.title, | ||
| style = MaterialTheme.typography.titleMedium, | ||
| fontWeight = FontWeight.Bold, | ||
| maxLines = 3, | ||
| overflow = TextOverflow.Ellipsis, | ||
| ) | ||
| if (survey.description.isNotEmpty()) { | ||
| Text( | ||
| text = survey.description, | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| maxLines = 4, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.padding(top = 8.dp), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Spacer(Modifier.height(16.dp)) | ||
|
|
||
| Text( | ||
| text = stringResource(R.string.switch_survey), | ||
| style = MaterialTheme.typography.labelLarge, | ||
| color = MaterialTheme.colorScheme.primary, | ||
| fontWeight = FontWeight.Bold, | ||
| modifier = Modifier.padding(vertical = 8.dp).clickable(onClick = onSwitchSurvey), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private sealed interface IconSource { | ||
| data class Vector(val imageVector: androidx.compose.ui.graphics.vector.ImageVector) : IconSource | ||
|
|
||
| data class Drawable(@androidx.annotation.DrawableRes val id: Int) : IconSource | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun HomeDrawerPreview() { | ||
| val mockUser = | ||
| User(id = "1", email = "test@example.com", displayName = "Jane Doe", photoUrl = null) | ||
| val mockSurvey = | ||
| Survey( | ||
| id = "1", | ||
| title = "Tree Survey", | ||
| description = "A comprehensive survey for mapping urban tree canopy and assessing health.", | ||
| jobMap = emptyMap(), | ||
| generalAccess = org.groundplatform.android.proto.Survey.GeneralAccess.PUBLIC, | ||
| ) | ||
| AppTheme { | ||
| HomeDrawer(user = mockUser, survey = mockSurvey, versionText = "1.0.0-preview", onAction = {}) | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/groundplatform/android/ui/home/HomeDrawerAction.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,34 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.ui.home | ||
|
|
||
| sealed interface HomeDrawerAction { | ||
| data object OnSwitchSurvey : HomeDrawerAction | ||
|
|
||
| data object OnNavigateToOfflineAreas : HomeDrawerAction | ||
|
|
||
| data object OnNavigateToSyncStatus : HomeDrawerAction | ||
|
|
||
| data object OnNavigateToSettings : HomeDrawerAction | ||
|
|
||
| data object OnNavigateToAbout : HomeDrawerAction | ||
|
|
||
| data object OnNavigateToTerms : HomeDrawerAction | ||
|
|
||
| data object OnSignOut : HomeDrawerAction | ||
|
|
||
| data object OnUserDetails : HomeDrawerAction | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.