mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Add selection count indicator in top bar and refactor
This commit is contained in:
parent
1a86883ec0
commit
ca30bf18bf
2 changed files with 56 additions and 32 deletions
|
|
@ -2,8 +2,12 @@ package fr.free.nrw.commons.customselector.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowLeft
|
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowLeft
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
|
@ -14,6 +18,8 @@ import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
|
import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.PreviewLightDark
|
import androidx.compose.ui.tooling.preview.PreviewLightDark
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -28,7 +34,9 @@ fun CustomSelectorTopBar(
|
||||||
onNavigateBack: ()-> Unit,
|
onNavigateBack: ()-> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
secondaryText: String? = null,
|
secondaryText: String? = null,
|
||||||
|
selectionCount: Int = 0,
|
||||||
showNavigationIcon: Boolean = true,
|
showNavigationIcon: Boolean = true,
|
||||||
|
showSelectionCount: Boolean = false,
|
||||||
showAlertIcon: Boolean = false,
|
showAlertIcon: Boolean = false,
|
||||||
onAlertAction: ()-> Unit = { },
|
onAlertAction: ()-> Unit = { },
|
||||||
) {
|
) {
|
||||||
|
|
@ -38,7 +46,6 @@ fun CustomSelectorTopBar(
|
||||||
Text(
|
Text(
|
||||||
text = primaryText,
|
text = primaryText,
|
||||||
style = MaterialTheme.typography.titleMedium.copy(fontSize = 18.sp),
|
style = MaterialTheme.typography.titleMedium.copy(fontSize = 18.sp),
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
|
@ -73,6 +80,23 @@ fun CustomSelectorTopBar(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(showSelectionCount) {
|
||||||
|
ElevatedCard(
|
||||||
|
colors = CardDefaults.elevatedCardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary
|
||||||
|
),
|
||||||
|
shape = CircleShape,
|
||||||
|
modifier = Modifier.semantics { contentDescription = "$selectionCount Selected" }
|
||||||
|
.padding(end = 8.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "$selectionCount",
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
style = MaterialTheme.typography.labelMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +110,8 @@ private fun CustomSelectorTopBarPreview() {
|
||||||
primaryText = "My Folder",
|
primaryText = "My Folder",
|
||||||
secondaryText = "10 images",
|
secondaryText = "10 images",
|
||||||
onNavigateBack = { },
|
onNavigateBack = { },
|
||||||
showAlertIcon = true
|
showAlertIcon = true,
|
||||||
|
selectionCount = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,37 +21,34 @@ import fr.free.nrw.commons.ui.theme.CommonsTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PartialStorageAccessDialog(
|
fun PartialStorageAccessDialog(
|
||||||
isVisible: Boolean,
|
onManageAction: () -> Unit,
|
||||||
onManage: ()-> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
if(isVisible) {
|
Card(
|
||||||
Card(
|
modifier = modifier,
|
||||||
modifier = modifier,
|
colors = CardDefaults.cardColors(
|
||||||
colors = CardDefaults.cardColors(
|
containerColor = MaterialTheme.colorScheme.secondaryContainer
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer
|
),
|
||||||
),
|
shape = RoundedCornerShape(12.dp)
|
||||||
shape = RoundedCornerShape(12.dp)
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(vertical = 8.dp, horizontal = 16.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Row(
|
Text(
|
||||||
modifier = Modifier
|
text = "You've given access to a selected number of photos",
|
||||||
.padding(vertical = 8.dp, horizontal = 16.dp)
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
.fillMaxWidth(),
|
modifier = Modifier.weight(1f)
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
)
|
||||||
verticalAlignment = Alignment.CenterVertically
|
Button(
|
||||||
|
onClick = onManageAction,
|
||||||
|
shape = RoundedCornerShape(8.dp),
|
||||||
|
contentPadding = PaddingValues(horizontal = 16.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(text = "Manage", style = MaterialTheme.typography.labelMedium)
|
||||||
text = "You've given access to a selected number of photos",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
Button(
|
|
||||||
onClick = onManage,
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
contentPadding = PaddingValues(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
Text(text = "Manage", style = MaterialTheme.typography.labelMedium)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,9 +59,11 @@ fun PartialStorageAccessDialog(
|
||||||
fun PartialStorageAccessIndicatorPreview() {
|
fun PartialStorageAccessIndicatorPreview() {
|
||||||
CommonsTheme {
|
CommonsTheme {
|
||||||
Surface {
|
Surface {
|
||||||
PartialStorageAccessDialog(isVisible = true, onManage = {}, modifier = Modifier
|
PartialStorageAccessDialog(
|
||||||
.padding(8.dp)
|
onManageAction = {},
|
||||||
.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.padding(8.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue