diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/clock/parts/MusicPartProvider.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/clock/parts/MusicPartProvider.kt index af2153ee5..379532b70 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/clock/parts/MusicPartProvider.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/clock/parts/MusicPartProvider.kt @@ -22,9 +22,12 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import de.mm20.launcher2.crashreporter.CrashReporter +import de.mm20.launcher2.ktx.sendWithBackgroundPermission import de.mm20.launcher2.music.MusicService import de.mm20.launcher2.music.PlaybackState import de.mm20.launcher2.music.SupportedActions @@ -68,8 +71,11 @@ class MusicPartProvider : PartProvider, KoinComponent { .combinedClickable( onClick = { try { - musicService.openPlayer()?.send() + musicService + .openPlayer() + ?.sendWithBackgroundPermission(context) } catch (e: PendingIntent.CanceledException) { + CrashReporter.logException(e) } }, onLongClick = { @@ -99,14 +105,17 @@ class MusicPartProvider : PartProvider, KoinComponent { painter = rememberAnimatedVectorPainter( animatedImageVector = playIcon, atEnd = state == PlaybackState.Playing - ), contentDescription = null + ), contentDescription = stringResource( + if (state == PlaybackState.Playing) R.string.music_widget_pause + else R.string.music_widget_play + ) ) } if (supportedActions.skipToNext) { IconButton(onClick = { musicService.next() }) { Icon( imageVector = Icons.Rounded.SkipNext, - contentDescription = null + contentDescription = stringResource(R.string.music_widget_next_track) ) } } @@ -122,7 +131,7 @@ class MusicPartProvider : PartProvider, KoinComponent { .combinedClickable( onClick = { try { - musicService.openPlayer()?.send() + musicService.openPlayer()?.sendWithBackgroundPermission(context) } catch (e: PendingIntent.CanceledException) { } }, @@ -156,7 +165,7 @@ class MusicPartProvider : PartProvider, KoinComponent { IconButton(onClick = { musicService.previous() }) { Icon( imageVector = Icons.Rounded.SkipPrevious, - contentDescription = null + contentDescription = stringResource(R.string.music_widget_previous_track) ) } } @@ -165,14 +174,17 @@ class MusicPartProvider : PartProvider, KoinComponent { painter = rememberAnimatedVectorPainter( animatedImageVector = playIcon, atEnd = state == PlaybackState.Playing - ), contentDescription = null + ), contentDescription = stringResource( + if (state == PlaybackState.Playing) R.string.music_widget_pause + else R.string.music_widget_play + ) ) } if (supportedActions.skipToPrevious) { IconButton(onClick = { musicService.next() }) { Icon( imageVector = Icons.Rounded.SkipNext, - contentDescription = null + contentDescription = stringResource(R.string.music_widget_next_track) ) } } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidget.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidget.kt index 5e3424edd..10fe4788a 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidget.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidget.kt @@ -258,7 +258,7 @@ fun MusicWidget(widget: MusicWidget) { .clip(MaterialTheme.shapes.small) .combinedClickable( onClick = { - viewModel.openPlayer() + viewModel.openPlayer(context) }, onLongClick = { viewModel.openPlayerSelector(context) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidgetVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidgetVM.kt index 3c5f75724..39241e3f6 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidgetVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/widgets/music/MusicWidgetVM.kt @@ -7,6 +7,7 @@ import android.media.session.PlaybackState.CustomAction import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.ViewModel import de.mm20.launcher2.crashreporter.CrashReporter +import de.mm20.launcher2.ktx.sendWithBackgroundPermission import de.mm20.launcher2.music.MusicService import de.mm20.launcher2.music.PlaybackState import de.mm20.launcher2.music.SupportedActions @@ -50,9 +51,9 @@ class MusicWidgetVM: ViewModel(), KoinComponent { musicService.togglePause() } - fun openPlayer() { + fun openPlayer(context: Context) { try { - musicService.openPlayer()?.send() + musicService.openPlayer()?.sendWithBackgroundPermission(context) } catch (e: PendingIntent.CanceledException) { CrashReporter.logException(e) }