Skip to content

Commit 561a49e

Browse files
committed
Add Exit Soundscape option at top of main menu
At some point in the past I convince myself that this wasn't something that Android allowed. However, there have been numerous complains about how hard it is to shut down Soundscape, so here's the fix. At the top of the main menu there is now an "Exit Soundscape" button which stops the service and closes the app.
1 parent a6b3d67 commit 561a49e

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

app/src/main/java/org/scottishtecharmy/soundscape/MainActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,11 @@ class MainActivity : AppCompatActivity() {
751751
}
752752
}
753753

754+
fun exitApp() {
755+
soundscapeServiceConnection.stopService()
756+
finishAndRemoveTask()
757+
}
758+
754759
fun shareRecording() {
755760
val shareUri = soundscapeServiceConnection.soundscapeService?.getRecordingShareUri(applicationContext)
756761
if(shareUri != null) {

app/src/main/java/org/scottishtecharmy/soundscape/screens/home/DrawerContent.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.material.icons.Icons
1414
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
1515
import androidx.compose.material.icons.automirrored.rounded.Comment
1616
import androidx.compose.material.icons.automirrored.rounded.HelpOutline
17+
import androidx.compose.material.icons.automirrored.rounded.ExitToApp
1718
import androidx.compose.material.icons.rounded.Headphones
1819
import androidx.compose.material.icons.rounded.Markunread
1920
import androidx.compose.material.icons.rounded.Download
@@ -54,7 +55,8 @@ fun DrawerContent(
5455
toggleTutorial: () -> Unit,
5556
tutorialRunning: Boolean,
5657
preferences: SharedPreferences?,
57-
newReleaseDialog: MutableState<Boolean>?
58+
newReleaseDialog: MutableState<Boolean>?,
59+
exitApp: () -> Unit
5860
) {
5961
val recordingEnabled = preferences?.getBoolean(RECORD_TRAVEL_KEY, RECORD_TRAVEL_DEFAULT) == true
6062
val running = remember(tutorialRunning) { mutableStateOf(tutorialRunning) }
@@ -103,6 +105,13 @@ fun DrawerContent(
103105
.padding(innerPadding)
104106
.verticalScroll(rememberScrollState()),
105107
) {
108+
DrawerMenuItem(
109+
onClick = { exitApp() },
110+
label = stringResource(R.string.menu_exit_app),
111+
icon = Icons.AutoMirrored.Rounded.ExitToApp,
112+
modifier = Modifier.testTag("menuExitApp")
113+
)
114+
106115
// Not implemented yet
107116
// DrawerMenuItem(
108117
// onClick = { notAvailableToast() },
@@ -201,6 +210,7 @@ fun PreviewDrawerContent() {
201210
toggleTutorial = { },
202211
tutorialRunning = false,
203212
preferences = null,
204-
newReleaseDialog = null
213+
newReleaseDialog = null,
214+
exitApp = { }
205215
)
206216
}

app/src/main/java/org/scottishtecharmy/soundscape/screens/home/home/Home.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ fun Home(
120120

121121
// Memoize drawer callbacks to avoid recreating on every recomposition
122122
val shareRecording = remember { { (context as MainActivity).shareRecording() } }
123+
val exitApp = remember { { (context as MainActivity).exitApp() } }
123124
// Use rememberUpdatedState so the lambda is stable but always uses current location
124125
val currentLocation by rememberUpdatedState(state.location)
125126
val offlineMaps = remember(onNavigate) {
@@ -233,7 +234,8 @@ fun Home(
233234
toggleTutorial = toggleTutorial,
234235
tutorialRunning = tutorialRunning,
235236
preferences = preferences,
236-
newReleaseDialog = newReleaseDialog
237+
newReleaseDialog = newReleaseDialog,
238+
exitApp = exitApp
237239
)
238240
}
239241

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@
538538
<string name="menu_rate">"Rate"</string>
539539
<!-- Title for menu option to contact support by email -->
540540
<string name="menu_contact_support">"Contact support"</string>
541+
<!-- Title for menu option to exit the app completely -->
542+
<string name="menu_exit_app">"Exit Soundscape"</string>
541543
<!-- Title for menu option to go to markers and routes advanced settings screen -->
542544
<string name="menu_advanced_markers_and_routes">"Advanced Markers and Routes"</string>
543545
<!-- Text for main markers and routes advanced settings screen to explain what it's for -->

0 commit comments

Comments
 (0)