all: cleanup code
Upgrade dependencies, fix deprecation issues, and just clean up code in general.
This commit is contained in:
@@ -170,7 +170,7 @@ class AlbumArtFetcher(private val context: Context) : Fetcher<Album> {
|
||||
|
||||
if (tracks == null || tracks.isEmpty) {
|
||||
// Unrecognized format. This is expected, as ExoPlayer only supports a
|
||||
// subset of formats.
|
||||
// subset of formats.
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import java.io.Closeable
|
||||
import java.lang.Exception
|
||||
|
||||
/**
|
||||
@@ -139,13 +138,6 @@ class MosaicFetcher(private val context: Context) : Fetcher<MusicParent> {
|
||||
return mosaicBitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through a list of [Closeable]s, running [block] on each and closing it when done.
|
||||
*/
|
||||
private fun <T : Closeable> List<T>.useForEach(block: (T) -> Unit) {
|
||||
forEach { it.use(block) }
|
||||
}
|
||||
|
||||
override fun key(data: MusicParent): String = data.hashCode().toString()
|
||||
override fun handles(data: MusicParent) = data !is Album // Albums are not used here
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ abstract class DetailFragment : Fragment() {
|
||||
* @param onMenuClick (Optional) a click listener for that menu
|
||||
*/
|
||||
protected fun setupToolbar(
|
||||
data: Music,
|
||||
music: Music,
|
||||
@MenuRes menu: Int = -1,
|
||||
onMenuClick: ((itemId: Int) -> Boolean)? = null
|
||||
) {
|
||||
binding.detailToolbar.apply {
|
||||
title = data.name
|
||||
title = music.name
|
||||
|
||||
if (menu != -1) {
|
||||
inflateMenu(menu)
|
||||
|
||||
@@ -47,7 +47,7 @@ import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* A [RecyclerView] that enables better fast-scrolling. This is fundamentally a implementation of
|
||||
* Zhanghi's AndroidFastScroll but slimmed down for Auxio and with a couple of enhancements.
|
||||
* Hai Zhang's AndroidFastScroll but slimmed down for Auxio and with a couple of enhancements.
|
||||
*
|
||||
* Attributions as per the Apache 2.0 license:
|
||||
* ORIGINAL AUTHOR: Hai Zhang [https://github.com/zhanghai]
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.oxycblt.auxio.util.logE
|
||||
import java.lang.Exception
|
||||
|
||||
/**
|
||||
* The main storage for music items. Use [MusicStore.getInstance] to get the single instance of it.
|
||||
* The main storage for music items.
|
||||
* Getting an instance of this object is more complicated as it loads asynchronously.
|
||||
* See the companion object for more.
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class MusicStore private constructor() {
|
||||
@@ -194,7 +196,8 @@ class MusicStore private constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe get a MusicStore instance.
|
||||
* Maybe get a MusicStore instance. This is useful if you are running code while the
|
||||
* loading process may still be going on.
|
||||
*
|
||||
* @return null if the music store instance is still loading or if the loading process has
|
||||
* encountered an error. An instance is returned otherwise.
|
||||
|
||||
@@ -246,7 +246,7 @@ class PlaybackBarLayout @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the playback positon on this layout. This will be reflected in the compact view
|
||||
* Update the playback position on this layout. This will be reflected in the compact view
|
||||
* at the bottom of the screen.
|
||||
*/
|
||||
fun setPosition(position: Long) {
|
||||
|
||||
@@ -60,7 +60,7 @@ class PlaybackFragment : Fragment() {
|
||||
binding.playbackModel = playbackModel
|
||||
binding.detailModel = detailModel
|
||||
|
||||
binding.root.setOnApplyWindowInsetsListener { v, insets ->
|
||||
binding.root.setOnApplyWindowInsetsListener { _, insets ->
|
||||
val bars = insets.systemBarsCompat
|
||||
|
||||
binding.root.updatePadding(
|
||||
|
||||
@@ -22,7 +22,7 @@ import android.content.Context
|
||||
import android.media.AudioManager
|
||||
import androidx.media.AudioFocusRequestCompat
|
||||
import androidx.media.AudioManagerCompat
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.util.getSystemServiceSafe
|
||||
@@ -35,7 +35,7 @@ import org.oxycblt.auxio.util.logD
|
||||
*/
|
||||
class AudioReactor(
|
||||
context: Context,
|
||||
private val player: SimpleExoPlayer
|
||||
private val player: ExoPlayer
|
||||
) : AudioManager.OnAudioFocusChangeListener {
|
||||
private val playbackManager = PlaybackStateManager.maybeGetInstance()
|
||||
private val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
@@ -32,11 +32,11 @@ import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.PlaybackException
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.RenderersFactory
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
|
||||
@@ -65,7 +65,7 @@ import org.oxycblt.auxio.widgets.WidgetProvider
|
||||
|
||||
/**
|
||||
* A service that manages the system-side aspects of playback, such as:
|
||||
* - The single [SimpleExoPlayer] instance.
|
||||
* - The single [ExoPlayer] instance.
|
||||
* - The Media Notification
|
||||
* - Headset management
|
||||
* - Widgets
|
||||
@@ -77,7 +77,7 @@ import org.oxycblt.auxio.widgets.WidgetProvider
|
||||
class PlaybackService : Service(), Player.Listener, PlaybackStateManager.Callback, SettingsManager.Callback {
|
||||
|
||||
// Player components
|
||||
private lateinit var player: SimpleExoPlayer
|
||||
private lateinit var player: ExoPlayer
|
||||
private lateinit var mediaSession: MediaSessionCompat
|
||||
private lateinit var connector: PlaybackSessionConnector
|
||||
|
||||
@@ -341,9 +341,9 @@ class PlaybackService : Service(), Player.Listener, PlaybackStateManager.Callbac
|
||||
// --- OTHER FUNCTIONS ---
|
||||
|
||||
/**
|
||||
* Create the [SimpleExoPlayer] instance.
|
||||
* Create the [ExoPlayer] instance.
|
||||
*/
|
||||
private fun newPlayer(): SimpleExoPlayer {
|
||||
private fun newPlayer(): ExoPlayer {
|
||||
// Since Auxio is a music player, only specify an audio renderer to save
|
||||
// battery/apk size/cache size
|
||||
val audioRenderer = RenderersFactory { handler, _, audioListener, _, _ ->
|
||||
@@ -355,7 +355,7 @@ class PlaybackService : Service(), Player.Listener, PlaybackStateManager.Callbac
|
||||
// Enable constant bitrate seeking so that certain MP3s/AACs are seekable
|
||||
val extractorsFactory = DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true)
|
||||
|
||||
return SimpleExoPlayer.Builder(this, audioRenderer)
|
||||
return ExoPlayer.Builder(this, audioRenderer)
|
||||
.setMediaSourceFactory(DefaultMediaSourceFactory(this, extractorsFactory))
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class AboutFragment : Fragment() {
|
||||
): View {
|
||||
val binding = FragmentAboutBinding.inflate(layoutInflater)
|
||||
|
||||
binding.aboutContents.setOnApplyWindowInsetsListener { v, insets ->
|
||||
binding.aboutContents.setOnApplyWindowInsetsListener { _, insets ->
|
||||
binding.aboutContents.updatePadding(bottom = insets.systemBarsCompat.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
||||
view.findViewById<RecyclerView>(androidx.preference.R.id.recycler_view).apply {
|
||||
clipToPadding = false
|
||||
|
||||
setOnApplyWindowInsetsListener { v, insets ->
|
||||
setOnApplyWindowInsetsListener { _, insets ->
|
||||
updatePadding(bottom = insets.systemBarsCompat.bottom)
|
||||
|
||||
insets
|
||||
|
||||
@@ -65,11 +65,11 @@ class ActionMenu(
|
||||
|
||||
// Get viewmodels using the activity as the store owner
|
||||
private val detailModel: DetailViewModel by lazy {
|
||||
ViewModelProvider(activity).get(DetailViewModel::class.java)
|
||||
ViewModelProvider(activity)[DetailViewModel::class.java]
|
||||
}
|
||||
|
||||
private val playbackModel: PlaybackViewModel by lazy {
|
||||
ViewModelProvider(activity).get(PlaybackViewModel::class.java)
|
||||
ViewModelProvider(activity)[PlaybackViewModel::class.java]
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -23,9 +23,9 @@ import androidx.databinding.ViewDataBinding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import org.oxycblt.auxio.util.assertMainThread
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
@@ -51,7 +51,7 @@ class MemberBinder<T : ViewDataBinding>(
|
||||
private val fragment: Fragment,
|
||||
private val inflate: (LayoutInflater) -> T,
|
||||
private val onDestroy: T.() -> Unit
|
||||
) : ReadOnlyProperty<Fragment, T>, LifecycleObserver {
|
||||
) : ReadOnlyProperty<Fragment, T>, LifecycleObserver, LifecycleEventObserver {
|
||||
private var fragmentBinding: T? = null
|
||||
|
||||
init {
|
||||
@@ -82,6 +82,13 @@ class MemberBinder<T : ViewDataBinding>(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||
if (event == Lifecycle.Event.ON_DESTROY) {
|
||||
fragmentBinding?.onDestroy()
|
||||
fragmentBinding = null
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun Fragment.observeOwnerThroughCreation(
|
||||
crossinline viewOwner: LifecycleOwner.() -> Unit
|
||||
) {
|
||||
@@ -95,11 +102,4 @@ class MemberBinder<T : ViewDataBinding>(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Suppress("UNUSED")
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun destroy() {
|
||||
fragmentBinding?.onDestroy()
|
||||
fragmentBinding = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import org.oxycblt.auxio.R
|
||||
|
||||
/**
|
||||
* Apply a [MaterialShapeDrawable] to this view, automatically initializing the elevation overlay
|
||||
|
||||
@@ -152,8 +152,6 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
// We can't resize the widget until we can generate the views, so request an update
|
||||
// from PlaybackService.
|
||||
requestUpdate(context)
|
||||
} else {
|
||||
logD(newOptions?.getParcelableArrayList<SizeF>(AppWidgetManager.OPTION_APPWIDGET_SIZES) ?: "nothing")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user