-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Jetpack Compose] Migrate offline area list to Compose Lazy Column (#…
…2698) * Add AppTheme to preview of SyncListItem * Create compose view for offline area list item * Replace recycler view with lazy column * handle clicks * Replace toast with navigation * Convert OfflineAreaListItemViewModel to data class OfflineAreaDetails * Remove unused recycler view related classes * Reformat code * Simplify OfflineAreaDetails class * Fix import order * Add content description * Remove unused style * Update unit tests * Refactor tests * Apply suggestions
- Loading branch information
1 parent
bb24e59
commit 4434801
Showing
11 changed files
with
170 additions
and
254 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
48 changes: 0 additions & 48 deletions
48
ground/src/main/java/com/google/android/ground/ui/offlineareas/OfflineAreaListAdapter.kt
This file was deleted.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
ground/src/main/java/com/google/android/ground/ui/offlineareas/OfflineAreaListItem.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,110 @@ | ||
/* | ||
* Copyright 2024 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 com.google.android.ground.ui.offlineareas | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.res.vectorResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.google.android.ground.R | ||
import com.google.android.ground.ui.theme.AppTheme | ||
|
||
@Composable | ||
fun OfflineAreaListItem( | ||
modifier: Modifier = Modifier, | ||
offlineAreaDetails: OfflineAreaDetails, | ||
itemClicked: (areaId: String) -> Unit = {}, | ||
) { | ||
Column { | ||
Row( | ||
modifier = | ||
modifier | ||
.fillMaxWidth() | ||
.padding(start = 16.dp, top = 4.dp, end = 24.dp, bottom = 4.dp) | ||
.clickable { itemClicked(offlineAreaDetails.id) }, | ||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterHorizontally), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_offline_pin), | ||
contentDescription = stringResource(id = R.string.offline_area_list_item_icon), | ||
tint = MaterialTheme.colorScheme.primary, | ||
modifier = Modifier.size(24.dp), | ||
) | ||
|
||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalArrangement = Arrangement.spacedBy(0.dp, Alignment.CenterVertically), | ||
horizontalAlignment = Alignment.Start, | ||
) { | ||
Text( | ||
text = offlineAreaDetails.name, | ||
style = | ||
TextStyle( | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp, | ||
fontFamily = FontFamily(Font(R.font.text_500)), | ||
color = MaterialTheme.colorScheme.onSurface, | ||
), | ||
) | ||
|
||
Text( | ||
text = | ||
stringResource( | ||
id = R.string.offline_area_list_item_size_on_disk_mb, | ||
offlineAreaDetails.sizeOnDisk, | ||
), | ||
style = | ||
TextStyle( | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp, | ||
fontFamily = FontFamily(Font(R.font.text_500)), | ||
color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true, showSystemUi = true) | ||
fun PreviewOfflineAreaListItem() { | ||
AppTheme { | ||
OfflineAreaListItem( | ||
offlineAreaDetails = | ||
OfflineAreaDetails(id = "id", name = "Region name, Country", sizeOnDisk = "12 MB") | ||
) | ||
} | ||
} |
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
Oops, something went wrong.