Skip to content

Commit 786fad2

Browse files
committed
#2025 feat: add button to report bug on home screen
1 parent 413c6de commit 786fad2

File tree

5 files changed

+102
-11
lines changed

5 files changed

+102
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Added
66

77
- #2024 support Expert mode on all Android versions supported by Key Mapper (8.0+).
8+
- #2025 add report bug button to home screen menu.
89

910
## [4.0.3](https://github.com/sds100/KeyMapper/releases/tag/v4.0.3)
1011

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.animation.slideInVertically
1212
import androidx.compose.animation.slideOutHorizontally
1313
import androidx.compose.animation.slideOutVertically
1414
import androidx.compose.foundation.layout.Box
15+
import androidx.compose.foundation.layout.Row
1516
import androidx.compose.foundation.layout.WindowInsets
1617
import androidx.compose.foundation.layout.WindowInsetsSides
1718
import androidx.compose.foundation.layout.only
@@ -24,12 +25,15 @@ import androidx.compose.material.icons.Icons
2425
import androidx.compose.material.icons.automirrored.outlined.ArrowForward
2526
import androidx.compose.material.icons.outlined.Add
2627
import androidx.compose.material.icons.outlined.FlashlightOn
28+
import androidx.compose.material3.AlertDialog
2729
import androidx.compose.material3.ExperimentalMaterial3Api
2830
import androidx.compose.material3.Scaffold
2931
import androidx.compose.material3.SnackbarDuration
3032
import androidx.compose.material3.SnackbarHost
3133
import androidx.compose.material3.SnackbarHostState
3234
import androidx.compose.material3.Surface
35+
import androidx.compose.material3.Text
36+
import androidx.compose.material3.TextButton
3337
import androidx.compose.material3.TopAppBarDefaults
3438
import androidx.compose.material3.rememberModalBottomSheetState
3539
import androidx.compose.runtime.Composable
@@ -145,6 +149,12 @@ fun HomeKeyMapListScreen(
145149
)
146150
}
147151

152+
var showBugReportDialog by rememberSaveable { mutableStateOf(false) }
153+
154+
if (showBugReportDialog) {
155+
BugReportDialog(onDismissRequest = { showBugReportDialog = false })
156+
}
157+
148158
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
149159
val uriHandler = LocalUriHandler.current
150160
val ctx = LocalContext.current
@@ -216,6 +226,9 @@ fun HomeKeyMapListScreen(
216226
onConstraintModeChanged = viewModel::onGroupConstraintModeChanged,
217227
onFixConstraintClick = viewModel::onFixClick,
218228
onKeyMapsEnabledChange = viewModel::onGroupKeyMapsEnabledChanged,
229+
onReportBugClick = {
230+
showBugReportDialog = true
231+
},
219232
)
220233
},
221234
selectionBottomSheet = {
@@ -349,6 +362,43 @@ fun HandleImportExportState(
349362
}
350363
}
351364

