Fixed Circle widget

This commit is contained in:
Prathamesh More 2022-02-17 20:06:55 +05:30
parent 0aa4017146
commit e827acea83
2 changed files with 17 additions and 12 deletions

View file

@ -14,7 +14,7 @@ android {
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic" applicationId "code.name.monkey.retromusic"
versionCode 10565 versionCode 10567
versionName '5.7.2' versionName '5.7.2'
buildConfigField("String", "GOOGLE_PLAY_LICENSING_KEY", "\"${getProperty(getProperties('../public.properties'), 'GOOGLE_PLAY_LICENSE_KEY')}\"") buildConfigField("String", "GOOGLE_PLAY_LICENSING_KEY", "\"${getProperty(getProperties('../public.properties'), 'GOOGLE_PLAY_LICENSE_KEY')}\"")

View file

@ -124,6 +124,7 @@ class MusicService : MediaBrowserServiceCompat(),
private val appWidgetSmall = AppWidgetSmall.instance private val appWidgetSmall = AppWidgetSmall.instance
private val appWidgetText = AppWidgetText.instance private val appWidgetText = AppWidgetText.instance
private val appWidgetMd3 = AppWidgetMD3.instance private val appWidgetMd3 = AppWidgetMD3.instance
private val appWidgetCircle = AppWidgetCircle.instance
private val widgetIntentReceiver: BroadcastReceiver = object : BroadcastReceiver() { private val widgetIntentReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val command = intent.getStringExtra(EXTRA_APP_WIDGET_NAME) val command = intent.getStringExtra(EXTRA_APP_WIDGET_NAME)
@ -148,6 +149,9 @@ class MusicService : MediaBrowserServiceCompat(),
AppWidgetMD3.NAME -> { AppWidgetMD3.NAME -> {
appWidgetMd3.performUpdate(this@MusicService, ids) appWidgetMd3.performUpdate(this@MusicService, ids)
} }
AppWidgetCircle.NAME -> {
appWidgetCircle.performUpdate(this@MusicService, ids)
}
} }
} }
} }
@ -186,15 +190,15 @@ class MusicService : MediaBrowserServiceCompat(),
} }
} }
private var playerHandler: PlaybackHandler? = null private var playerHandler: PlaybackHandler? = null
private val audioFocusListener: OnAudioFocusChangeListener = private val audioFocusListener = OnAudioFocusChangeListener { focusChange ->
OnAudioFocusChangeListener { focusChange -> playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget()
playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget() }
}
private var playingNotification: PlayingNotification? = null private var playingNotification: PlayingNotification? = null
private val updateFavoriteReceiver: BroadcastReceiver = object : BroadcastReceiver() { private val updateFavoriteReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() } playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() }
startForegroundOrNotify() startForegroundOrNotify()
appWidgetCircle.notifyChange(this@MusicService, FAVORITE_STATE_CHANGED)
} }
} }
private val lockScreenReceiver: BroadcastReceiver = object : BroadcastReceiver() { private val lockScreenReceiver: BroadcastReceiver = object : BroadcastReceiver() {
@ -505,11 +509,11 @@ class MusicService : MediaBrowserServiceCompat(),
var newPosition = getPosition() - 1 var newPosition = getPosition() - 1
when (repeatMode) { when (repeatMode) {
REPEAT_MODE_ALL -> if (newPosition < 0) { REPEAT_MODE_ALL -> if (newPosition < 0) {
newPosition = getPlayingQueue().size - 1 newPosition = playingQueue.size - 1
} }
REPEAT_MODE_THIS -> if (force) { REPEAT_MODE_THIS -> if (force) {
if (newPosition < 0) { if (newPosition < 0) {
newPosition = getPlayingQueue().size - 1 newPosition = playingQueue.size - 1
} }
} else { } else {
newPosition = getPosition() newPosition = getPosition()
@ -552,9 +556,9 @@ class MusicService : MediaBrowserServiceCompat(),
val currentSongId = Objects.requireNonNull(currentSong).id val currentSongId = Objects.requireNonNull(currentSong).id
playingQueue = ArrayList(originalPlayingQueue) playingQueue = ArrayList(originalPlayingQueue)
var newPosition = 0 var newPosition = 0
for (song in getPlayingQueue()) { for (song in playingQueue) {
if (song.id == currentSongId) { if (song.id == currentSongId) {
newPosition = getPlayingQueue().indexOf(song) newPosition = playingQueue.indexOf(song)
} }
} }
position = newPosition position = newPosition
@ -565,8 +569,8 @@ class MusicService : MediaBrowserServiceCompat(),
} }
private fun getSongAt(position: Int): Song { private fun getSongAt(position: Int): Song {
return if ((position >= 0) && (position < getPlayingQueue().size)) { return if ((position >= 0) && (position < playingQueue.size)) {
getPlayingQueue()[position] playingQueue[position]
} else { } else {
emptySong emptySong
} }
@ -1137,7 +1141,7 @@ class MusicService : MediaBrowserServiceCompat(),
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null)
metaData.putLong( metaData.putLong(
MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, MediaMetadataCompat.METADATA_KEY_NUM_TRACKS,
getPlayingQueue().size.toLong() playingQueue.size.toLong()
) )
if (isAlbumArtOnLockScreen) { if (isAlbumArtOnLockScreen) {
val screenSize = RetroUtil.getScreenSize(this@MusicService) val screenSize = RetroUtil.getScreenSize(this@MusicService)
@ -1391,6 +1395,7 @@ class MusicService : MediaBrowserServiceCompat(),
appWidgetCard.notifyChange(this, what) appWidgetCard.notifyChange(this, what)
appWidgetText.notifyChange(this, what) appWidgetText.notifyChange(this, what)
appWidgetMd3.notifyChange(this, what) appWidgetMd3.notifyChange(this, what)
appWidgetCircle.notifyChange(this, what)
} }
private fun setCustomAction(stateBuilder: PlaybackStateCompat.Builder) { private fun setCustomAction(stateBuilder: PlaybackStateCompat.Builder) {