all: view cleanup

Do even more cleanup regarding views.
This commit is contained in:
OxygenCobalt
2022-03-13 18:56:24 -06:00
parent 33da09a08a
commit 2ff7d93263
48 changed files with 122 additions and 98 deletions
@@ -38,7 +38,9 @@ import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
* The single [AppCompatActivity] for Auxio. TODO: Add a new view for crashes with a stack trace
* The single [AppCompatActivity] for Auxio.
*
* TODO: Add a new view for crashes with a stack trace
* TODO: Custom language support TODO: Rework menus [perhaps add multi-select]
*/
class MainActivity : AppCompatActivity() {
@@ -40,8 +40,9 @@ import org.oxycblt.auxio.util.logW
/**
* A wrapper around the home fragment that shows the playback fragment and controls the more
* high-level navigation features.
* @author OxygenCobalt TODO: Add a new view with a stack trace whenever the music loading process
* fails.
* @author OxygenCobalt
*
* TODO: Add a new view with a stack trace whenever the music loading process fails.
*/
class MainFragment : Fragment() {
private val playbackModel: PlaybackViewModel by activityViewModels()
@@ -53,8 +53,10 @@ import org.oxycblt.auxio.util.logTraceOrThrow
/**
* The main "Launching Point" fragment of Auxio, allowing navigation to the detail views for each
* respective item.
* @author OxygenCobalt TODO: Make tabs invisible when there is only one TODO: Add duration and song
* count sorts
* @author OxygenCobalt
*
* TODO: Make tabs invisible when there is only one
* TODO: Add duration and song count sorts
*/
class HomeFragment : Fragment() {
private val playbackModel: PlaybackViewModel by activityViewModels()
@@ -35,13 +35,13 @@ import androidx.annotation.AttrRes
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.math.MathUtils
import androidx.core.view.isInvisible
import androidx.core.view.updatePadding
import androidx.core.widget.TextViewCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.EdgeRecyclerView
import org.oxycblt.auxio.util.canScroll
import org.oxycblt.auxio.util.getAttrColorSafe
import org.oxycblt.auxio.util.getDimenOffsetSafe
@@ -76,7 +76,7 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
class FastScrollRecyclerView
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
RecyclerView(context, attrs, defStyleAttr) {
EdgeRecyclerView(context, attrs, defStyleAttr) {
/** Callback to provide a string to be shown on the popup when an item is passed */
var popupProvider: ((Int) -> String)? = null
@@ -118,7 +118,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
}
private val initialPadding = Rect(paddingLeft, paddingTop, paddingRight, paddingBottom)
private val scrollerPadding = Rect(0, 0, 0, 0)
init {
@@ -316,16 +315,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
super.onApplyWindowInsets(insets)
val bars = insets.systemBarInsetsCompat
updatePadding(
initialPadding.left,
initialPadding.top,
initialPadding.right,
initialPadding.bottom + bars.bottom)
scrollerPadding.bottom = bars.bottom
return insets
}
@@ -56,7 +56,6 @@ abstract class HomeListFragment : Fragment() {
onDragListener = { dragging -> homeModel.updateFastScrolling(dragging) }
}
// Make sure that this RecyclerView has data before startup
homeData.observe(viewLifecycleOwner) { data -> homeAdapter.updateData(data) }
}
@@ -23,8 +23,10 @@ import androidx.recyclerview.widget.RecyclerView
/**
* A simple [ItemTouchHelper.Callback] that handles dragging items in the tab customization menu.
* Unlike QueueAdapter's ItemTouchHelper, this one is bare and simple. TODO: Consider unifying the
* shared behavior between this and QueueDragCallback into a single class.
* Unlike QueueAdapter's ItemTouchHelper, this one is bare and simple.
*
* TODO: Consider unifying the
* shared behavior between this and QueueDragCallback into a single class.
*/
class TabDragCallback(private val getTabs: () -> Array<Tab>) : ItemTouchHelper.Callback() {
private val tabs: Array<Tab>
@@ -33,8 +33,10 @@ sealed class Item {
}
/**
* [Item] variant that represents a music item. TODO: Make name the actual display name and move raw
* names (including file names) to a new field called rawName.
* [Item] variant that represents a music item.
*
* TODO: Make name the actual display name and move raw names (including file names) to a
* new field called rawName.
*/
sealed class Music : Item() {
/** The raw name of this item. */
@@ -32,8 +32,9 @@ import org.oxycblt.auxio.util.logE
/**
* 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. TODO: Add automatic rescanning [major
* change]
* loads asynchronously. See the companion object for more.
*
* TODO: Add automatic rescanning [major change]
* @author OxygenCobalt
*/
class MusicStore private constructor() {
@@ -111,7 +112,9 @@ class MusicStore private constructor() {
/**
* A response that [MusicStore] returns when loading music. And before you ask, yes, I do like
* rust. TODO: Add the exception to the "FAILED" ErrorKind
* rust.
*
* TODO: Add the exception to the "FAILED" ErrorKind
*/
sealed class Response {
class Ok(val musicStore: MusicStore) : Response()
@@ -30,8 +30,10 @@ import org.oxycblt.auxio.util.logD
/**
* ViewModel that acts as a wrapper around [ExcludedDatabase], allowing for the addition/removal of
* paths. Use [Factory] to instantiate this. TODO: Unify with MusicViewModel
* paths. Use [Factory] to instantiate this.
* @author OxygenCobalt
*
* TODO: Unify with MusicViewModel
*/
class ExcludedViewModel(private val excludedDatabase: ExcludedDatabase) : ViewModel() {
private val mPaths = MutableLiveData(mutableListOf<String>())
@@ -37,7 +37,9 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
* A [Fragment] that displays more information about the song, along with more media controls.
* Instantiation is done by the navigation component, **do not instantiate this fragment manually.**
* @author OxygenCobalt TODO: Handle RTL correctly in the playback buttons
* @author OxygenCobalt
*
* TODO: Handle RTL correctly in the playback buttons
*/
class PlaybackFragment : Fragment() {
private val playbackModel: PlaybackViewModel by activityViewModels()
@@ -64,8 +64,9 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
* state and view magic. I tried my best to document it, but it's probably not the most friendly or
* extendable. You have been warned.
*
* @author OxygenCobalt (With help from Umano and Hai Zhang) TODO: Find a better way to handle
* PlaybackFragment in general (navigation, creation)
* @author OxygenCobalt (With help from Umano and Hai Zhang)
*
* TODO: Find a better way to handle PlaybackFragment in general (navigation, creation)
*/
class PlaybackLayout
@JvmOverloads
@@ -34,8 +34,9 @@ import org.oxycblt.auxio.util.stateList
/**
* A custom view that bundles together a seekbar with a current duration and a total duration. The
* sub-views are specifically laid out so that the seekbar has an adequate touch height while still
* not having gobs of whitespace everywhere. TODO: Add smooth seeking [i.e seeking in sub-second
* values]
* not having gobs of whitespace everywhere.
*
* TODO: Add smooth seeking [i.e seeking in sub-second values]
* @author OxygenCobalt
*/
@SuppressLint("RestrictedApi")
@@ -61,7 +61,8 @@ class AudioReactor(context: Context, private val callback: (Float) -> Unit) :
private var pauseWasTransient = false
// It's good to keep the volume and the ducking multiplier separate so that we can
// It's good to keep the volume and the ducking multiplier separate so that we don't
// lose information
private var multiplier = 1f
set(value) {
field = value
@@ -87,8 +88,11 @@ class AudioReactor(context: Context, private val callback: (Float) -> Unit) :
/**
* Updates the rough volume adjustment for [Metadata] with ReplayGain tags. This is based off
* Vanilla Music's implementation. TODO: Add ReplayGain pre-amp TODO: Add positive ReplayGain
* values
* Vanilla Music's implementation.
*
* TODO: Add ReplayGain pre-amp
*
* TODO: Add positive ReplayGain
*/
fun applyReplayGain(metadata: Metadata?) {
if (metadata == null) {
@@ -498,9 +498,10 @@ class PlaybackService :
}
/**
* Pause from a headset plug. TODO: Find a way to centralize this stuff into a single
* BroadcastReciever instead of the weird disjointed arrangement between MediaSession and
* this.
* Pause from a headset plug.
*
* TODO: Find a way to centralize this stuff into a single BroadcastReceiver instead of
* the weird disjointed arrangement between MediaSession and this.
*/
private fun pauseFromPlug() {
if (playbackManager.song != null) {
@@ -54,8 +54,10 @@ fun Fragment.newMenu(anchor: View, data: Item, flag: Int = ActionMenu.FLAG_NONE)
* @param flag Any extra flags to accompany the data. See [FLAG_NONE], [FLAG_IN_ALBUM],
* [FLAG_IN_ARTIST], [FLAG_IN_GENRE] for more details.
* @throws IllegalStateException When there is no menu for this specific datatype/flag
* @author OxygenCobalt TODO: Stop scrolling when a menu is open TODO: Prevent duplicate menus from
* showing up TODO: Maybe replace this with a bottom sheet?
* @author OxygenCobalt
*
* TODO: Stop scrolling when a menu is open TODO: Prevent duplicate menus from showing up
* TODO: Maybe replace this with a bottom sheet?
*/
class ActionMenu(
activity: AppCompatActivity,
@@ -18,6 +18,7 @@
package org.oxycblt.auxio.ui
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.view.WindowInsets
import androidx.annotation.AttrRes
@@ -26,12 +27,25 @@ import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.util.systemBarInsetsCompat
/** A [RecyclerView] that automatically applies insets to itself. */
class EdgeRecyclerView
open class EdgeRecyclerView
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
RecyclerView(context, attrs, defStyleAttr) {
private val initialPadding = Rect(paddingLeft, paddingTop, paddingRight, paddingBottom)
init {
// Prevent children from being clipped by window insets
clipToPadding = false
}
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
updatePadding(
initialPadding.left,
initialPadding.top,
initialPadding.right,
initialPadding.bottom + insets.systemBarInsetsCompat.bottom)
return insets
}
}
@@ -32,9 +32,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
abstract class LifecycleDialog : AppCompatDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = MaterialAlertDialogBuilder(requireActivity(), theme)
onConfigDialog(builder)
return builder.create()
}
@@ -68,7 +68,6 @@ abstract class BaseViewHolder<T : Item>(
doOnLongClick?.let { onLongClick ->
binding.root.setOnLongClickListener { view ->
onLongClick(view, data)
true
}
}