From cf8e887f9a259367689bfc1a3beb01b0077529c6 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Thu, 16 Jun 2022 15:35:16 -0600 Subject: [PATCH] all: use compat when stopping foreground services Use ServiceCompat.stopForeground instead of stopForeground. This is preliminary preparation for Android 13. I can only change SDK versions however when the Android Gradle Plugin makes a new release though. --- CHANGELOG.md | 15 +++++++-------- .../java/org/oxycblt/auxio/home/HomeFragment.kt | 5 +++-- .../org/oxycblt/auxio/music/IndexerService.kt | 3 ++- .../auxio/playback/system/PlaybackService.kt | 5 +++-- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a7a943b..12897d40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,18 +3,17 @@ ## v2.4.0 #### What's New -- Excluded directories has been revampled into "Music folders" +- Excluded directories has been revamped into "Music folders" - Folders on external drives can now be excluded [#134] - Added new "Include" option to restrict indexing to a particular folder [#154] -- Added a new view for song properties (Such as Bitrate) -- The playback bar now has a new design, with an improved progress indicator and a - skip action +- Added a new view for song properties (Such as Bitrate) [#144] +- The playback bar now has a new design, with an improved progress indicator and a skip action #### What's Improved - The toolbar in the home UI now collapses when scrolling - The toolbar layout is now consistent with Material Design 3 - Genre parsing now handles multiple integer values and cover/remix indicators (May wipe playback state) -- "Rounded album covers" option is no longer dependent on "Show album covers" option +- "Rounded album covers" option is no longer dependent on "Show album covers" option [#152] - Added song actions to the playback panel - Playback controls are now easier to reach when gesture navigation is enabled - Added Play Next/Add to Queue options to artists and genres @@ -25,12 +24,12 @@ - Playback bar now picks the larger inset in case that gesture inset is missing [#149] - Fixed unusable excluded directory UI - Songs with no data (i.e size of 0) are now filtered out -- Fixed non-sensical menu items from appearing on songs -- Fixed issue where multiple menus would open if long-clicks occured simultaniously +- Fixed nonsensical menu items from appearing on songs +- Fixed issue where multiple menus would open if long-clicks occured simultaneously #### Dev/Meta - New translations [Fjuro -> Czech, Konstantin Tutsch -> German] -- Moved music loading to a foreground service +- Moved music loading to a foreground service [#72] - Phased out `ImageButton` for `MaterialButton` - Unified icon sizing - Properly handle volumes throughout the entire music loading process diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt index 250eea1c4..9a36d6b10 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt @@ -245,11 +245,12 @@ class HomeFragment : ViewBindingFragment(), Toolbar.OnMenuI } private fun updateSortMenu(displayMode: DisplayMode, isVisible: (Int) -> Boolean) { - val sortItem = requireNotNull(sortItem) { "Cannot update sort menu while detached" } + val sortMenu = + requireNotNull(sortItem?.subMenu) { "Cannot update sort menu while detached" } val toHighlight = homeModel.getSortForDisplay(displayMode) - for (option in sortItem.subMenu) { + for (option in sortMenu) { if (option.itemId == toHighlight.itemId) { option.isChecked = true } diff --git a/app/src/main/java/org/oxycblt/auxio/music/IndexerService.kt b/app/src/main/java/org/oxycblt/auxio/music/IndexerService.kt index f9fb1ec68..13cee699e 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/IndexerService.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/IndexerService.kt @@ -25,6 +25,7 @@ import android.content.Intent import android.os.Build import android.os.IBinder import androidx.core.app.NotificationCompat +import androidx.core.app.ServiceCompat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -136,7 +137,7 @@ class IndexerService : Service(), Indexer.Callback { private fun stopForegroundSession() { if (isForeground) { - stopForeground(true) + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) isForeground = false } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt index 5391e06b4..47d7fe5fd 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt @@ -24,6 +24,7 @@ import android.content.Intent import android.content.IntentFilter import android.media.AudioManager import android.os.IBinder +import androidx.core.app.ServiceCompat import com.google.android.exoplayer2.C import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.MediaItem @@ -159,7 +160,7 @@ class PlaybackService : override fun onDestroy() { super.onDestroy() - stopForeground(true) + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) isForeground = false // Pause just in case this destruction was unexpected. @@ -356,7 +357,7 @@ class PlaybackService : /** Stop the foreground state and hide the notification */ private fun stopAndSave() { - stopForeground(true) + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) isForeground = false saveScope.launch { playbackManager.saveState(this@PlaybackService) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 86669af8b..92a967384 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,7 +54,7 @@ Parent path Format Size - Bitrate + Bit rate Sample rate State saved