Fixed notification not dismissible on pre-A12 devices
This commit is contained in:
parent
b572fe1aee
commit
6116b4714f
2 changed files with 23 additions and 28 deletions
|
@ -116,12 +116,11 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
||||||
binding.viewPager.addOnPageChangeListener(this)
|
binding.viewPager.addOnPageChangeListener(this)
|
||||||
val nps = PreferenceUtil.nowPlayingScreen
|
val nps = PreferenceUtil.nowPlayingScreen
|
||||||
|
|
||||||
val metrics = resources.displayMetrics
|
|
||||||
val ratio = metrics.heightPixels.toFloat() / metrics.widthPixels.toFloat()
|
|
||||||
|
|
||||||
if (nps == Full || nps == Classic || nps == Fit || nps == Gradient) {
|
if (nps == Full || nps == Classic || nps == Fit || nps == Gradient) {
|
||||||
binding.viewPager.offscreenPageLimit = 2
|
binding.viewPager.offscreenPageLimit = 2
|
||||||
} else if (PreferenceUtil.isCarouselEffect) {
|
} else if (PreferenceUtil.isCarouselEffect) {
|
||||||
|
val metrics = resources.displayMetrics
|
||||||
|
val ratio = metrics.heightPixels.toFloat() / metrics.widthPixels.toFloat()
|
||||||
binding.viewPager.clipToPadding = false
|
binding.viewPager.clipToPadding = false
|
||||||
val padding =
|
val padding =
|
||||||
if (ratio >= 1.777f) {
|
if (ratio >= 1.777f) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import android.support.v4.media.session.PlaybackStateCompat
|
||||||
import android.telephony.PhoneStateListener
|
import android.telephony.PhoneStateListener
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.media.AudioAttributesCompat
|
import androidx.media.AudioAttributesCompat
|
||||||
|
@ -57,7 +58,6 @@ import code.name.monkey.retromusic.extensions.showToast
|
||||||
import code.name.monkey.retromusic.glide.BlurTransformation
|
import code.name.monkey.retromusic.glide.BlurTransformation
|
||||||
import code.name.monkey.retromusic.glide.GlideApp
|
import code.name.monkey.retromusic.glide.GlideApp
|
||||||
import code.name.monkey.retromusic.glide.RetroGlideExtension.getSongModel
|
import code.name.monkey.retromusic.glide.RetroGlideExtension.getSongModel
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.isCasting
|
|
||||||
import code.name.monkey.retromusic.helper.ShuffleHelper.makeShuffleList
|
import code.name.monkey.retromusic.helper.ShuffleHelper.makeShuffleList
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.model.Song.Companion.emptySong
|
import code.name.monkey.retromusic.model.Song.Companion.emptySong
|
||||||
|
@ -90,7 +90,6 @@ import code.name.monkey.retromusic.util.PreferenceUtil.unregisterOnSharedPrefere
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
||||||
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
||||||
import com.bumptech.glide.RequestBuilder
|
|
||||||
import com.bumptech.glide.request.target.SimpleTarget
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import org.koin.java.KoinJavaComponent.get
|
import org.koin.java.KoinJavaComponent.get
|
||||||
|
@ -303,7 +302,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
HandlerThread("QueueSaveHandler", Process.THREAD_PRIORITY_BACKGROUND)
|
HandlerThread("QueueSaveHandler", Process.THREAD_PRIORITY_BACKGROUND)
|
||||||
queueSaveHandlerThread?.start()
|
queueSaveHandlerThread?.start()
|
||||||
queueSaveHandler = QueueSaveHandler(this, queueSaveHandlerThread!!.looper)
|
queueSaveHandler = QueueSaveHandler(this, queueSaveHandlerThread!!.looper)
|
||||||
uiThreadHandler = Handler()
|
uiThreadHandler = Handler(Looper.getMainLooper())
|
||||||
registerReceiver(widgetIntentReceiver, IntentFilter(APP_WIDGET_UPDATE))
|
registerReceiver(widgetIntentReceiver, IntentFilter(APP_WIDGET_UPDATE))
|
||||||
registerReceiver(updateFavoriteReceiver, IntentFilter(FAVORITE_STATE_CHANGED))
|
registerReceiver(updateFavoriteReceiver, IntentFilter(FAVORITE_STATE_CHANGED))
|
||||||
registerReceiver(lockScreenReceiver, IntentFilter(Intent.ACTION_SCREEN_OFF))
|
registerReceiver(lockScreenReceiver, IntentFilter(Intent.ACTION_SCREEN_OFF))
|
||||||
|
@ -698,9 +697,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
val progress = songProgressMillis
|
val progress = songProgressMillis
|
||||||
val wasPlaying = isPlaying
|
val wasPlaying = isPlaying
|
||||||
/* Switch to MultiPlayer if Crossfade duration is 0 and
|
/* Switch to MultiPlayer if Crossfade duration is 0 and
|
||||||
Playback is not an instance of MultiPlayer */if (playback != null) playback?.setCrossFadeDuration(
|
Playback is not an instance of MultiPlayer */
|
||||||
crossFadeDuration
|
|
||||||
)
|
|
||||||
if (playback !is MultiPlayer && crossFadeDuration == 0) {
|
if (playback !is MultiPlayer && crossFadeDuration == 0) {
|
||||||
if (playback != null) {
|
if (playback != null) {
|
||||||
playback?.release()
|
playback?.release()
|
||||||
|
@ -728,6 +725,9 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (playback != null) playback?.setCrossFadeDuration(
|
||||||
|
crossFadeDuration
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData()
|
ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData()
|
||||||
COLORED_NOTIFICATION -> {
|
COLORED_NOTIFICATION -> {
|
||||||
|
@ -1130,24 +1130,21 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
val metaData = MediaMetadataCompat.Builder()
|
val metaData = MediaMetadataCompat.Builder()
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName)
|
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName)
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artistName)
|
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.albumArtist)
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName)
|
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName)
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title)
|
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title)
|
||||||
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration)
|
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration)
|
||||||
.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, (getPosition() + 1).toLong())
|
.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, (getPosition() + 1).toLong())
|
||||||
.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year.toLong())
|
.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year.toLong())
|
||||||
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null)
|
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null)
|
||||||
metaData.putLong(
|
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, playingQueue.size.toLong())
|
||||||
MediaMetadataCompat.METADATA_KEY_NUM_TRACKS,
|
|
||||||
playingQueue.size.toLong()
|
|
||||||
)
|
|
||||||
if (isAlbumArtOnLockScreen) {
|
if (isAlbumArtOnLockScreen) {
|
||||||
val screenSize = RetroUtil.getScreenSize(this@MusicService)
|
val screenSize = RetroUtil.getScreenSize(this@MusicService)
|
||||||
val request: RequestBuilder<Bitmap> =
|
val request = GlideApp.with(this@MusicService)
|
||||||
GlideApp.with(this@MusicService)
|
.asBitmap()
|
||||||
.asBitmap()
|
.songCoverOptions(song)
|
||||||
.songCoverOptions(song)
|
.load(getSongModel(song))
|
||||||
.load(getSongModel(song))
|
|
||||||
if (isBlurredAlbumArt) {
|
if (isBlurredAlbumArt) {
|
||||||
request.transform(BlurTransformation.Builder(this@MusicService).build())
|
request.transform(BlurTransformation.Builder(this@MusicService).build())
|
||||||
}
|
}
|
||||||
|
@ -1240,17 +1237,16 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
private fun startForegroundOrNotify() {
|
private fun startForegroundOrNotify() {
|
||||||
if (playingNotification != null && currentSong.id != -1L) {
|
if (playingNotification != null && currentSong.id != -1L) {
|
||||||
if (!VersionUtils.hasS()) {
|
if (isForeground && !isPlaying) {
|
||||||
if (isForeground && !isPlaying) {
|
// This makes the notification dismissible
|
||||||
// This makes the notification dismissible
|
// We can't call stopForeground(false) on A12 though, which may result in crashes
|
||||||
// We can't call stopForeground(false) on A12 though, which may result in crashes
|
// when we call startForeground after that e.g. when Alarm goes off,
|
||||||
// when we call startForeground after that e.g. when Alarm goes off
|
if (!VersionUtils.hasS()) {
|
||||||
|
|
||||||
stopForeground(false)
|
stopForeground(false)
|
||||||
isForeground = false
|
isForeground = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isForeground) {
|
if (!isForeground && isPlaying) {
|
||||||
// Specify that this is a media service, if supported.
|
// Specify that this is a media service, if supported.
|
||||||
if (VersionUtils.hasQ()) {
|
if (VersionUtils.hasQ()) {
|
||||||
startForeground(
|
startForeground(
|
||||||
|
@ -1311,10 +1307,10 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
openQueue(playlistSongs, 0, true)
|
openQueue(playlistSongs, 0, true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showToast( R.string.playlist_is_empty)
|
showToast(R.string.playlist_is_empty, Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showToast(R.string.playlist_is_empty)
|
showToast(R.string.playlist_is_empty, Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue