Skip to content

Commit 27e2fcf

Browse files
committed
fix: creating key map shortcuts from groups works
1 parent 3180fe9 commit 27e2fcf

7 files changed

Lines changed: 282 additions & 88 deletions

File tree

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import io.github.sds100.keymapper.util.ui.compose.ComposeIconInfo
5151
fun GroupRow(
5252
modifier: Modifier = Modifier,
5353
groups: List<GroupListItemModel>,
54+
showNewGroup: Boolean = true,
5455
onNewGroupClick: () -> Unit = {},
5556
onGroupClick: (String) -> Unit = {},
5657
enabled: Boolean = true,
@@ -80,19 +81,21 @@ fun GroupRow(
8081
// Show new group button in the expand indicator if the new group button
8182
// in the flow row has overflowed.
8283
Row {
83-
NewGroupButton(
84-
onClick = onNewGroupClick,
85-
text = if (isSubgroups) {
86-
stringResource(R.string.home_new_subgroup_button)
87-
} else {
88-
stringResource(R.string.home_new_group_button)
89-
},
90-
icon = {
91-
Icon(imageVector = Icons.Rounded.Add, null)
92-
},
93-
showText = groups.isEmpty(),
94-
enabled = enabled,
95-
)
84+
if (showNewGroup) {
85+
NewGroupButton(
86+
onClick = onNewGroupClick,
87+
text = if (isSubgroups) {
88+
stringResource(R.string.home_new_subgroup_button)
89+
} else {
90+
stringResource(R.string.home_new_group_button)
91+
},
92+
icon = {
93+
Icon(imageVector = Icons.Rounded.Add, null)
94+
},
95+
showText = groups.isEmpty(),
96+
enabled = enabled,
97+
)
98+
}
9699

97100
Spacer(Modifier.width(8.dp))
98101

@@ -160,19 +163,21 @@ fun GroupRow(
160163
)
161164
}
162165

163-
NewGroupButton(
164-
onClick = onNewGroupClick,
165-
text = if (isSubgroups) {
166-
stringResource(R.string.home_new_subgroup_button)
167-
} else {
168-
stringResource(R.string.home_new_group_button)
169-
},
170-
icon = {
171-
Icon(imageVector = Icons.Rounded.Add, null)
172-
},
173-
showText = groups.isEmpty(),
174-
enabled = enabled,
175-
)
166+
if (showNewGroup) {
167+
NewGroupButton(
168+
onClick = onNewGroupClick,
169+
text = if (isSubgroups) {
170+
stringResource(R.string.home_new_subgroup_button)
171+
} else {
172+
stringResource(R.string.home_new_group_button)
173+
},
174+
icon = {
175+
Icon(imageVector = Icons.Rounded.Add, null)
176+
},
177+
showText = groups.isEmpty(),
178+
enabled = enabled,
179+
)
180+
}
176181
}
177182
}
178183
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fun HomeKeyMapListScreen(
177177
)
178178
},
179179
appBarContent = {
180-
KeyMapAppBar(
180+
KeyMapListAppBar(
181181
state = state.appBarState,
182182
scrollBehavior = scrollBehavior,
183183
onSettingsClick = onSettingsClick,
@@ -500,7 +500,7 @@ private fun PreviewSelectingKeyMaps() {
500500
)
501501
},
502502
appBarContent = {
503-
KeyMapAppBar(state = appBarState)
503+
KeyMapListAppBar(state = appBarState)
504504
},
505505
selectionBottomSheet = {
506506
SelectionBottomSheet(
@@ -543,7 +543,7 @@ private fun PreviewKeyMapsRunning() {
543543
)
544544
},
545545
appBarContent = {
546-
KeyMapAppBar(state = appBarState)
546+
KeyMapListAppBar(state = appBarState)
547547
},
548548
selectionBottomSheet = {},
549549
)
@@ -579,7 +579,7 @@ private fun PreviewKeyMapsPaused() {
579579
)
580580
},
581581
appBarContent = {
582-
KeyMapAppBar(state = appBarState)
582+
KeyMapListAppBar(state = appBarState)
583583
},
584584
selectionBottomSheet = {},
585585
)
@@ -634,7 +634,7 @@ private fun PreviewKeyMapsWarnings() {
634634
)
635635
},
636636
appBarContent = {
637-
KeyMapAppBar(state = appBarState)
637+
KeyMapListAppBar(state = appBarState)
638638
},
639639
selectionBottomSheet = {},
640640
)
@@ -681,7 +681,7 @@ private fun PreviewKeyMapsWarningsEmpty() {
681681
)
682682
},
683683
appBarContent = {
684-
KeyMapAppBar(state = appBarState)
684+
KeyMapListAppBar(state = appBarState)
685685
},
686686
selectionBottomSheet = {},
687687
)

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ import kotlinx.coroutines.launch
111111

