Fix compatibility

Do some minor compatibility fixes for older versions of android.
This commit is contained in:
OxygenCobalt 2020-11-02 19:58:11 -07:00
parent 188d7e047f
commit 1cab11ba9c
3 changed files with 29 additions and 23 deletions

View file

@ -11,12 +11,8 @@ import org.oxycblt.auxio.theme.accent
// FIXME: Fix bug where fast navigation will break the animations and
// lead to nothing being displayed [Possibly Un-fixable]
// TODO: Test for compatibility
// API 30 - No Issues
// API 29 - No Issues [Primary Testing Version]
// API 28-23 - Not tested yet
// API 22 - ProgressBar/SeekBar look wonky, RecyclerView dividers don't show
// API 21 - Not tested yet
// FIXME: Compat issues with Versions 5/6 that cause recyclerview
// dividers not to show and for progress bars to look wonky
class MainActivity : AppCompatActivity(R.layout.activity_main) {
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {

View file

@ -19,6 +19,8 @@ import org.oxycblt.auxio.playback.state.PlaybackMode
import org.oxycblt.auxio.playback.state.PlaybackStateManager
object NotificationUtils {
val DO_COMPAT_SUBTEXT = Build.VERSION.SDK_INT < Build.VERSION_CODES.O
const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK"
const val NOTIFICATION_ID = 0xA0A0
const val REQUEST_CODE = 0xA0C0
@ -70,7 +72,6 @@ fun NotificationManager.createMediaNotification(
.addAction(newAction(NotificationUtils.ACTION_SKIP_NEXT, context))
.addAction(newAction(NotificationUtils.ACTION_EXIT, context))
.setNotificationSilent()
.setSubText(context.getString(R.string.title_playback))
.setContentIntent(mainIntent)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
}
@ -81,6 +82,14 @@ fun NotificationCompat.Builder.setMetadata(song: Song, context: Context, onDone:
song.album.artist.name,
)
// On older versions of android [API <26], show the song's album on the subtext instead of
// the current mode, as that makes more sense for the old style of media notifications.
if (NotificationUtils.DO_COMPAT_SUBTEXT) {
setSubText(song.album.name)
}
// getBitmap() is concurrent, so only call back to the object calling this function when
// the loading is over.
getBitmap(song, context) {
setLargeIcon(it)
@ -98,15 +107,16 @@ fun NotificationCompat.Builder.updateLoop(context: Context) {
mActions[0] = newAction(NotificationUtils.ACTION_LOOP, context)
}
@SuppressLint("RestrictedApi")
fun NotificationCompat.Builder.updateMode(context: Context) {
val playbackManager = PlaybackStateManager.getInstance()
if (!NotificationUtils.DO_COMPAT_SUBTEXT) {
val playbackManager = PlaybackStateManager.getInstance()
// If the mode is ALL_SONGS, then just put a string, otherwise put the parent model's name.
if (playbackManager.mode == PlaybackMode.ALL_SONGS) {
setSubText(context.getString(R.string.title_all_songs))
} else {
setSubText(playbackManager.parent!!.name)
// If the mode is ALL_SONGS, then just put a string, otherwise put the parent model's name.
if (playbackManager.mode == PlaybackMode.ALL_SONGS) {
setSubText(context.getString(R.string.title_all_songs))
} else {
setSubText(playbackManager.parent!!.name)
}
}
}

View file

@ -102,10 +102,14 @@ class PlaybackStateManager private constructor() {
val musicStore = MusicStore.getInstance()
mMode = mode
mParent = when (mode) {
PlaybackMode.ALL_SONGS -> null
PlaybackMode.IN_ARTIST -> song.album.artist
PlaybackMode.IN_ALBUM -> song.album
PlaybackMode.IN_GENRE -> error("what")
}
resetLoopMode()
updatePlayback(song)
mMode = mode
mQueue = when (mode) {
PlaybackMode.ALL_SONGS -> musicStore.songs.toMutableList()
@ -114,12 +118,8 @@ class PlaybackStateManager private constructor() {
PlaybackMode.IN_GENRE -> error("what")
}
mParent = when (mode) {
PlaybackMode.ALL_SONGS -> null
PlaybackMode.IN_ARTIST -> song.album.artist
PlaybackMode.IN_ALBUM -> song.album
PlaybackMode.IN_GENRE -> error("what")
}
resetLoopMode()
updatePlayback(song)
if (mIsShuffling) {
genShuffle(true)