Skip to content

Commit

Permalink
chore(capabilities): Revamp System (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz authored Sep 19, 2023
1 parent 35446d7 commit ab58f87
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.doublesymmetry.kotlinaudio.models.AudioPlayerState
import com.doublesymmetry.kotlinaudio.models.CapabilitiesConfig
import com.doublesymmetry.kotlinaudio.models.Capability
import com.doublesymmetry.kotlinaudio.models.DefaultAudioItem
import com.doublesymmetry.kotlinaudio.models.MediaSessionCallback
import com.doublesymmetry.kotlinaudio.models.MediaType
import com.doublesymmetry.kotlinaudio.models.NotificationButton
import com.doublesymmetry.kotlinaudio.models.NotificationConfig
import com.doublesymmetry.kotlinaudio.models.NofiticationActionOptions
import com.doublesymmetry.kotlinaudio.models.NotificationOptions
import com.doublesymmetry.kotlinaudio.models.RepeatMode
import com.doublesymmetry.kotlinaudio.models.PlayerConfig
import com.doublesymmetry.kotlinaudio.players.QueuedAudioPlayer
import com.example.kotlin_audio_example.ui.component.ActionBottomSheet
import com.example.kotlin_audio_example.ui.component.PlayerControls
import com.example.kotlin_audio_example.ui.component.TrackDisplay
import com.example.kotlin_audio_example.ui.theme.KotlinAudioTheme
import com.google.android.exoplayer2.ui.R
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand Down Expand Up @@ -160,15 +163,21 @@ class MainActivity : ComponentActivity() {
}

private fun setupNotification() {
val notificationConfig = NotificationConfig(
listOf(
NotificationButton.PLAY_PAUSE(),
NotificationButton.NEXT(isCompact = true),
NotificationButton.PREVIOUS(isCompact = true),
NotificationButton.SEEK_TO
), accentColor = null, smallIcon = null, pendingIntent = null
val capabilitiesConfig = CapabilitiesConfig(
capabilities = listOf(
Capability.PlayPause(),
Capability.Next(),
Capability.Previous(),
Capability.Forward(notificationOptions = NofiticationActionOptions(isCompact = false)),
Capability.Backward(notificationOptions = NofiticationActionOptions(isCompact = false, icon = R.drawable.exo_icon_circular_play)),
Capability.SeekTo
),
notificationOptions = NotificationOptions(
accentColor = null, smallIcon = null, pendingIntent = null
)
)
player.notificationManager.createNotification(notificationConfig)

player.notificationManager.createNotification(capabilitiesConfig)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
package com.doublesymmetry.kotlinaudio.models

enum class Capability {
PLAY,
PLAY_FROM_ID,
PLAY_FROM_SEARCH,
PAUSE,
STOP,
SEEK_TO,
SKIP,
SKIP_TO_NEXT,
SKIP_TO_PREVIOUS,
JUMP_FORWARD,
JUMP_BACKWARD,
SET_RATING,
LIKE,
DISLIKE,
BOOKMARK
/**
* Defines the capabilities supported by the media session and whether they're also supported by the notification.
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showPlayPauseButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showStopButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showRewindButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showRewindButtonCompact]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showForwardButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showForwardButtonCompact]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showNextButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showNextButtonCompact]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showPreviousButton]
* @see [com.doublesymmetry.kotlinaudio.notification.NotificationManager.showPreviousButtonCompact]
*/
sealed class Capability(open val showInNotification: Boolean = true) {
data class PlayPause(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationPlayPauseActionOptions = NofiticationPlayPauseActionOptions.DEFAULT
) : Capability()

object PlayFromId : Capability(showInNotification = false)

object PlayFromSearch : Capability(showInNotification = false)

data class Stop(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationIconActionOptions? = null
) : Capability()

object SeekTo : Capability(showInNotification = false)

object Skip : Capability(showInNotification = false)

data class Next(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationActionOptions = NofiticationActionOptions.DEFAULT
) : Capability()

data class Previous(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationActionOptions = NofiticationActionOptions.DEFAULT
) : Capability()

data class Forward(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationActionOptions = NofiticationActionOptions.DEFAULT
) : Capability()

data class Backward(
override val showInNotification: Boolean = true,
val notificationOptions: NofiticationActionOptions = NofiticationActionOptions.DEFAULT
) : Capability()

data class SetRating(val type: Int) : Capability(showInNotification = false)
}


data class CapabilitiesConfig(
val capabilities: List<Capability>,
val notificationOptions: NotificationOptions,
)

/** Custom extension to filter out only those capabilities that are supported by the notification */
fun List<Capability>.filterForNotification(): List<Capability> {
return this.filter { it.showInNotification }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.doublesymmetry.kotlinaudio.models

import android.app.PendingIntent
import androidx.annotation.DrawableRes

/**
* Used to configure the player notification.
* @param accentColor The accent color of the notification.
* @param smallIcon The small icon of the notification which is also shown in the system status bar.
* @param pendingIntent The [PendingIntent] that would be called when tapping on the notification itself.
*/
data class NotificationOptions(
val accentColor: Int? = null,
@DrawableRes val smallIcon: Int? = null,
val pendingIntent: PendingIntent? = null
)

/** Used to configure the properties of a standard notification button */
data class NofiticationActionOptions(
@DrawableRes val icon: Int? = null,
val isCompact: Boolean = false
) {
companion object {
val DEFAULT = NofiticationActionOptions(isCompact = true)
}
}

/** Used to configure the properties of a standard notification button */
data class NofiticationIconActionOptions(
@DrawableRes val icon: Int? = null,
)

/** Used to configure the properties of a standard notification button */
data class NofiticationPlayPauseActionOptions(
@DrawableRes val playIcon: Int? = null,
@DrawableRes var pauseIcon: Int? = null,
val isCompact: Boolean = false
) {
companion object {
val DEFAULT = NofiticationPlayPauseActionOptions(isCompact = true)
}
}
Loading

0 comments on commit ab58f87

Please sign in to comment.