mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
add functionality for unselecting all pictures at once
This commit is contained in:
parent
130158f510
commit
03713dd62b
5 changed files with 37 additions and 9 deletions
|
|
@ -1,11 +1,15 @@
|
||||||
package fr.free.nrw.commons.customselector.ui.components
|
package fr.free.nrw.commons.customselector.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
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.material.icons.filled.Close
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.ElevatedCard
|
import androidx.compose.material3.ElevatedCard
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
|
@ -16,6 +20,7 @@ import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
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.contentDescription
|
||||||
|
|
@ -39,6 +44,7 @@ fun CustomSelectorTopBar(
|
||||||
showSelectionCount: Boolean = false,
|
showSelectionCount: Boolean = false,
|
||||||
showAlertIcon: Boolean = false,
|
showAlertIcon: Boolean = false,
|
||||||
onAlertAction: ()-> Unit = { },
|
onAlertAction: ()-> Unit = { },
|
||||||
|
onUnselectAllAction: ()-> Unit = { }
|
||||||
) {
|
) {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = {
|
||||||
|
|
@ -86,15 +92,27 @@ fun CustomSelectorTopBar(
|
||||||
colors = CardDefaults.elevatedCardColors(
|
colors = CardDefaults.elevatedCardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primary
|
containerColor = MaterialTheme.colorScheme.primary
|
||||||
),
|
),
|
||||||
|
elevation = CardDefaults.elevatedCardElevation(8.dp),
|
||||||
shape = CircleShape,
|
shape = CircleShape,
|
||||||
modifier = Modifier.semantics { contentDescription = "$selectionCount Selected" }
|
modifier = Modifier.semantics { contentDescription = "$selectionCount Selected" }
|
||||||
.padding(end = 8.dp)
|
.padding(end = 8.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Row(
|
||||||
text = "$selectionCount",
|
modifier = Modifier.padding(start = 16.dp, end = 8.dp),
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
style = MaterialTheme.typography.labelMedium
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
)
|
) {
|
||||||
|
Text(
|
||||||
|
text = "$selectionCount",
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Close,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.clickable { onUnselectAllAction() }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +129,8 @@ private fun CustomSelectorTopBarPreview() {
|
||||||
secondaryText = "10 images",
|
secondaryText = "10 images",
|
||||||
onNavigateBack = { },
|
onNavigateBack = { },
|
||||||
showAlertIcon = true,
|
showAlertIcon = true,
|
||||||
selectionCount = 1
|
selectionCount = 2,
|
||||||
|
showSelectionCount = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ interface CustomSelectorEvent {
|
||||||
data class OnFolderClick(val bucketId: Long): CustomSelectorEvent
|
data class OnFolderClick(val bucketId: Long): CustomSelectorEvent
|
||||||
data class OnImageSelection(val imageId: Long): CustomSelectorEvent
|
data class OnImageSelection(val imageId: Long): CustomSelectorEvent
|
||||||
data class OnDragImageSelection(val imageIds: Set<Long>): CustomSelectorEvent
|
data class OnDragImageSelection(val imageIds: Set<Long>): CustomSelectorEvent
|
||||||
|
data object OnUnselectAll: CustomSelectorEvent
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.widthIn
|
import androidx.compose.foundation.layout.widthIn
|
||||||
|
|
@ -85,7 +86,8 @@ fun CustomSelectorScreen(
|
||||||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, it)
|
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, it)
|
||||||
},
|
},
|
||||||
hasPartialAccess = hasPartialAccess,
|
hasPartialAccess = hasPartialAccess,
|
||||||
adaptiveInfo = adaptiveInfo
|
adaptiveInfo = adaptiveInfo,
|
||||||
|
onUnselectAll = { onEvent(CustomSelectorEvent.OnUnselectAll) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -112,6 +114,7 @@ fun CustomSelectorScreen(
|
||||||
fun FoldersPane(
|
fun FoldersPane(
|
||||||
uiState: CustomSelectorState,
|
uiState: CustomSelectorState,
|
||||||
onFolderClick: (Folder)-> Unit,
|
onFolderClick: (Folder)-> Unit,
|
||||||
|
onUnselectAll: ()-> Unit,
|
||||||
adaptiveInfo: WindowAdaptiveInfo,
|
adaptiveInfo: WindowAdaptiveInfo,
|
||||||
hasPartialAccess: Boolean = false
|
hasPartialAccess: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
@ -129,6 +132,7 @@ fun FoldersPane(
|
||||||
showAlertIcon = uiState.selectedImageIds.size > 20 && isCompatWidth,
|
showAlertIcon = uiState.selectedImageIds.size > 20 && isCompatWidth,
|
||||||
selectionCount = uiState.selectedImageIds.size,
|
selectionCount = uiState.selectedImageIds.size,
|
||||||
onAlertAction = { },
|
onAlertAction = { },
|
||||||
|
onUnselectAllAction = onUnselectAll,
|
||||||
showSelectionCount = uiState.inSelectionMode && isCompatWidth
|
showSelectionCount = uiState.inSelectionMode && isCompatWidth
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,9 @@ class CustomSelectorViewModel(private val mediaReader: MediaReader): ViewModel()
|
||||||
_uiState.update { it.copy(selectedImageIds = e.imageIds) }
|
_uiState.update { it.copy(selectedImageIds = e.imageIds) }
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
CustomSelectorEvent.OnUnselectAll-> {
|
||||||
|
_uiState.update { it.copy(selectedImageIds = emptySet()) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
|
@ -101,7 +102,8 @@ fun ImagesPane(
|
||||||
showNavigationIcon = isCompatWidth,
|
showNavigationIcon = isCompatWidth,
|
||||||
showAlertIcon = selectedImages().size > 20,
|
showAlertIcon = selectedImages().size > 20,
|
||||||
selectionCount = selectedImages().size,
|
selectionCount = selectedImages().size,
|
||||||
showSelectionCount = uiState.inSelectionMode
|
showSelectionCount = uiState.inSelectionMode,
|
||||||
|
onUnselectAllAction = { onEvent(CustomSelectorEvent.OnUnselectAll) }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue