Skip to content

Commit e4ec495

Browse files
committed
feat: groups in the selection bottom sheet are fully navigable
1 parent f7d07e3 commit e4ec495

14 files changed

Lines changed: 270 additions & 171 deletions

File tree

app/src/main/java/io/github/sds100/keymapper/data/db/dao/GroupDao.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import androidx.room.OnConflictStrategy
77
import androidx.room.Query
88
import androidx.room.Update
99
import io.github.sds100.keymapper.data.entities.GroupEntity
10-
import io.github.sds100.keymapper.data.entities.GroupEntityWithSubGroups
10+
import io.github.sds100.keymapper.data.entities.GroupEntityWithChildren
1111
import io.github.sds100.keymapper.data.entities.KeyMapEntitiesWithGroup
1212
import kotlinx.coroutines.flow.Flow
1313

@@ -39,7 +39,7 @@ interface GroupDao {
3939
fun getByIdFlow(uid: String): Flow<GroupEntity?>
4040

4141
@Query("SELECT * FROM $TABLE_NAME WHERE $KEY_UID = (:uid)")
42-
fun getGroupWithSubGroups(uid: String): Flow<GroupEntityWithSubGroups>
42+
fun getGroupWithSubGroups(uid: String): Flow<GroupEntityWithChildren>
4343

4444
@Query("SELECT * FROM $TABLE_NAME WHERE $KEY_PARENT_UID IS (:uid)")
4545
fun getGroupsByParent(uid: String?): Flow<List<GroupEntity>>

app/src/main/java/io/github/sds100/keymapper/data/entities/GroupEntityWithSubGroups.kt renamed to app/src/main/java/io/github/sds100/keymapper/data/entities/GroupEntityWithChildren.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import androidx.room.Embedded
44
import androidx.room.Relation
55
import io.github.sds100.keymapper.data.db.dao.GroupDao
66

7-
data class GroupEntityWithSubGroups(
7+
data class GroupEntityWithChildren(
88
@Embedded
99
val group: GroupEntity,
1010

1111
@Relation(
1212
parentColumn = GroupDao.KEY_UID,
1313
entityColumn = GroupDao.KEY_PARENT_UID,
1414
)
15-
val subGroups: List<GroupEntity>,
15+
val children: List<GroupEntity>,
1616
)

app/src/main/java/io/github/sds100/keymapper/data/repositories/GroupRepository.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.github.sds100.keymapper.data.repositories
22

33
import io.github.sds100.keymapper.data.db.dao.GroupDao
44
import io.github.sds100.keymapper.data.entities.GroupEntity
5-
import io.github.sds100.keymapper.data.entities.GroupEntityWithSubGroups
5+
import io.github.sds100.keymapper.data.entities.GroupEntityWithChildren
66
import io.github.sds100.keymapper.data.entities.KeyMapEntitiesWithGroup
77
import io.github.sds100.keymapper.util.DefaultDispatcherProvider
88
import io.github.sds100.keymapper.util.DispatcherProvider
@@ -23,7 +23,7 @@ interface GroupRepository {
2323
fun getAllGroups(): Flow<List<GroupEntity>>
2424
fun getGroups(vararg uid: String): Flow<List<GroupEntity>>
2525
fun getGroupsByParent(uid: String?): Flow<List<GroupEntity>>
26-
fun getGroupWithSubGroups(uid: String): Flow<GroupEntityWithSubGroups>
26+
fun getGroupWithChildren(uid: String): Flow<GroupEntityWithChildren>
2727
suspend fun insert(groupEntity: GroupEntity)
2828
suspend fun update(groupEntity: GroupEntity)
2929
fun delete(uid: String)
@@ -59,7 +59,7 @@ class RoomGroupRepository(
5959
return dao.getGroupsByParent(uid).flowOn(dispatchers.io())
6060
}
6161

62-
override fun getGroupWithSubGroups(uid: String): Flow<GroupEntityWithSubGroups> {
62+
override fun getGroupWithChildren(uid: String): Flow<GroupEntityWithChildren> {
6363
return dao.getGroupWithSubGroups(uid).flowOn(dispatchers.io())
6464
}
6565

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.sds100.keymapper.groups
2+
3+
data class GroupFamily(
4+
val group: Group?,
5+
val children: List<Group>,
6+
val parents: List<Group>,
7+
)

app/src/main/java/io/github/sds100/keymapper/groups/GroupRow.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ fun GroupRow(
5050
onGroupClick: (String) -> Unit = {},
5151
enabled: Boolean = true,
5252
isSubgroups: Boolean = false,
53+
showThisGroupButton: Boolean = false,
54+
onThisGroupClick: () -> Unit = {},
5355
) {
5456
var viewAllState by rememberSaveable { mutableStateOf(false) }
5557

@@ -67,15 +69,15 @@ fun GroupRow(
6769
overflow = FlowRowOverflow.expandOrCollapseIndicator(
6870
expandIndicator = {
6971
// Some padding is required on the end to stop it overflowing the screen.
70-
ViewAllButton(
72+
TextGroupButton(
7173
modifier = Modifier.padding(end = 16.dp),
7274
onClick = { viewAllState = true },
7375
text = stringResource(R.string.home_new_view_all_groups_button),
7476
enabled = enabled,
7577
)
7678
},
7779
collapseIndicator = {
78-
ViewAllButton(
80+
TextGroupButton(
7981
modifier = Modifier.padding(end = 16.dp),
8082
onClick = { viewAllState = false },
8183
text = stringResource(R.string.home_new_hide_groups_button),
@@ -99,6 +101,14 @@ fun GroupRow(
99101
enabled = enabled,
100102
)
101103

104+
if (showThisGroupButton) {
105+
TextGroupButton(
106+
onClick = onThisGroupClick,
107+
text = stringResource(R.string.home_this_group_button),
108+
enabled = enabled,
109+
)
110+
}
111+
102112
for (group in groups) {
103113
GroupButton(
104114
onClick = { onGroupClick(group.uid) },
@@ -180,7 +190,7 @@ private fun NewGroupButton(
180190
}
181191

182192
@Composable
183-
private fun ViewAllButton(
193+
private fun TextGroupButton(
184194
modifier: Modifier = Modifier,
185195
onClick: () -> Unit,
186196
text: String,
@@ -287,6 +297,7 @@ private fun PreviewOneItem() {
287297
),
288298
),
289299
enabled = false,
300+
showThisGroupButton = false,
290301
)
291302
}
292303
}
@@ -337,6 +348,7 @@ private fun PreviewMultipleItems() {
337348
icon = null,
338349
),
339350
),
351+
showThisGroupButton = true,
340352
)
341353
}
342354
}

app/src/main/java/io/github/sds100/keymapper/groups/GroupWithSubGroups.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/java/io/github/sds100/keymapper/home/HomeKeyMapListScreen.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ fun HomeKeyMapListScreen(
216216
selectedKeyMapsEnabled = SelectedKeyMapsEnabled.NONE,
217217
isAllSelected = false,
218218
groups = emptyList(),
219+
breadcrumbs = emptyList(),
220+
showThisGroup = false,
219221
)
220222

221223
SelectionBottomSheet(
@@ -225,13 +227,16 @@ fun HomeKeyMapListScreen(
225227
},
226228
enabled = selectionState.selectionCount > 0,
227229
groups = selectionState.groups,
230+
breadcrumbs = selectionState.breadcrumbs,
228231
selectedKeyMapsEnabled = selectionState.selectedKeyMapsEnabled,
229232
onEnabledKeyMapsChange = viewModel::onEnabledKeyMapsChange,
230233
onDuplicateClick = viewModel::onDuplicateSelectedKeyMapsClick,
231234
onExportClick = viewModel::onExportSelectedKeyMaps,
232235
onDeleteClick = { showDeleteDialog = true },
233-
onMoveToGroupClick = viewModel::onMoveToGroupClick,
236+
onGroupClick = viewModel::onSelectionGroupClick,
234237
onNewGroupClick = viewModel::onNewGroupClick,
238+
showThisGroup = selectionState.showThisGroup,
239+
onThisGroupClick = viewModel::onMoveToThisGroupClick,
235240
)
236241
}
237242
},
@@ -476,6 +481,8 @@ private fun PreviewSelectingKeyMaps() {
476481
selectedKeyMapsEnabled = SelectedKeyMapsEnabled.MIXED,
477482
isAllSelected = false,
478483
groups = emptyList(),
484+
breadcrumbs = emptyList(),
485+
showThisGroup = false,
479486
)
480487

481488
val listState = State.Data(sampleList())
@@ -499,6 +506,7 @@ private fun PreviewSelectingKeyMaps() {
499506
enabled = true,
500507
selectedKeyMapsEnabled = SelectedKeyMapsEnabled.MIXED,
501508
groups = emptyList(),
509+
breadcrumbs = emptyList(),
502510
)
503511
},
504512
)

app/src/main/java/io/github/sds100/keymapper/home/KeyMapAppBar.kt

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fun KeyMapAppBar(
228228
onEditClick = onEditGroupNameClick,
229229
isEditingGroupName = state.isEditingGroupName,
230230
subGroups = state.subGroups,
231-
parentGroups = state.parentGroups,
231+
parentGroups = state.breadcrumbs,
232232
onGroupClick = onGroupClick,
233233
constraints = state.constraints,
234234
constraintMode = state.constraintMode,
@@ -415,12 +415,6 @@ private fun ChildGroupAppBar(
415415
}
416416

417417
Column(horizontalAlignment = Alignment.End) {
418-
// Text(
419-
// modifier = Modifier.padding(horizontal = 8.dp),
420-
// text = stringResource(R.string.home_group_constraints_title),
421-
// style = MaterialTheme.typography.titleSmall,
422-
// )
423-
424418
GroupConstraintRow(
425419
modifier = Modifier
426420
.padding(horizontal = 8.dp)
@@ -462,17 +456,6 @@ private fun ChildGroupAppBar(
462456

463457
Surface {
464458
Column {
465-
GroupRow(
466-
modifier = Modifier
467-
.padding(8.dp)
468-
.fillMaxWidth(),
469-
groups = subGroups,
470-
onNewGroupClick = onNewGroupClick,
471-
onGroupClick = onGroupClick,
472-
enabled = !isEditingGroupName,
473-
isSubgroups = true,
474-
)
475-
476459
val scrollState = rememberScrollState()
477460

478461
LaunchedEffect(parentGroups) {
@@ -483,10 +466,21 @@ private fun ChildGroupAppBar(
483466
modifier = Modifier
484467
.horizontalScroll(scrollState)
485468
.fillMaxWidth()
486-
.padding(horizontal = 8.dp),
469+
.padding(8.dp),
487470
groups = parentGroups,
488471
onGroupClick = onGroupClick,
489472
)
473+
474+
GroupRow(
475+
modifier = Modifier
476+
.fillMaxWidth()
477+
.padding(horizontal = 8.dp),
478+
groups = subGroups,
479+
onNewGroupClick = onNewGroupClick,
480+
onGroupClick = onGroupClick,
481+
enabled = !isEditingGroupName,
482+
isSubgroups = true,
483+
)
490484
}
491485
}
492486
}
@@ -644,6 +638,7 @@ private fun GroupNameRow(
644638
placeholder,
645639
style = MaterialTheme.typography.titleLarge,
646640
maxLines = 1,
641+
color = OutlinedTextFieldDefaults.colors().disabledPlaceholderColor,
647642
)
648643
},
649644
innerTextField = {
@@ -911,7 +906,7 @@ private fun KeyMapsChildGroupPreview() {
911906
subGroups = groupSampleList(),
912907
constraints = constraintsSampleList(),
913908
constraintMode = ConstraintMode.AND,
914-
parentGroups = groupSampleList(),
909+
breadcrumbs = groupSampleList(),
915910
isEditingGroupName = false,
916911
isNewGroup = false,
917912
)
@@ -929,7 +924,7 @@ private fun KeyMapsChildGroupDarkPreview() {
929924
subGroups = groupSampleList(),
930925
constraints = emptyList(),
931926
constraintMode = ConstraintMode.AND,
932-
parentGroups = emptyList(),
927+
breadcrumbs = emptyList(),
933928
isEditingGroupName = false,
934929
isNewGroup = false,
935930
)
@@ -942,25 +937,22 @@ private fun KeyMapsChildGroupDarkPreview() {
942937
@Preview(showSystemUi = true)
943938
@Composable
944939
private fun KeyMapsChildGroupEditingPreview() {
945-
val state = KeyMapAppBarState.ChildGroup(
946-
groupName = "Untitled group 23",
947-
subGroups = groupSampleList(),
948-
constraints = constraintsSampleList(),
949-
constraintMode = ConstraintMode.AND,
950-
parentGroups = emptyList(),
951-
isEditingGroupName = true,
952-
isNewGroup = true,
953-
)
954-
955940
val focusRequester = FocusRequester()
956941

957942
LaunchedEffect("") {
958943
focusRequester.requestFocus()
959944
}
960945

961946
KeyMapperTheme {
962-
KeyMapAppBar(
963-
state = state,
947+
ChildGroupAppBar(
948+
groupName = TextFieldValue(""),
949+
placeholder = "Untitled group 23",
950+
error = stringResource(R.string.home_app_bar_group_name_unique_error),
951+
isEditingGroupName = true,
952+
subGroups = emptyList(),
953+
parentGroups = emptyList(),
954+
constraints = emptyList(),
955+
constraintMode = ConstraintMode.AND,
964956
)
965957
}
966958
}
@@ -974,7 +966,7 @@ private fun KeyMapsChildGroupEditingDarkPreview() {
974966
subGroups = groupSampleList(),
975967
constraints = constraintsSampleList(),
976968
constraintMode = ConstraintMode.AND,
977-
parentGroups = emptyList(),
969+
breadcrumbs = emptyList(),
978970
isEditingGroupName = true,
979971
isNewGroup = true,
980972
)
@@ -1104,6 +1096,8 @@ private fun HomeStateSelectingPreview() {
11041096
selectedKeyMapsEnabled = SelectedKeyMapsEnabled.MIXED,
11051097
isAllSelected = false,
11061098
groups = emptyList(),
1099+
breadcrumbs = emptyList(),
1100+
showThisGroup = false,
11071101
)
11081102
KeyMapperTheme {
11091103
KeyMapAppBar(state = state)
@@ -1119,6 +1113,8 @@ private fun HomeStateSelectingDisabledPreview() {
11191113
selectedKeyMapsEnabled = SelectedKeyMapsEnabled.MIXED,
11201114
isAllSelected = true,
11211115
groups = emptyList(),
1116+
breadcrumbs = emptyList(),
1117+
showThisGroup = false,
11221118
)
11231119
KeyMapperTheme {
11241120
KeyMapAppBar(state = state)

0 commit comments

Comments
 (0)