112112
@Composable
113113
@OptIn(ExperimentalMaterial3Api::class)
114-
fun KeyMapAppBar(
114+
fun KeyMapListAppBar(
115115
modifier: Modifier = Modifier,
116116
state: KeyMapAppBarState,
117117
onSettingsClick: () -> Unit = {},
@@ -146,10 +146,17 @@ fun KeyMapAppBar(
146146
state = state,
147147
scrollBehavior = scrollBehavior,
148148
onTogglePausedClick = onTogglePausedClick,
149-
onSortClick = onSortClick,
150149
onFixWarningClick = onFixWarningClick,
151150
onNewGroupClick = onNewGroupClick,
152151
onGroupClick = onGroupClick,
152+
navigationIcon = {
153+
IconButton(onClick = onSortClick) {
154+
Icon(
155+
Icons.AutoMirrored.Rounded.Sort,
156+
contentDescription = stringResource(R.string.home_app_bar_sort),
157+
)
158+
}
159+
},
153160
actions = {
154161
AppBarActions(
155162
onHelpClick,
@@ -282,10 +289,10 @@ private fun RootGroupAppBar(
282289
state: KeyMapAppBarState.RootGroup,
283290
scrollBehavior: TopAppBarScrollBehavior,
284291
onTogglePausedClick: () -> Unit,
285-
onSortClick: () -> Unit,
286292
onFixWarningClick: (String) -> Unit,
287293
onNewGroupClick: () -> Unit,
288294
onGroupClick: (String) -> Unit,
295+
navigationIcon: @Composable () -> Unit,
289296
actions: @Composable RowScope.() -> Unit,
290297
) {
291298
// This is taken from the AppBar color code.
@@ -319,14 +326,7 @@ private fun RootGroupAppBar(
319326
onTogglePausedClick = onTogglePausedClick,
320327
)
321328
},
322-
navigationIcon = {
323-
IconButton(onClick = onSortClick) {
324-
Icon(
325-
Icons.AutoMirrored.Rounded.Sort,
326-
contentDescription = stringResource(R.string.home_app_bar_sort),
327-
)
328-
}
329-
},
329+
navigationIcon = navigationIcon,
330330
actions = actions,
331331
colors = appBarColors,
332332
)
@@ -914,7 +914,7 @@ private fun KeyMapsChildGroupPreview() {
914914
isNewGroup = false,
915915
)
916916
KeyMapperTheme {
917-
KeyMapAppBar(modifier = Modifier.fillMaxWidth(), state = state)
917+
KeyMapListAppBar(modifier = Modifier.fillMaxWidth(), state = state)
918918
}
919919
}
920920

@@ -933,7 +933,7 @@ private fun KeyMapsChildGroupDarkPreview() {
933933
isNewGroup = false,
934934
)
935935
KeyMapperTheme(darkTheme = true) {
936-
KeyMapAppBar(modifier = Modifier.fillMaxWidth(), state = state)
936+
KeyMapListAppBar(modifier = Modifier.fillMaxWidth(), state = state)
937937
}
938938
}
939939

@@ -984,7 +984,7 @@ private fun KeyMapsChildGroupEditingDarkPreview() {
984984
}
985985

986986
KeyMapperTheme(darkTheme = true) {
987-
KeyMapAppBar(
987+
KeyMapListAppBar(
988988
state = state,
989989
)
990990
}
@@ -1024,7 +1024,7 @@ private fun KeyMapsRunningPreview() {
10241024
isPaused = false,
10251025
)
10261026
KeyMapperTheme {
1027-
KeyMapAppBar(state = state)
1027+
KeyMapListAppBar(state = state)
10281028
}
10291029
}
10301030

@@ -1038,7 +1038,7 @@ private fun HomeStatePausedPreview() {
10381038
isPaused = true,
10391039
)
10401040
KeyMapperTheme {
1041-
KeyMapAppBar(state = state)
1041+
KeyMapListAppBar(state = state)
10421042
}
10431043
}
10441044

@@ -1064,7 +1064,7 @@ private fun HomeStateWarningsPreview() {
10641064
isPaused = true,
10651065
)
10661066
KeyMapperTheme {
1067-
KeyMapAppBar(state = state)
1067+
KeyMapListAppBar(state = state)
10681068
}
10691069
}
10701070

@@ -1090,7 +1090,7 @@ private fun HomeStateWarningsDarkPreview() {
10901090
isPaused = true,
10911091
)
10921092
KeyMapperTheme(darkTheme = true) {
1093-
KeyMapAppBar(state = state)
1093+
KeyMapListAppBar(state = state)
10941094
}
10951095
}
10961096

@@ -1107,7 +1107,7 @@ private fun HomeStateSelectingPreview() {
11071107
showThisGroup = false,
11081108
)
11091109
KeyMapperTheme {
1110-
KeyMapAppBar(state = state)
1110+
KeyMapListAppBar(state = state)
11111111
}
11121112
}
11131113

@@ -1124,6 +1124,6 @@ private fun HomeStateSelectingDisabledPreview() {
11241124
showThisGroup = false,
11251125
)
11261126
KeyMapperTheme {
1127-
KeyMapAppBar(state = state)
1127+
KeyMapListAppBar(state = state)
11281128
}
11291129
}

app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapScreen.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private fun ConfigKeyMapScreen(
148148
modifier.displayCutoutPadding(),
149149
snackbarHost = { SnackbarHost(snackbarHostState) },
150150
bottomBar = {
151-
KeyMapAppBar(
151+
ConfigKeyMapAppBar(
152152
isKeyMapEnabled = isKeyMapEnabled,
153153
onKeyMapEnabledChange = onKeyMapEnabledChange,
154154
onBackClick = onBackClick,
@@ -163,7 +163,7 @@ private fun ConfigKeyMapScreen(
163163
ConfigKeyMapTab.ACTIONS -> actionsHelpUrl
164164
ConfigKeyMapTab.CONSTRAINTS -> constraintsHelpUrl
165165
ConfigKeyMapTab.OPTIONS -> optionsHelpUrl
166-
else -> return@KeyMapAppBar
166+
else -> return@ConfigKeyMapAppBar
167167
}
168168

169169
if (url.isNotEmpty()) {
@@ -298,7 +298,7 @@ private fun ConfigKeyMapScreen(
298298
}
299299

300300
@Composable
301-
private fun KeyMapAppBar(
301+
private fun ConfigKeyMapAppBar(
302302
modifier: Modifier = Modifier,
303303
isKeyMapEnabled: Boolean,
304304
onKeyMapEnabledChange: (Boolean) -> Unit = {},

0 commit comments

Comments
 (0)