365+
@Composable
366+
private fun BugReportDialog(onDismissRequest: () -> Unit) {
367+
val ctx = LocalContext.current
368+
val subject = stringResource(R.string.customer_email_subject_bug_report)
369+
370+
val discordLink = stringResource(R.string.url_discord_server_invite)
371+
val uriHandler = LocalUriHandler.current
372+
AlertDialog(
373+
onDismissRequest = onDismissRequest,
374+
title = { Text(stringResource(R.string.dialog_title_bug_report)) },
375+
text = { Text(stringResource(R.string.dialog_message_bug_report)) },
376+
confirmButton = {
377+
Row {
378+
TextButton(
379+
onClick = {
380+
ShareUtils.sendBugReportEmail(ctx, subject)
381+
},
382+
) {
383+
Text(stringResource(R.string.dialog_bug_report_email_button))
384+
}
385+
TextButton(
386+
onClick = {
387+
uriHandler.openUriSafe(ctx, discordLink)
388+
},
389+
) {
390+
Text(stringResource(R.string.dialog_bug_report_discord_button))
391+
}
392+
}
393+
},
394+
dismissButton = {
395+
TextButton(onClick = onDismissRequest) {
396+
Text(stringResource(R.string.neg_cancel))
397+
}
398+
},
399+
)
400+
}
401+
352402
@Composable
353403
private fun sampleList(): List<KeyMapListItemModel> {
354404
val context = LocalContext.current

base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListAppBar.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.compose.material.icons.automirrored.rounded.ArrowBack
3737
import androidx.compose.material.icons.automirrored.rounded.HelpOutline
3838
import androidx.compose.material.icons.automirrored.rounded.Sort
3939
import androidx.compose.material.icons.outlined.Lock
40+
import androidx.compose.material.icons.rounded.BugReport
4041
import androidx.compose.material.icons.rounded.Delete
4142
import androidx.compose.material.icons.rounded.Done
4243
import androidx.compose.material.icons.rounded.Edit
@@ -138,6 +139,7 @@ fun KeyMapListAppBar(
138139
onConstraintModeChanged: (ConstraintMode) -> Unit = {},
139140
onFixConstraintClick: (KMError) -> Unit = {},
140141
onKeyMapsEnabledChange: (Boolean) -> Unit = {},
142+
onReportBugClick: () -> Unit = {},
141143
) {
142144
BackHandler(onBack = onBackClick)
143145

@@ -170,10 +172,6 @@ fun KeyMapListAppBar(
170172
dropdownMenuContent = {
171173
RootGroupDropdownMenu(
172174
expanded = expandedDropdown,
173-
onSortClick = {
174-
expandedDropdown = false
175-
onSortClick()
176-
},
177175
onSettingsClick = {
178176
expandedDropdown = false
179177
onSettingsClick()
@@ -194,6 +192,10 @@ fun KeyMapListAppBar(
194192
expandedDropdown = false
195193
onInputMethodPickerClick()
196194
},
195+
onReportBugClick = {
196+
expandedDropdown = false
197+
onReportBugClick()
198+
},
197199
onDismissRequest = { expandedDropdown = false },
198200
)
199201
},
@@ -531,9 +533,11 @@ private fun ChildGroupAppBar(
531533
SelectedKeyMapsEnabled.ALL -> stringResource(
532534
R.string.home_enabled_key_maps_enabled,
533535
)
536+
534537
SelectedKeyMapsEnabled.MIXED -> stringResource(
535538
R.string.home_enabled_key_maps_mixed,
536539
)
540+
537541
SelectedKeyMapsEnabled.NONE, null -> stringResource(
538542
R.string.home_enabled_key_maps_disabled,
539543
)
@@ -871,12 +875,12 @@ private fun selectedTextTransition(targetState: Int, initialState: Int): Content
871875
@Composable
872876
private fun RootGroupDropdownMenu(
873877
expanded: Boolean,
874-
onSortClick: () -> Unit = {},
875878
onSettingsClick: () -> Unit = {},
876879
onAboutClick: () -> Unit = {},
877880
onExportClick: () -> Unit = {},
878881
onImportClick: () -> Unit = {},
879882
onInputMethodPickerClick: () -> Unit = {},
883+
onReportBugClick: () -> Unit = {},
880884
onDismissRequest: () -> Unit = {},
881885
) {
882886
DropdownMenu(
@@ -908,6 +912,11 @@ private fun RootGroupDropdownMenu(
908912
text = { Text(stringResource(R.string.home_menu_about)) },
909913
onClick = onAboutClick,
910914
)
915+
DropdownMenuItem(
916+
leadingIcon = { Icon(Icons.Rounded.BugReport, contentDescription = null) },
917+
text = { Text(stringResource(R.string.home_menu_report_bug)) },
918+
onClick = onReportBugClick,
919+
)
911920
}
912921
}
913922

@@ -1037,7 +1046,7 @@ private fun KeyMapsChildGroupDarkPreview() {
10371046
@Preview
10381047
@Composable
10391048
private fun KeyMapsChildGroupEditingPreview() {
1040-
val focusRequester = FocusRequester()
1049+
val focusRequester = remember { FocusRequester() }
10411050

10421051
LaunchedEffect("") {
10431052
focusRequester.requestFocus()
@@ -1075,7 +1084,7 @@ private fun KeyMapsChildGroupEditingDarkPreview() {
10751084
keyMapsEnabled = SelectedKeyMapsEnabled.ALL,
10761085
)
10771086

1078-
val focusRequester = FocusRequester()
1087+
val focusRequester = remember { FocusRequester() }
10791088

10801089
LaunchedEffect("") {
10811090
focusRequester.requestFocus()
@@ -1091,7 +1100,7 @@ private fun KeyMapsChildGroupEditingDarkPreview() {
10911100
@Preview
10921101
@Composable
10931102
private fun KeyMapsChildGroupErrorPreview() {
1094-
val focusRequester = FocusRequester()
1103+
val focusRequester = remember { FocusRequester() }
10951104

10961105
LaunchedEffect("") {
10971106
focusRequester.requestFocus()

base/src/main/java/io/github/sds100/keymapper/base/utils/ShareUtils.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,35 @@ import io.github.sds100.keymapper.base.BaseMainActivity
1414
import io.github.sds100.keymapper.base.R
1515

1616
object ShareUtils {
17+
fun sendBugReportEmail(ctx: Context, subject: String) {
18+
val body = ctx.getString(
19+
R.string.customer_email_body,
20+
Build.DEVICE,
21+
if (Build.VERSION.SDK_INT >=
22+
Build.VERSION_CODES.R
23+
) {
24+
Build.VERSION.RELEASE_OR_CODENAME
25+
} else {
26+
Build.VERSION.RELEASE
27+
},
28+
ctx.applicationContext.packageManager.getPackageInfo(ctx.packageName, 0).versionName,
29+
)
30+
31+
sendMail(
32+
ctx,
33+
email = ctx.getString(R.string.purchasing_contact_email),
34+
subject = subject,
35+
body = body,
36+
)
37+
}
38+
1739
fun sendMail(ctx: Context, email: String, subject: String, body: String) {
1840
try {
41+
// Specify the extra parameters so it works with the gmail app.
42+
val uri = "mailto:$email?subject=$subject&body=$body".toUri()
43+
1944
val intent = Intent(Intent.ACTION_SENDTO).apply {
20-
data = "mailto:$email".toUri()
45+
data = uri
2146
putExtra(Intent.EXTRA_SUBJECT, subject)
2247
putExtra(Intent.EXTRA_TEXT, body)
2348
}

base/src/main/res/values/strings.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,9 @@
13971397
<string name="purchasing_error_assistant_not_purchased_home_screen">You must purchase the side key trigger feature! Tap on the key map and then purchase it by clicking on the shop.</string>
13981398
<string name="purchasing_error_floating_buttons_not_purchased_home_screen">You must purchase the floating buttons feature! Tap on the key map and then purchase it by clicking on the shop.</string>
13991399
<string name="purchasing_contact_email" translatable="false">contact@keymapper.app</string>
1400-
<string name="customer_email_subject" translatable="false">Key Mapper Pro query</string>
1401-
<string name="customer_email_body" translatable="false">Please fill the following information so I can help you.\n\n1. Device model:\n2. Android version:\n3. Key maps (make a backup in the home screen menu):\n4. Screenshot of Key Mapper home screen:\n5. Describe the problem you are having:</string>
1400+
<string name="customer_email_subject_pro" translatable="false">Key Mapper Pro query</string>
1401+
<string name="customer_email_subject_bug_report" translatable="false">Key Mapper Bug report</string>
1402+
<string name="customer_email_body" translatable="false">Please fill the following information so I can help you.\n\n1. Device model: %s\n2. Android version: %s\n3. Key Mapper version: %s\n4, Key maps (make a backup in the home screen menu)\n6. Screenshot of Key Mapper home screen\n6. Describe the problem you are having</string>
14021403
<string name="purchase_thank_you_title">Thank you for supporting the app!</string>
14031404
<string name="purchase_thank_you_message">Your purchase was successful. As a paying user of Key\u00A0Mapper you will receive priority support to help you use the app. There is now a button in the shop to contact the developer.</string>
14041405
<string name="purchasing_not_implemented_bottom_sheet_text">The advanced triggers are paid feature but you downloaded the FOSS build of Key Mapper that does not include this closed source module or Google Play billing. Please download Key Mapper from Google Play to get access to this feature.</string>
@@ -1518,6 +1519,7 @@
15181519
<string name="home_menu_settings">Settings</string>
15191520
<string name="home_menu_delete_group">Delete group</string>
15201521
<string name="home_menu_about">About</string>
1522+
<string name="home_menu_report_bug">Report bug</string>
15211523
<string name="home_menu_export">Export all</string>
15221524
<string name="home_menu_import">Import</string>
15231525
<string name="home_menu_input_method_picker">Choose keyboard</string>
@@ -1891,5 +1893,9 @@
18911893
<string name="floating_buttons_review_card_message">We would love to know! Please consider leaving a review on Google Play to help others discover this feature. ❤️</string>
18921894
<string name="floating_buttons_review_card_dismiss">Dismiss</string>
18931895
<string name="error_write_evdev_event_failed">Write evdev event failed</string>
1896+
<string name="dialog_title_bug_report">Report bug</string>
1897+
<string name="dialog_message_bug_report">We would prefer it if you report your bug to the Discord server so other users can help you. Otherwise, you can email us at contact@keymapper.app.</string>
1898+
<string name="dialog_bug_report_discord_button">Open Discord</string>
1899+
<string name="dialog_bug_report_email_button">Email us</string>
18941900

18951901
</resources>

0 commit comments

Comments
 (0)