Skip to content

Commit a4b36ac

Browse files
committed
move getevent debug screen to expert mode section and hide events output when recording
1 parent 384ba77 commit a4b36ac

5 files changed

Lines changed: 55 additions & 37 deletions

File tree

base/src/main/java/io/github/sds100/keymapper/base/debug/GetEventScreen.kt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ fun GetEventScreen(
7474
onBackClick = onBackClick,
7575
onToggleRecordClick = viewModel::onToggleRecordClick,
7676
onRefreshDeviceInfoClick = viewModel::onRefreshDeviceInfoClick,
77-
onCopyToClipboardClick = { tab -> viewModel.onCopyToClipboardClick(tab.toOutputTab()) },
78-
onSaveToFileClick = { tab -> viewModel.onSaveToFileClick(tab.toOutputTab()) },
77+
onCopyToClipboardClick = viewModel::onCopyToClipboardClick,
78+
onSaveToFileClick = viewModel::onSaveToFileClick,
7979
onSetupExpertModeClick = viewModel::onSetupExpertModeClick,
8080
)
8181
}
@@ -91,11 +91,6 @@ private enum class RefreshButtonState {
9191
STOP,
9292
}
9393

94-
private fun GetEventTab.toOutputTab(): GetEventViewModel.OutputTab = when (this) {
95-
GetEventTab.INFO -> GetEventViewModel.OutputTab.INFO
96-
GetEventTab.EVENTS -> GetEventViewModel.OutputTab.EVENTS
97-
}
98-
9994
@OptIn(ExperimentalMaterial3Api::class)
10095
@Composable
10196
private fun GetEventScreen(
@@ -104,18 +99,16 @@ private fun GetEventScreen(
10499
onBackClick: () -> Unit = {},
105100
onToggleRecordClick: () -> Unit = {},
106101
onRefreshDeviceInfoClick: () -> Unit = {},
107-
onCopyToClipboardClick: (GetEventTab) -> Unit = {},
108-
onSaveToFileClick: (GetEventTab) -> Unit = {},
102+
onCopyToClipboardClick: () -> Unit = {},
103+
onSaveToFileClick: () -> Unit = {},
109104
onSetupExpertModeClick: () -> Unit = {},
110105
) {
111106
val pagerState = rememberPagerState(pageCount = { 2 })
112107
val scope = rememberCoroutineScope()
113108
val isExpertModeEnabled = state.expertModeStatus == ExpertModeStatus.ENABLED
114109
val selectedTab = if (pagerState.currentPage == 0) GetEventTab.INFO else GetEventTab.EVENTS
115-
val hasOutputForSelectedTab = when (selectedTab) {
116-
GetEventTab.INFO -> state.deviceInfoOutput.isNotEmpty()
117-
GetEventTab.EVENTS -> state.recordingOutput.isNotEmpty()
118-
}
110+
val hasOutputForSelectedTab =
111+
state.deviceInfoOutput.isNotEmpty() || state.recordingOutput.isNotEmpty()
119112
val refreshButtonState = when {
120113
selectedTab == GetEventTab.INFO -> RefreshButtonState.REFRESH_INFO
121114
state.isRecording -> RefreshButtonState.STOP
@@ -209,7 +202,7 @@ private fun GetEventScreen(
209202
}
210203
Spacer(modifier = Modifier.weight(1f))
211204
IconButton(
212-
onClick = { onCopyToClipboardClick(selectedTab) },
205+
onClick = onCopyToClipboardClick,
213206
enabled = hasOutputForSelectedTab,
214207
) {
215208
Icon(
@@ -218,7 +211,7 @@ private fun GetEventScreen(
218211
)
219212
}
220213
IconButton(
221-
onClick = { onSaveToFileClick(selectedTab) },
214+
onClick = onSaveToFileClick,
222215
enabled = hasOutputForSelectedTab,
223216
) {
224217
Icon(
@@ -366,7 +359,7 @@ private fun EventsContent(modifier: Modifier = Modifier, state: GetEventViewMode
366359
)
367360
}
368361

369-
if (state.recordingOutput.isNotEmpty()) {
362+
if (!state.isRecording && state.recordingOutput.isNotEmpty()) {
370363
SelectionContainer(
371364
modifier = Modifier
372365
.weight(1f)

base/src/main/java/io/github/sds100/keymapper/base/debug/GetEventViewModel.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ class GetEventViewModel @Inject constructor(
2424
) : ViewModel(),
2525
NavigationProvider by navigationProvider {
2626

27-
enum class OutputTab {
28-
INFO,
29-
EVENTS,
30-
}
31-
3227
data class State(
3328
val deviceInfoOutput: String = "",
3429
val recordingOutput: String = "",
@@ -102,19 +97,27 @@ class GetEventViewModel @Inject constructor(
10297
}
10398
}
10499

105-
fun onCopyToClipboardClick(tab: OutputTab) {
106-
outputUseCase.copyOutput(getOutputForTab(tab))
100+
fun onCopyToClipboardClick() {
101+
outputUseCase.copyOutput(getCombinedOutput())
107102
}
108103

109-
fun onSaveToFileClick(tab: OutputTab) {
104+
fun onSaveToFileClick() {
110105
viewModelScope.launch {
111-
outputUseCase.shareOutput(getOutputForTab(tab))
106+
outputUseCase.shareOutput(getCombinedOutput())
112107
}
113108
}
114109

115-
private fun getOutputForTab(tab: OutputTab): String = when (tab) {
116-
OutputTab.INFO -> state.deviceInfoOutput
117-
OutputTab.EVENTS -> state.recordingOutput
110+
private fun getCombinedOutput(): String = buildString {
111+
if (state.deviceInfoOutput.isNotBlank()) {
112+
append(state.deviceInfoOutput)
113+
}
114+
115+
if (state.recordingOutput.isNotBlank()) {
116+
if (isNotEmpty()) {
117+
append("\n\n")
118+
}
119+
append(state.recordingOutput)
120+
}
118121
}
119122

120123
fun onBackClick() {

base/src/main/java/io/github/sds100/keymapper/base/expertmode/ExpertModeScreen.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.foundation.verticalScroll
2929
import androidx.compose.material.icons.Icons
3030
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
3131
import androidx.compose.material.icons.automirrored.rounded.HelpOutline
32+
import androidx.compose.material.icons.outlined.BugReport
3233
import androidx.compose.material.icons.rounded.Check
3334
import androidx.compose.material.icons.rounded.Checklist
3435
import androidx.compose.material.icons.rounded.Close
@@ -74,6 +75,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
7475
import io.github.sds100.keymapper.base.R
7576
import io.github.sds100.keymapper.base.compose.KeyMapperTheme
7677
import io.github.sds100.keymapper.base.compose.LocalCustomColorsPalette
78+
import io.github.sds100.keymapper.base.utils.ui.compose.OptionPageButton
7779
import io.github.sds100.keymapper.base.utils.ui.compose.OptionsHeaderRow
7880
import io.github.sds100.keymapper.base.utils.ui.compose.SwitchPreferenceCompose
7981
import io.github.sds100.keymapper.base.utils.ui.compose.icons.FakeShizuku
@@ -114,6 +116,7 @@ fun ExpertModeScreen(modifier: Modifier = Modifier, viewModel: ExpertModeViewMod
114116
onAutoStartAtBootToggled = { viewModel.onAutoStartBootToggled() },
115117
onLaunchDeveloperOptionsClick = viewModel::onLaunchDeveloperOptionsClick,
116118
onGetShellStartCommandClick = viewModel::onGetShellStartCommandClick,
119+
onGetEventClick = viewModel::onGetEventClick,
117120
)
118121
}
119122
}
@@ -196,6 +199,7 @@ private fun Content(
196199
onAutoStartAtBootToggled: () -> Unit = {},
197200
onLaunchDeveloperOptionsClick: () -> Unit = {},
198201
onGetShellStartCommandClick: () -> Unit = {},
202+
onGetEventClick: () -> Unit = {},
199203
) {
200204
Column(modifier = modifier.verticalScroll(rememberScrollState())) {
201205
AnimatedVisibility(
@@ -255,6 +259,27 @@ private fun Content(
255259
textAlign = TextAlign.Center,
256260
)
257261
}
262+
263+
Spacer(modifier = Modifier.height(16.dp))
264+
265+
OptionsHeaderRow(
266+
modifier = Modifier
267+
.fillMaxWidth()
268+
.padding(horizontal = 16.dp),
269+
icon = Icons.Outlined.BugReport,
270+
text = stringResource(R.string.settings_section_debugging_title),
271+
)
272+
273+
Spacer(modifier = Modifier.height(8.dp))
274+
275+
OptionPageButton(
276+
modifier = Modifier.padding(horizontal = 8.dp),
277+
title = stringResource(R.string.title_pref_get_event_debug),
278+
text = stringResource(R.string.summary_pref_get_event_debug),
279+
icon = Icons.Outlined.BugReport,
280+
onClick = onGetEventClick,
281+
)
282+
Spacer(modifier = Modifier.height(8.dp))
258283
}
259284
}
260285

base/src/main/java/io/github/sds100/keymapper/base/expertmode/ExpertModeViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ class ExpertModeViewModel @Inject constructor(
188188
}
189189
}
190190

191+
fun onGetEventClick() {
192+
viewModelScope.launch {
193+
navigate("get_event_debug", NavDestination.GetEvent)
194+
}
195+
}
196+
191197
private fun stoppedStateFlow(): Flow<ExpertModeState.Stopped> = combine(
192198
useCase.isRootGranted,
193199
useCase.shizukuSetupState,

base/src/main/java/io/github/sds100/keymapper/base/settings/SettingsScreen.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ fun SettingsScreen(modifier: Modifier = Modifier, viewModel: SettingsViewModel)
152152
onForceVibrateToggled = viewModel::onForceVibrateToggled,
153153
onLoggingToggled = viewModel::onLoggingToggled,
154154
onViewLogClick = viewModel::onViewLogClick,
155-
onGetEventClick = viewModel::onGetEventClick,
156155
onHideHomeScreenAlertsToggled = viewModel::onHideHomeScreenAlertsToggled,
157156
onShowDeviceDescriptorsToggled = viewModel::onShowDeviceDescriptorsToggled,
158157
onAutomaticBackupClick = {
@@ -236,7 +235,6 @@ private fun Content(
236235
onForceVibrateToggled: (Boolean) -> Unit = { },
237236
onLoggingToggled: (Boolean) -> Unit = { },
238237
onViewLogClick: () -> Unit = { },
239-
onGetEventClick: () -> Unit = { },
240238
onShareLogcatClick: () -> Unit = { },
241239
onHideHomeScreenAlertsToggled: (Boolean) -> Unit = { },
242240
onShowDeviceDescriptorsToggled: (Boolean) -> Unit = { },
@@ -400,13 +398,6 @@ private fun Content(
400398
onClick = onShareLogcatClick,
401399
)
402400

403-
OptionPageButton(
404-
title = stringResource(R.string.title_pref_get_event_debug),
405-
text = stringResource(R.string.summary_pref_get_event_debug),
406-
icon = Icons.Rounded.Keyboard,
407-
onClick = onGetEventClick,
408-
)
409-
410401
Spacer(modifier = Modifier.height(8.dp))
411402
}
412403
}

0 commit comments

Comments
 (0)