Skip to content

Commit 07abfe4

Browse files
authored
New ListView Albums (#700)
* Added PreferenceKey logic for ViewType * Added AlbumRowComponent for ListView * Added functionality for switching ViewType from Grid to List * Fixed padding values and added Haze to LazyColumn * Fixed PreferenceKey
1 parent 294f8e6 commit 07abfe4

File tree

4 files changed

+505
-151
lines changed

4 files changed

+505
-151
lines changed

app/src/main/kotlin/com/dot/gallery/core/Settings.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ object Settings {
5757

5858
object Album {
5959
private val LAST_SORT = stringPreferencesKey("album_last_sort_obj")
60+
private val LAST_VIEW = stringPreferencesKey("album_last_view_obj")
6061

6162
@Serializable
6263
@Parcelize
@@ -65,13 +66,26 @@ object Settings {
6566
val kind: FilterKind
6667
) : Parcelable
6768

69+
@Serializable
70+
@Parcelize
71+
enum class ViewType : Parcelable {
72+
GRID, LIST
73+
}
74+
6875
@Composable
6976
fun rememberLastSort() =
7077
rememberPreferenceSerializable(
7178
keyString = LAST_SORT,
7279
defaultValue = LastSort(OrderType.Descending, FilterKind.DATE)
7380
)
7481

82+
@Composable
83+
fun rememberLastViewType() =
84+
rememberPreferenceSerializable(
85+
keyString = LAST_VIEW,
86+
defaultValue = ViewType.GRID
87+
)
88+
7589
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
7690
@Composable
7791
fun rememberAlbumGridSize(): MutableState<Int> {

app/src/main/kotlin/com/dot/gallery/core/presentation/components/FilterComponent.kt

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.dot.gallery.core.presentation.components
77

88
import androidx.compose.foundation.clickable
9+
import androidx.compose.foundation.layout.Arrangement
910
import androidx.compose.foundation.layout.Box
1011
import androidx.compose.foundation.layout.Row
1112
import androidx.compose.foundation.layout.fillMaxWidth
@@ -14,6 +15,8 @@ import androidx.compose.foundation.layout.wrapContentSize
1415
import androidx.compose.foundation.shape.RoundedCornerShape
1516
import androidx.compose.material.icons.Icons
1617
import androidx.compose.material.icons.outlined.Check
18+
import androidx.compose.material.icons.outlined.GridView
19+
import androidx.compose.material.icons.outlined.HorizontalSplit
1720
import androidx.compose.material.icons.outlined.KeyboardDoubleArrowDown
1821
import androidx.compose.material.icons.outlined.KeyboardDoubleArrowUp
1922
import androidx.compose.material3.DropdownMenu
@@ -33,14 +36,17 @@ import androidx.compose.ui.draw.clip
3336
import androidx.compose.ui.res.stringResource
3437
import androidx.compose.ui.text.font.FontWeight
3538
import androidx.compose.ui.unit.dp
39+
import com.dot.gallery.core.Settings
3640
import com.dot.gallery.core.Settings.Album.rememberLastSort
3741
import com.dot.gallery.feature_node.domain.util.MediaOrder
3842
import com.dot.gallery.feature_node.domain.util.OrderType
3943

4044
@Composable
4145
fun FilterButton(
4246
modifier: Modifier = Modifier,
43-
filterOptions: Array<FilterOption> = emptyArray()
47+
filterOptions: Array<FilterOption> = emptyArray(),
48+
viewType: Settings.Album.ViewType,
49+
onViewTypeChange: (Settings.Album.ViewType) -> Unit
4450
) {
4551
var lastSort by rememberLastSort()
4652
var expanded by remember { mutableStateOf(false) }
@@ -54,38 +60,59 @@ fun FilterButton(
5460
contentAlignment = Alignment.TopEnd
5561
) {
5662
Row(
57-
verticalAlignment = Alignment.CenterVertically
63+
modifier = Modifier.fillMaxWidth(),
64+
verticalAlignment = Alignment.CenterVertically,
65+
horizontalArrangement = Arrangement.SpaceBetween
5866
) {
59-
Text(
60-
modifier = Modifier
61-
.clip(RoundedCornerShape(100))
62-
.clickable {
63-
expanded = true
64-
}
65-
.padding(vertical = 4.dp, horizontal = 8.dp),
66-
style = MaterialTheme.typography.titleMedium,
67-
fontWeight = FontWeight.Bold,
68-
color = MaterialTheme.colorScheme.primary,
69-
text = stringResource(selectedFilter.titleRes)
70-
)
7167
IconButton(
7268
onClick = {
73-
order = if (order == OrderType.Ascending) OrderType.Descending else OrderType.Ascending
74-
lastSort = lastSort.copy(orderType = order)
69+
if (viewType == Settings.Album.ViewType.GRID) {
70+
onViewTypeChange(Settings.Album.ViewType.LIST)
71+
} else {
72+
onViewTypeChange(Settings.Album.ViewType.GRID)
73+
}
7574
}
7675
) {
7776
Icon(
78-
imageVector = remember(selectedFilter) {
79-
if (order == OrderType.Descending)
80-
Icons.Outlined.KeyboardDoubleArrowDown
81-
else Icons.Outlined.KeyboardDoubleArrowUp
82-
},
83-
tint = MaterialTheme.colorScheme.primary,
84-
contentDescription = null
77+
imageVector = if (viewType == Settings.Album.ViewType.GRID) Icons.Outlined.GridView else Icons.Outlined.HorizontalSplit,
78+
contentDescription = "Toggle View Type",
79+
tint = MaterialTheme.colorScheme.primary
8580
)
8681
}
87-
}
8882

83+
Row(
84+
verticalAlignment = Alignment.CenterVertically
85+
) {
86+
Text(
87+
modifier = Modifier
88+
.clip(RoundedCornerShape(100))
89+
.clickable {
90+
expanded = true
91+
}
92+
.padding(vertical = 4.dp, horizontal = 8.dp),
93+
style = MaterialTheme.typography.titleMedium,
94+
fontWeight = FontWeight.Bold,
95+
color = MaterialTheme.colorScheme.primary,
96+
text = stringResource(selectedFilter.titleRes)
97+
)
98+
IconButton(
99+
onClick = {
100+
order = if (order == OrderType.Ascending) OrderType.Descending else OrderType.Ascending
101+
lastSort = lastSort.copy(orderType = order)
102+
}
103+
) {
104+
Icon(
105+
imageVector = remember(selectedFilter) {
106+
if (order == OrderType.Descending)
107+
Icons.Outlined.KeyboardDoubleArrowDown
108+
else Icons.Outlined.KeyboardDoubleArrowUp
109+
},
110+
tint = MaterialTheme.colorScheme.primary,
111+
contentDescription = null
112+
)
113+
}
114+
}
115+
}
89116
Box(
90117
modifier = Modifier
91118
.wrapContentSize(Alignment.TopEnd)

0 commit comments

Comments
 (0)