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.
This commit is contained in:
OxygenCobalt
2022-06-16 15:35:16 -06:00
parent f187900d0c
commit cf8e887f9a
5 changed files with 16 additions and 14 deletions
@@ -245,11 +245,12 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), 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
}
@@ -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
}
}
@@ -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) }
}
+1 -1
View File
@@ -54,7 +54,7 @@
<string name="lbl_relative_path">Parent path</string>
<string name="lbl_format">Format</string>
<string name="lbl_size">Size</string>
<string name="lbl_bitrate">Bitrate</string>
<string name="lbl_bitrate">Bit rate</string>
<string name="lbl_sample_rate">Sample rate</string>
<string name="lbl_state_saved">State saved</string>