Fix compat issues

Fix some issues on older versions.
This commit is contained in:
OxygenCobalt
2020-12-19 15:43:07 -07:00
parent a443ccd508
commit d4d40c97ad
14 changed files with 48 additions and 32 deletions
@@ -41,6 +41,7 @@ import org.oxycblt.auxio.ui.setupSongActions
* search functionality.
* TODO: Move search to separate tab?
* FIXME: Leak when navving from search
* FIXME: Leak on older versions
*/
class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
@@ -19,16 +19,15 @@ import org.oxycblt.auxio.music.Song
* **Do not use this on the UI elements, instead use the Binding Adapters.**
* @param context [Context] required
* @param song Song to load the cover for
* @param onDone What to do with the bitmap when the loading is finished.
* @param onDone What to do with the bitmap when the loading is finished. Bitmap will be null if loading failed.
*/
fun getBitmap(context: Context, song: Song, onDone: (Bitmap) -> Unit) {
Coil.enqueue(
ImageRequest.Builder(context)
.data(song.album.coverUri)
.error(R.drawable.ic_song)
.target { onDone(it.toBitmap()) }
.build()
)
fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
val request = ImageRequest.Builder(context)
.data(song.album.coverUri)
.target(onError = { onDone(null) }, onSuccess = { onDone(it.toBitmap()) })
.build()
Coil.imageLoader(context).enqueue(request)
}
// --- BINDING ADAPTERS ---
@@ -97,9 +97,9 @@ fun NotificationCompat.Builder.setMetadata(
song.album.artist.name,
)
// On older versions of android [API <26], show the song's album on the subtext instead of
// On older versions of android [API <24], 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 (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
setSubText(song.album.name)
}
@@ -145,7 +145,7 @@ fun NotificationCompat.Builder.updateExtraAction(context: Context, useAltAction:
* @param context The context required to get the strings required to show certain modes
*/
fun NotificationCompat.Builder.updateMode(context: Context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val playbackManager = PlaybackStateManager.getInstance()
// If playing from all songs, set the subtext as that, otherwise the currently played parent.
@@ -237,7 +237,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
uploadMetadataToSession(it)
notification.setMetadata(this, playbackManager.song!!, settingsManager.colorizeNotif) {
notification.setMetadata(this, it, settingsManager.colorizeNotif) {
startForegroundOrNotify("Song")
}
@@ -152,12 +152,7 @@ class NoLeakThumbView @JvmOverloads constructor(
) {
val thumbTargetY = indicatorCenterY.toFloat() - (thumbView.measuredHeight / 2)
// Don't animate if the view is invisible.
if (!isActivated || !isVisible) {
y = thumbTargetY
} else {
thumbAnimation.animateToFinalPosition(thumbTargetY)
}
thumbAnimation.animateToFinalPosition(thumbTargetY)
when (indicator) {
is FastScrollItemIndicator.Text -> {
@@ -1,5 +1,7 @@
package org.oxycblt.auxio.songs
import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
@@ -18,8 +20,10 @@ import org.oxycblt.auxio.logD
import org.oxycblt.auxio.music.MusicStore
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.isLandscape
import org.oxycblt.auxio.ui.setupSongActions
import org.oxycblt.auxio.ui.toColor
import kotlin.math.ceil
/**
@@ -105,6 +109,11 @@ class SongsFragment : Fragment() {
binding.songFastScroll.apply {
var concatInterval = -1
// API 22 and below don't support the state color, so just use the accent.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
textColor = ColorStateList.valueOf(accent.first.toColor(requireContext()))
}
setupWithRecyclerView(
binding.songRecycler,
{ pos ->