Skip to content

Commit 0c5f046

Browse files
committed
Update current pending intents
1 parent 2f00dcb commit 0c5f046

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/android/intents/IntentBuilder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class IntentBuilder(private val context: Context) : BuildIntents {
3232
override fun buildLibrarySettingsIntent(libraryId: LibraryId): Intent = getBrowserActivityIntent(ConnectionSettingsScreen(libraryId))
3333
override fun buildLibraryServerSettingsPendingIntent(libraryId: LibraryId): PendingIntent {
3434
val baseIntent = buildLibrarySettingsIntent(libraryId)
35-
return PendingIntent.getActivity(context, 0, baseIntent, 0.makePendingIntentImmutable())
35+
return PendingIntent.getActivity(context, 0, baseIntent, PendingIntent.FLAG_UPDATE_CURRENT.makePendingIntentImmutable())
3636
}
3737

3838
@OptIn(UnstableApi::class)
@@ -45,15 +45,15 @@ class IntentBuilder(private val context: Context) : BuildIntents {
4545

4646
override fun buildPendingNowPlayingIntent(libraryId: LibraryId): PendingIntent {
4747
val intent = buildNowPlayingIntent(libraryId)
48-
return PendingIntent.getActivity(context, 0, intent, 0.makePendingIntentImmutable())
48+
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT.makePendingIntentImmutable())
4949
}
5050

5151
@OptIn(UnstableApi::class)
5252
override fun buildPendingPausePlaybackIntent(): PendingIntent = PlaybackService.pendingPauseIntent(context)
5353

5454
override fun buildPendingShowDownloadsIntent(): PendingIntent {
5555
val baseIntent = buildShowDownloadsIntent()
56-
return PendingIntent.getActivity(context, 0, baseIntent, 0.makePendingIntentImmutable())
56+
return PendingIntent.getActivity(context, 0, baseIntent, PendingIntent.FLAG_UPDATE_CURRENT.makePendingIntentImmutable())
5757
}
5858

5959
private fun buildShowDownloadsIntent(): Intent = getBrowserActivityIntent(ActiveLibraryDownloadsScreen)

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/navigation/BrowserDestinations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sealed interface LibraryDestination : Destination {
3535
class ConnectionSettingsScreen(override val libraryId: LibraryId) : LibraryDestination
3636

3737
@Parcelize
38-
class NowPlayingScreen(override val libraryId: LibraryId) : LibraryDestination
38+
data class NowPlayingScreen(override val libraryId: LibraryId) : LibraryDestination
3939

4040
@Parcelize
4141
class ListedFileDetailsScreen(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.lasthopesoftware.bluewater.client.playback.nowplaying.intent.GivenTheActiveLibraryIdChanges
2+
3+
import android.content.Intent
4+
import androidx.test.core.app.ApplicationProvider
5+
import com.lasthopesoftware.AndroidContext
6+
import com.lasthopesoftware.bluewater.android.intents.IntentBuilder
7+
import com.lasthopesoftware.bluewater.android.intents.safelyGetParcelableExtra
8+
import com.lasthopesoftware.bluewater.client.browsing.library.repository.LibraryId
9+
import com.lasthopesoftware.bluewater.client.browsing.navigation.NowPlayingScreen
10+
import com.lasthopesoftware.bluewater.client.destinationProperty
11+
import org.assertj.core.api.Assertions.assertThat
12+
import org.junit.Test
13+
import org.robolectric.Shadows
14+
15+
class WhenBuildingTheNowPlayingIntent : AndroidContext() {
16+
companion object {
17+
private var returnedIntent: Intent? = null
18+
}
19+
20+
override fun before() {
21+
val intentBuilder = IntentBuilder(ApplicationProvider.getApplicationContext())
22+
intentBuilder.buildPendingNowPlayingIntent(LibraryId(559))
23+
val pendingIntent = intentBuilder.buildPendingNowPlayingIntent(LibraryId(844))
24+
val shadow = Shadows.shadowOf(pendingIntent)
25+
returnedIntent = shadow.savedIntent
26+
}
27+
28+
@Test
29+
fun `then the returned intent has the correct library`() {
30+
assertThat(returnedIntent?.safelyGetParcelableExtra<NowPlayingScreen>(destinationProperty)).isEqualTo(
31+
NowPlayingScreen(
32+
LibraryId(844)
33+
)
34+
)
35+
}
36+
}

0 commit comments

Comments
 (0)