From e827acea8385e4b0ba6b0f4923507491752963d8 Mon Sep 17 00:00:00 2001 From: Prathamesh More Date: Thu, 17 Feb 2022 20:06:55 +0530 Subject: [PATCH] Fixed Circle widget --- app/build.gradle | 2 +- .../monkey/retromusic/service/MusicService.kt | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6818156d0..ba63953b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { vectorDrawables.useSupportLibrary = true applicationId "code.name.monkey.retromusic" - versionCode 10565 + versionCode 10567 versionName '5.7.2' buildConfigField("String", "GOOGLE_PLAY_LICENSING_KEY", "\"${getProperty(getProperties('../public.properties'), 'GOOGLE_PLAY_LICENSE_KEY')}\"") diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt index 61e792a6c..1a4a02744 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt @@ -124,6 +124,7 @@ class MusicService : MediaBrowserServiceCompat(), private val appWidgetSmall = AppWidgetSmall.instance private val appWidgetText = AppWidgetText.instance private val appWidgetMd3 = AppWidgetMD3.instance + private val appWidgetCircle = AppWidgetCircle.instance private val widgetIntentReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val command = intent.getStringExtra(EXTRA_APP_WIDGET_NAME) @@ -148,6 +149,9 @@ class MusicService : MediaBrowserServiceCompat(), AppWidgetMD3.NAME -> { 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 val audioFocusListener: OnAudioFocusChangeListener = - OnAudioFocusChangeListener { focusChange -> - playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget() - } + private val audioFocusListener = OnAudioFocusChangeListener { focusChange -> + playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget() + } private var playingNotification: PlayingNotification? = null private val updateFavoriteReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() } startForegroundOrNotify() + appWidgetCircle.notifyChange(this@MusicService, FAVORITE_STATE_CHANGED) } } private val lockScreenReceiver: BroadcastReceiver = object : BroadcastReceiver() { @@ -505,11 +509,11 @@ class MusicService : MediaBrowserServiceCompat(), var newPosition = getPosition() - 1 when (repeatMode) { REPEAT_MODE_ALL -> if (newPosition < 0) { - newPosition = getPlayingQueue().size - 1 + newPosition = playingQueue.size - 1 } REPEAT_MODE_THIS -> if (force) { if (newPosition < 0) { - newPosition = getPlayingQueue().size - 1 + newPosition = playingQueue.size - 1 } } else { newPosition = getPosition() @@ -552,9 +556,9 @@ class MusicService : MediaBrowserServiceCompat(), val currentSongId = Objects.requireNonNull(currentSong).id playingQueue = ArrayList(originalPlayingQueue) var newPosition = 0 - for (song in getPlayingQueue()) { + for (song in playingQueue) { if (song.id == currentSongId) { - newPosition = getPlayingQueue().indexOf(song) + newPosition = playingQueue.indexOf(song) } } position = newPosition @@ -565,8 +569,8 @@ class MusicService : MediaBrowserServiceCompat(), } private fun getSongAt(position: Int): Song { - return if ((position >= 0) && (position < getPlayingQueue().size)) { - getPlayingQueue()[position] + return if ((position >= 0) && (position < playingQueue.size)) { + playingQueue[position] } else { emptySong } @@ -1137,7 +1141,7 @@ class MusicService : MediaBrowserServiceCompat(), .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null) metaData.putLong( MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, - getPlayingQueue().size.toLong() + playingQueue.size.toLong() ) if (isAlbumArtOnLockScreen) { val screenSize = RetroUtil.getScreenSize(this@MusicService) @@ -1391,6 +1395,7 @@ class MusicService : MediaBrowserServiceCompat(), appWidgetCard.notifyChange(this, what) appWidgetText.notifyChange(this, what) appWidgetMd3.notifyChange(this, what) + appWidgetCircle.notifyChange(this, what) } private fun setCustomAction(stateBuilder: PlaybackStateCompat.Builder) {