all: refactor associating class naming
Standardize from/new companion method usage, Callback/Listener usage, and companion object visibility across the app.
This commit is contained in:
parent
4ed8a7e967
commit
bf56a50b59
57 changed files with 253 additions and 253 deletions
|
|
@ -42,20 +42,12 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
|
|||
*
|
||||
* TODO: Custom language support
|
||||
*
|
||||
* TODO: Add multi-select
|
||||
*
|
||||
* TODO: Use proper material attributes (Not the weird dimen attributes I currently have)
|
||||
*
|
||||
* TODO: Migrate to material animation system
|
||||
*
|
||||
* TODO: Unit testing
|
||||
*
|
||||
* TODO: Standardize from/new usage
|
||||
*
|
||||
* TODO: Standardize companion object usage
|
||||
*
|
||||
* TODO: Standardize callback/listener naming.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
|
@ -146,7 +138,7 @@ class MainActivity : AppCompatActivity() {
|
|||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_INTENT_USED = BuildConfig.APPLICATION_ID + ".key.FILE_INTENT_USED"
|
||||
private companion object {
|
||||
const val KEY_INTENT_USED = BuildConfig.APPLICATION_ID + ".key.FILE_INTENT_USED"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,8 +166,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TOOLBAR_TITLE_TEXT_FIELD: Field by
|
||||
lazyReflectedField(Toolbar::class, "mTitleTextView")
|
||||
private companion object {
|
||||
val TOOLBAR_TITLE_TEXT_FIELD: Field by lazyReflectedField(Toolbar::class, "mTitleTextView")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import org.oxycblt.auxio.util.*
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class DetailViewModel(application: Application) :
|
||||
AndroidViewModel(application), MusicStore.Callback {
|
||||
AndroidViewModel(application), MusicStore.Listener {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
private val settings = Settings(application)
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ class AlbumDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
when (viewType) {
|
||||
AlbumDetailViewHolder.VIEW_TYPE -> AlbumDetailViewHolder.new(parent)
|
||||
DiscHeaderViewHolder.VIEW_TYPE -> DiscHeaderViewHolder.new(parent)
|
||||
AlbumSongViewHolder.VIEW_TYPE -> AlbumSongViewHolder.new(parent)
|
||||
AlbumDetailViewHolder.VIEW_TYPE -> AlbumDetailViewHolder.from(parent)
|
||||
DiscHeaderViewHolder.VIEW_TYPE -> DiscHeaderViewHolder.from(parent)
|
||||
AlbumSongViewHolder.VIEW_TYPE -> AlbumSongViewHolder.from(parent)
|
||||
else -> super.onCreateViewHolder(parent, viewType)
|
||||
}
|
||||
|
||||
|
|
@ -88,9 +88,9 @@ class AlbumDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
return super.isItemFullWidth(position) || item is Album || item is DiscHeader
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
private val DIFF_CALLBACK =
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleItemCallback<Item>() {
|
||||
override fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
|
||||
return when {
|
||||
|
|
@ -110,7 +110,7 @@ class AlbumDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays the [Album] header in the detail view. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays the [Album] header in the detail view. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -161,7 +161,7 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
AlbumDetailViewHolder(ItemDetailBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
@ -180,7 +180,7 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
|||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [DiscHeader] to delimit different disc groups. Use
|
||||
* [new] to create an instance.
|
||||
* [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
private class DiscHeaderViewHolder(private val binding: ItemDiscHeaderBinding) :
|
||||
|
|
@ -202,7 +202,7 @@ private class DiscHeaderViewHolder(private val binding: ItemDiscHeaderBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
DiscHeaderViewHolder(ItemDiscHeaderBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
@ -215,7 +215,7 @@ private class DiscHeaderViewHolder(private val binding: ItemDiscHeaderBinding) :
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song] in the context of an [Album]. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song] in the context of an [Album]. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -269,7 +269,7 @@ private class AlbumSongViewHolder private constructor(private val binding: ItemA
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
AlbumSongViewHolder(ItemAlbumSongBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ class ArtistDetailAdapter(private val listener: Listener) : DetailAdapter(listen
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
when (viewType) {
|
||||
ArtistDetailViewHolder.VIEW_TYPE -> ArtistDetailViewHolder.new(parent)
|
||||
ArtistAlbumViewHolder.VIEW_TYPE -> ArtistAlbumViewHolder.new(parent)
|
||||
ArtistSongViewHolder.VIEW_TYPE -> ArtistSongViewHolder.new(parent)
|
||||
ArtistDetailViewHolder.VIEW_TYPE -> ArtistDetailViewHolder.from(parent)
|
||||
ArtistAlbumViewHolder.VIEW_TYPE -> ArtistAlbumViewHolder.from(parent)
|
||||
ArtistSongViewHolder.VIEW_TYPE -> ArtistSongViewHolder.from(parent)
|
||||
else -> super.onCreateViewHolder(parent, viewType)
|
||||
}
|
||||
|
||||
|
|
@ -76,9 +76,9 @@ class ArtistDetailAdapter(private val listener: Listener) : DetailAdapter(listen
|
|||
return super.isItemFullWidth(position) || item is Artist
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
private val DIFF_CALLBACK =
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleItemCallback<Item>() {
|
||||
override fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
|
||||
return when {
|
||||
|
|
@ -97,7 +97,7 @@ class ArtistDetailAdapter(private val listener: Listener) : DetailAdapter(listen
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays the [Artist] header in the detail view. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays the [Artist] header in the detail view. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -156,7 +156,7 @@ private class ArtistDetailViewHolder private constructor(private val binding: It
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
ArtistDetailViewHolder(ItemDetailBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
@ -172,7 +172,7 @@ private class ArtistDetailViewHolder private constructor(private val binding: It
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays an [Album] in the context of an [Artist]. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays an [Album] in the context of an [Artist]. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -211,7 +211,7 @@ private class ArtistAlbumViewHolder private constructor(private val binding: Ite
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
ArtistAlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
@ -224,7 +224,7 @@ private class ArtistAlbumViewHolder private constructor(private val binding: Ite
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song] in the context of an [Artist]. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song] in the context of an [Artist]. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -260,7 +260,7 @@ private class ArtistSongViewHolder private constructor(private val binding: Item
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
ArtistSongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ abstract class DetailAdapter(
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
when (viewType) {
|
||||
HeaderViewHolder.VIEW_TYPE -> HeaderViewHolder.new(parent)
|
||||
SortHeaderViewHolder.VIEW_TYPE -> SortHeaderViewHolder.new(parent)
|
||||
HeaderViewHolder.VIEW_TYPE -> HeaderViewHolder.from(parent)
|
||||
SortHeaderViewHolder.VIEW_TYPE -> SortHeaderViewHolder.from(parent)
|
||||
else -> error("Invalid item type $viewType")
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ abstract class DetailAdapter(
|
|||
fun onOpenSortMenu(anchor: View)
|
||||
}
|
||||
|
||||
companion object {
|
||||
protected companion object {
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleItemCallback<Item>() {
|
||||
|
|
@ -128,7 +128,7 @@ abstract class DetailAdapter(
|
|||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [SortHeader], a variation on [Header] that adds a
|
||||
* button opening a menu for sorting. Use [new] to create an instance.
|
||||
* button opening a menu for sorting. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
private class SortHeaderViewHolder(private val binding: ItemSortHeaderBinding) :
|
||||
|
|
@ -157,7 +157,7 @@ private class SortHeaderViewHolder(private val binding: ItemSortHeaderBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
SortHeaderViewHolder(ItemSortHeaderBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ class GenreDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
when (viewType) {
|
||||
GenreDetailViewHolder.VIEW_TYPE -> GenreDetailViewHolder.new(parent)
|
||||
ArtistViewHolder.VIEW_TYPE -> ArtistViewHolder.new(parent)
|
||||
SongViewHolder.VIEW_TYPE -> SongViewHolder.new(parent)
|
||||
GenreDetailViewHolder.VIEW_TYPE -> GenreDetailViewHolder.from(parent)
|
||||
ArtistViewHolder.VIEW_TYPE -> ArtistViewHolder.from(parent)
|
||||
SongViewHolder.VIEW_TYPE -> SongViewHolder.from(parent)
|
||||
else -> super.onCreateViewHolder(parent, viewType)
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ class GenreDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
return super.isItemFullWidth(position) || item is Genre
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleItemCallback<Item>() {
|
||||
override fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
|
||||
|
|
@ -94,7 +94,7 @@ class GenreDetailAdapter(private val listener: Listener) : DetailAdapter(listene
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays the [Genre] header in the detail view. Use [new] to
|
||||
* A [RecyclerView.ViewHolder] that displays the [Genre] header in the detail view. Use [from] to
|
||||
* create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -130,7 +130,7 @@ private class GenreDetailViewHolder private constructor(private val binding: Ite
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
GenreDetailViewHolder(ItemDetailBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
|
|||
|
|
@ -493,12 +493,10 @@ class HomeFragment :
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val VP_RECYCLER_FIELD: Field by
|
||||
lazyReflectedField(ViewPager2::class, "mRecyclerView")
|
||||
private val RV_TOUCH_SLOP_FIELD: Field by
|
||||
lazyReflectedField(RecyclerView::class, "mTouchSlop")
|
||||
private const val KEY_LAST_TRANSITION_AXIS =
|
||||
private companion object {
|
||||
val VP_RECYCLER_FIELD: Field by lazyReflectedField(ViewPager2::class, "mRecyclerView")
|
||||
val RV_TOUCH_SLOP_FIELD: Field by lazyReflectedField(RecyclerView::class, "mTouchSlop")
|
||||
const val KEY_LAST_TRANSITION_AXIS =
|
||||
BuildConfig.APPLICATION_ID + ".key.LAST_TRANSITION_AXIS"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.oxycblt.auxio.util.logD
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class HomeViewModel(application: Application) :
|
||||
AndroidViewModel(application), Settings.Callback, MusicStore.Callback {
|
||||
AndroidViewModel(application), Settings.Listener, MusicStore.Listener {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
private val settings = Settings(application, this)
|
||||
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleRes: Int = 0)
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
// Pre-calculate sqrt(2)
|
||||
private const val SQRT2 = 1.4142135f
|
||||
const val SQRT2 = 1.4142135f
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,7 +524,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
else -> 0
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val AUTO_HIDE_SCROLLBAR_DELAY_MILLIS = 1500
|
||||
private companion object {
|
||||
const val AUTO_HIDE_SCROLLBAR_DELAY_MILLIS = 1500
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class AlbumListFragment :
|
|||
get() = differ.currentList
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
AlbumViewHolder.new(parent)
|
||||
AlbumViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: AlbumViewHolder, position: Int) {
|
||||
holder.bind(differ.currentList[position], listener)
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class ArtistListFragment :
|
|||
get() = differ.currentList
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
ArtistViewHolder.new(parent)
|
||||
ArtistViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ArtistViewHolder, position: Int) {
|
||||
holder.bind(differ.currentList[position], listener)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class GenreListFragment :
|
|||
get() = differ.currentList
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
GenreViewHolder.new(parent)
|
||||
GenreViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: GenreViewHolder, position: Int) {
|
||||
holder.bind(differ.currentList[position], listener)
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ class SongListFragment :
|
|||
get() = differ.currentList
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
SongViewHolder.new(parent)
|
||||
SongViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: SongViewHolder, position: Int) {
|
||||
holder.bind(differ.currentList[position], listener)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TabAdapter(private val listener: Listener) : RecyclerView.Adapter<TabViewH
|
|||
private set
|
||||
|
||||
override fun getItemCount() = tabs.size
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = TabViewHolder.new(parent)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = TabViewHolder.from(parent)
|
||||
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
|
||||
holder.bind(tabs[position], listener)
|
||||
}
|
||||
|
|
@ -92,13 +92,13 @@ class TabAdapter(private val listener: Listener) : RecyclerView.Adapter<TabViewH
|
|||
fun onPickUp(viewHolder: RecyclerView.ViewHolder)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PAYLOAD_TAB_CHANGED = Any()
|
||||
private companion object {
|
||||
val PAYLOAD_TAB_CHANGED = Any()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Tab]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Tab]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class TabViewHolder private constructor(private val binding: ItemTabBinding) :
|
||||
|
|
@ -143,6 +143,6 @@ class TabViewHolder private constructor(private val binding: ItemTabBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = TabViewHolder(ItemTabBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) = TabViewHolder(ItemTabBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class TabCustomizeDialog : ViewBindingDialogFragment<DialogTabsBinding>(), TabAd
|
|||
touchHelper.startDrag(viewHolder)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_TABS = BuildConfig.APPLICATION_ID + ".key.PENDING_TABS"
|
||||
private companion object {
|
||||
const val KEY_TABS = BuildConfig.APPLICATION_ID + ".key.PENDING_TABS"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ abstract class PlayingIndicatorAdapter<VH : RecyclerView.ViewHolder> : RecyclerV
|
|||
abstract fun updatePlayingIndicator(isActive: Boolean, isPlaying: Boolean)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PAYLOAD_PLAYING_INDICATOR_CHANGED = Any()
|
||||
private companion object {
|
||||
val PAYLOAD_PLAYING_INDICATOR_CHANGED = Any()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ abstract class SelectionIndicatorAdapter<VH : RecyclerView.ViewHolder> :
|
|||
abstract fun updateSelectionIndicator(isSelected: Boolean)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PAYLOAD_SELECTION_INDICATOR_CHANGED = Any()
|
||||
private companion object {
|
||||
val PAYLOAD_SELECTION_INDICATOR_CHANGED = Any()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import org.oxycblt.auxio.util.getPlural
|
|||
import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Song]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class SongViewHolder private constructor(private val binding: ItemSongBinding) :
|
||||
|
|
@ -70,7 +70,7 @@ class SongViewHolder private constructor(private val binding: ItemSongBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = SongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) = SongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
|
|
@ -82,7 +82,7 @@ class SongViewHolder private constructor(private val binding: ItemSongBinding) :
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Album]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Album]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class AlbumViewHolder private constructor(private val binding: ItemParentBinding) :
|
||||
|
|
@ -117,7 +117,7 @@ class AlbumViewHolder private constructor(private val binding: ItemParentBinding
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = AlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) = AlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
|
|
@ -131,7 +131,7 @@ class AlbumViewHolder private constructor(private val binding: ItemParentBinding
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Artist]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Artist]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class ArtistViewHolder private constructor(private val binding: ItemParentBinding) :
|
||||
|
|
@ -175,7 +175,8 @@ class ArtistViewHolder private constructor(private val binding: ItemParentBindin
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = ArtistViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) =
|
||||
ArtistViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
|
|
@ -189,7 +190,7 @@ class ArtistViewHolder private constructor(private val binding: ItemParentBindin
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Genre]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Genre]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class GenreViewHolder private constructor(private val binding: ItemParentBinding) :
|
||||
|
|
@ -228,7 +229,7 @@ class GenreViewHolder private constructor(private val binding: ItemParentBinding
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = GenreViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) = GenreViewHolder(ItemParentBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
|
|
@ -240,7 +241,7 @@ class GenreViewHolder private constructor(private val binding: ItemParentBinding
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [Header]. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays a [Header]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class HeaderViewHolder private constructor(private val binding: ItemHeaderBinding) :
|
||||
|
|
@ -262,7 +263,8 @@ class HeaderViewHolder private constructor(private val binding: ItemHeaderBindin
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = HeaderViewHolder(ItemHeaderBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) =
|
||||
HeaderViewHolder(ItemHeaderBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import org.oxycblt.auxio.music.*
|
|||
* A [ViewModel] that manages the current selection.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class SelectionViewModel : ViewModel(), MusicStore.Callback {
|
||||
class SelectionViewModel : ViewModel(), MusicStore.Listener {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
|
||||
private val _selected = MutableStateFlow(listOf<Music>())
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ import org.oxycblt.auxio.util.nonZeroOrNull
|
|||
* An ISO-8601/RFC 3339 Date.
|
||||
*
|
||||
* This class only encodes the timestamp spec and it's conversion to a human-readable date, without
|
||||
* any other time management or validation. In general, this should only be used for display.
|
||||
* any other time management or validation. In general, this should only be used for display. Use
|
||||
* [from] to create an instance.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -112,12 +113,17 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
|
|||
|
||||
/**
|
||||
* A range of [Date]s. This is used in contexts where the [Date] of an item is derived from
|
||||
* several sub-items and thus can have a "range" of release dates.
|
||||
* @param min The earliest [Date] in the range.
|
||||
* @param max The latest [Date] in the range. May be the same as [min].
|
||||
* several sub-items and thus can have a "range" of release dates. Use [from] to create an
|
||||
* instance.
|
||||
* @author Alexander Capehart
|
||||
*/
|
||||
class Range private constructor(val min: Date, val max: Date) : Comparable<Range> {
|
||||
class Range
|
||||
private constructor(
|
||||
/** The earliest [Date] in the range. */
|
||||
val min: Date,
|
||||
/** the latest [Date] in the range. May be the same as [min]. ] */
|
||||
val max: Date
|
||||
) : Comparable<Range> {
|
||||
|
||||
/**
|
||||
* Resolve this instance into a human-readable date range.
|
||||
|
|
|
|||
|
|
@ -280,9 +280,9 @@ sealed class Music : Item {
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** Cached collator instance re-used with [makeCollationKeyImpl]. */
|
||||
private val COLLATOR = Collator.getInstance().apply { strength = Collator.PRIMARY }
|
||||
val COLLATOR = Collator.getInstance().apply { strength = Collator.PRIMARY }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,42 +33,42 @@ import org.oxycblt.auxio.music.storage.useQuery
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class MusicStore private constructor() {
|
||||
private val callbacks = mutableListOf<Callback>()
|
||||
private val listeners = mutableListOf<Listener>()
|
||||
|
||||
/**
|
||||
* The current [Library]. May be null if a [Library] has not been successfully loaded yet. This
|
||||
* can change, so it's highly recommended to not access this directly and instead rely on
|
||||
* [Callback].
|
||||
* [Listener].
|
||||
*/
|
||||
var library: Library? = null
|
||||
set(value) {
|
||||
field = value
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onLibraryChanged(library)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a [Callback] to this instance. This can be used to receive changes in the music library.
|
||||
* Will invoke all [Callback] methods to initialize the instance with the current state.
|
||||
* @param callback The [Callback] to add.
|
||||
* @see Callback
|
||||
* Add a [Listener] to this instance. This can be used to receive changes in the music library.
|
||||
* Will invoke all [Listener] methods to initialize the instance with the current state.
|
||||
* @param listener The [Listener] to add.
|
||||
* @see Listener
|
||||
*/
|
||||
@Synchronized
|
||||
fun addCallback(callback: Callback) {
|
||||
callback.onLibraryChanged(library)
|
||||
callbacks.add(callback)
|
||||
fun addCallback(listener: Listener) {
|
||||
listener.onLibraryChanged(library)
|
||||
listeners.add(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a [Callback] from this instance, preventing it from recieving any further updates.
|
||||
* @param callback The [Callback] to remove. Does nothing if the [Callback] was never added in
|
||||
* Remove a [Listener] from this instance, preventing it from recieving any further updates.
|
||||
* @param listener The [Listener] to remove. Does nothing if the [Listener] was never added in
|
||||
* the first place.
|
||||
* @see Callback
|
||||
* @see Listener
|
||||
*/
|
||||
@Synchronized
|
||||
fun removeCallback(callback: Callback) {
|
||||
callbacks.remove(callback)
|
||||
fun removeCallback(listener: Listener) {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -167,7 +167,7 @@ class MusicStore private constructor() {
|
|||
}
|
||||
|
||||
/** A listener for changes in the music library. */
|
||||
interface Callback {
|
||||
interface Listener {
|
||||
/**
|
||||
* Called when the current [Library] has changed.
|
||||
* @param library The new [Library], or null if no [Library] has been loaded yet.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import org.oxycblt.auxio.music.system.Indexer
|
|||
* A [ViewModel] providing data specific to the music loading process.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class MusicViewModel : ViewModel(), Indexer.Callback {
|
||||
class MusicViewModel : ViewModel(), Indexer.Listener {
|
||||
private val indexer = Indexer.getInstance()
|
||||
|
||||
private val _indexerState = MutableStateFlow<Indexer.State?>(null)
|
||||
|
|
|
|||
|
|
@ -322,12 +322,12 @@ abstract class MediaStoreExtractor(
|
|||
genreNamesMap[raw.mediaStoreId]?.let { raw.genreNames = listOf(it) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/**
|
||||
* The base selector that works across all versions of android. Does not exclude
|
||||
* directories.
|
||||
*/
|
||||
private const val BASE_SELECTOR = "NOT ${MediaStore.Audio.Media.SIZE}=0"
|
||||
const val BASE_SELECTOR = "NOT ${MediaStore.Audio.Media.SIZE}=0"
|
||||
|
||||
/**
|
||||
* The album artist of a song. This column has existed since at least API 21, but until API
|
||||
|
|
@ -335,13 +335,13 @@ abstract class MediaStoreExtractor(
|
|||
* versions that Auxio supports.
|
||||
*/
|
||||
@Suppress("InlinedApi")
|
||||
private const val AUDIO_COLUMN_ALBUM_ARTIST = MediaStore.Audio.AudioColumns.ALBUM_ARTIST
|
||||
const val AUDIO_COLUMN_ALBUM_ARTIST = MediaStore.Audio.AudioColumns.ALBUM_ARTIST
|
||||
|
||||
/**
|
||||
* The external volume. This naming has existed since API 21, but no constant existed for it
|
||||
* until API 29. This will work on all versions that Auxio supports.
|
||||
*/
|
||||
@Suppress("InlinedApi") private const val VOLUME_EXTERNAL = MediaStore.VOLUME_EXTERNAL
|
||||
@Suppress("InlinedApi") const val VOLUME_EXTERNAL = MediaStore.VOLUME_EXTERNAL
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ class MetadataExtractor(
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TASK_CAPACITY = 8
|
||||
private companion object {
|
||||
const val TASK_CAPACITY = 8
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,13 +94,13 @@ class SeparatorsDialog : ViewBindingDialogFragment<DialogSeparatorsBinding>() {
|
|||
return separators
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val KEY_PENDING_SEPARATORS = BuildConfig.APPLICATION_ID + ".key.PENDING_SEPARATORS"
|
||||
private companion object {
|
||||
val KEY_PENDING_SEPARATORS = BuildConfig.APPLICATION_ID + ".key.PENDING_SEPARATORS"
|
||||
// TODO: Move these to a more "Correct" location?
|
||||
private const val SEPARATOR_COMMA = ','
|
||||
private const val SEPARATOR_SEMICOLON = ';'
|
||||
private const val SEPARATOR_SLASH = '/'
|
||||
private const val SEPARATOR_PLUS = '+'
|
||||
private const val SEPARATOR_AND = '&'
|
||||
const val SEPARATOR_COMMA = ','
|
||||
const val SEPARATOR_SEMICOLON = ';'
|
||||
const val SEPARATOR_SLASH = '/'
|
||||
const val SEPARATOR_PLUS = '+'
|
||||
const val SEPARATOR_AND = '&'
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ArtistChoiceAdapter(private val listener: ClickableListListener) :
|
|||
override fun getItemCount() = artists.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
ArtistChoiceViewHolder.new(parent)
|
||||
ArtistChoiceViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ArtistChoiceViewHolder, position: Int) =
|
||||
holder.bind(artists[position], listener)
|
||||
|
|
@ -58,7 +58,7 @@ class ArtistChoiceAdapter(private val listener: ClickableListListener) :
|
|||
|
||||
/**
|
||||
* A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [Artist] item, for
|
||||
* use with [ArtistChoiceAdapter]. Use [new] to create an instance.
|
||||
* use with [ArtistChoiceAdapter]. Use [from] to create an instance.
|
||||
*/
|
||||
class ArtistChoiceViewHolder(private val binding: ItemPickerChoiceBinding) :
|
||||
DialogRecyclerView.ViewHolder(binding.root) {
|
||||
|
|
@ -79,7 +79,7 @@ class ArtistChoiceViewHolder(private val binding: ItemPickerChoiceBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
ArtistChoiceViewHolder(ItemPickerChoiceBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class GenreChoiceAdapter(private val listener: ClickableListListener) :
|
|||
override fun getItemCount() = genres.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
GenreChoiceViewHolder.new(parent)
|
||||
GenreChoiceViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: GenreChoiceViewHolder, position: Int) =
|
||||
holder.bind(genres[position], listener)
|
||||
|
|
@ -58,7 +58,7 @@ class GenreChoiceAdapter(private val listener: ClickableListListener) :
|
|||
|
||||
/**
|
||||
* A [DialogRecyclerView.ViewHolder] that displays a smaller variant of a typical [Genre] item, for
|
||||
* use with [GenreChoiceAdapter]. Use [new] to create an instance.
|
||||
* use with [GenreChoiceAdapter]. Use [from] to create an instance.
|
||||
*/
|
||||
class GenreChoiceViewHolder(private val binding: ItemPickerChoiceBinding) :
|
||||
DialogRecyclerView.ViewHolder(binding.root) {
|
||||
|
|
@ -79,7 +79,7 @@ class GenreChoiceViewHolder(private val binding: ItemPickerChoiceBinding) :
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
GenreChoiceViewHolder(ItemPickerChoiceBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import org.oxycblt.auxio.util.unlikelyToBeNull
|
|||
* contain the music themselves and then exit if the library changes.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class PickerViewModel : ViewModel(), MusicStore.Callback {
|
||||
class PickerViewModel : ViewModel(), MusicStore.Listener {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
|
||||
private val _currentItem = MutableStateFlow<Music?>(null)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class DirectoryAdapter(private val listener: Listener) :
|
|||
override fun getItemCount() = dirs.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
MusicDirViewHolder.new(parent)
|
||||
MusicDirViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: MusicDirViewHolder, position: Int) =
|
||||
holder.bind(dirs[position], listener)
|
||||
|
|
@ -86,7 +86,7 @@ class DirectoryAdapter(private val listener: Listener) :
|
|||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.Recycler] that displays a [Directory]. Use [new] to create an instance.
|
||||
* A [RecyclerView.Recycler] that displays a [Directory]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class MusicDirViewHolder private constructor(private val binding: ItemMusicDirBinding) :
|
||||
|
|
@ -107,7 +107,7 @@ class MusicDirViewHolder private constructor(private val binding: ItemMusicDirBi
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
MusicDirViewHolder(ItemMusicDirBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ class MusicDirsDialog :
|
|||
private fun isUiModeInclude(binding: DialogMusicDirsBinding) =
|
||||
binding.folderModeGroup.checkedButtonId == R.id.dirs_mode_include
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
const val KEY_PENDING_DIRS = BuildConfig.APPLICATION_ID + ".key.PENDING_DIRS"
|
||||
const val KEY_PENDING_MODE = BuildConfig.APPLICATION_ID + ".key.SHOULD_INCLUDE"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class Indexer private constructor() {
|
|||
private var lastResponse: Response? = null
|
||||
private var indexingState: Indexing? = null
|
||||
private var controller: Controller? = null
|
||||
private var callback: Callback? = null
|
||||
private var listener: Listener? = null
|
||||
|
||||
/** Whether music loading is occurring or not. */
|
||||
val isIndexing: Boolean
|
||||
|
|
@ -71,7 +71,7 @@ class Indexer private constructor() {
|
|||
/**
|
||||
* Register a [Controller] for this instance. This instance will handle any commands to start
|
||||
* the music loading process. There can be only one [Controller] at a time. Will invoke all
|
||||
* [Callback] methods to initialize the instance with the current state.
|
||||
* [Listener] methods to initialize the instance with the current state.
|
||||
* @param controller The [Controller] to register. Will do nothing if already registered.
|
||||
*/
|
||||
@Synchronized
|
||||
|
|
@ -105,14 +105,14 @@ class Indexer private constructor() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Register the [Callback] for this instance. This can be used to receive rapid-fire updates to
|
||||
* the current music loading state. There can be only one [Callback] at a time. Will invoke all
|
||||
* [Callback] methods to initialize the instance with the current state.
|
||||
* @param callback The [Callback] to add.
|
||||
* Register the [Listener] for this instance. This can be used to receive rapid-fire updates to
|
||||
* the current music loading state. There can be only one [Listener] at a time. Will invoke all
|
||||
* [Listener] methods to initialize the instance with the current state.
|
||||
* @param listener The [Listener] to add.
|
||||
*/
|
||||
@Synchronized
|
||||
fun registerCallback(callback: Callback) {
|
||||
if (BuildConfig.DEBUG && this.callback != null) {
|
||||
fun registerCallback(listener: Listener) {
|
||||
if (BuildConfig.DEBUG && this.listener != null) {
|
||||
logW("Listener is already registered")
|
||||
return
|
||||
}
|
||||
|
|
@ -120,24 +120,24 @@ class Indexer private constructor() {
|
|||
// Initialize the listener with the current state.
|
||||
val currentState =
|
||||
indexingState?.let { State.Indexing(it) } ?: lastResponse?.let { State.Complete(it) }
|
||||
callback.onIndexerStateChanged(currentState)
|
||||
this.callback = callback
|
||||
listener.onIndexerStateChanged(currentState)
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a [Callback] from this instance, preventing it from recieving any further updates.
|
||||
* @param callback The [Callback] to unregister. Must be the current [Callback]. Does nothing if
|
||||
* invoked by another [Callback] implementation.
|
||||
* @see Callback
|
||||
* Unregister a [Listener] from this instance, preventing it from recieving any further updates.
|
||||
* @param listener The [Listener] to unregister. Must be the current [Listener]. Does nothing if
|
||||
* invoked by another [Listener] implementation.
|
||||
* @see Listener
|
||||
*/
|
||||
@Synchronized
|
||||
fun unregisterCallback(callback: Callback) {
|
||||
if (BuildConfig.DEBUG && this.callback !== callback) {
|
||||
fun unregisterCallback(listener: Listener) {
|
||||
if (BuildConfig.DEBUG && this.listener !== listener) {
|
||||
logW("Given controller did not match current controller")
|
||||
return
|
||||
}
|
||||
|
||||
this.callback = null
|
||||
this.listener = null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -388,7 +388,7 @@ class Indexer private constructor() {
|
|||
val state =
|
||||
indexingState?.let { State.Indexing(it) } ?: lastResponse?.let { State.Complete(it) }
|
||||
controller?.onIndexerStateChanged(state)
|
||||
callback?.onIndexerStateChanged(state)
|
||||
listener?.onIndexerStateChanged(state)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -411,7 +411,7 @@ class Indexer private constructor() {
|
|||
// Signal that the music loading process has been completed.
|
||||
val state = State.Complete(response)
|
||||
controller?.onIndexerStateChanged(state)
|
||||
callback?.onIndexerStateChanged(state)
|
||||
listener?.onIndexerStateChanged(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -476,10 +476,10 @@ class Indexer private constructor() {
|
|||
* A listener for rapid-fire changes in the music loading state.
|
||||
*
|
||||
* This is only useful for code that absolutely must show the current loading process.
|
||||
* Otherwise, [MusicStore.Callback] is highly recommended due to it's updates only consisting of
|
||||
* Otherwise, [MusicStore.Listener] is highly recommended due to it's updates only consisting of
|
||||
* the [MusicStore.Library].
|
||||
*/
|
||||
interface Callback {
|
||||
interface Listener {
|
||||
/**
|
||||
* Called when the current state of the Indexer changed.
|
||||
*
|
||||
|
|
@ -495,7 +495,7 @@ class Indexer private constructor() {
|
|||
* Context that runs the music loading process. Implementations should be capable of running the
|
||||
* background for long periods of time without android killing the process.
|
||||
*/
|
||||
interface Controller : Callback {
|
||||
interface Controller : Listener {
|
||||
/**
|
||||
* Called when a new music loading process was requested. Implementations should forward
|
||||
* this to [index].
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ import org.oxycblt.auxio.util.logD
|
|||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class IndexerService : Service(), Indexer.Controller, Settings.Callback {
|
||||
class IndexerService : Service(), Indexer.Controller, Settings.Listener {
|
||||
private val indexer = Indexer.getInstance()
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
|
|
@ -287,8 +287,8 @@ class IndexerService : Service(), Indexer.Controller, Settings.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val WAKELOCK_TIMEOUT_MS = 60 * 1000L
|
||||
private const val REINDEX_DELAY_MS = 500L
|
||||
private companion object {
|
||||
const val WAKELOCK_TIMEOUT_MS = 60 * 1000L
|
||||
const val REINDEX_DELAY_MS = 500L
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ class PlaybackPanelFragment :
|
|||
when (item.itemId) {
|
||||
R.id.action_open_equalizer -> {
|
||||
// Launch the system equalizer app, if possible.
|
||||
// TODO: Move this to a utility
|
||||
val equalizerIntent =
|
||||
Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL)
|
||||
// Provide audio session ID so equalizer can show options for this app
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.oxycblt.auxio.util.context
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class PlaybackViewModel(application: Application) :
|
||||
AndroidViewModel(application), PlaybackStateManager.Callback {
|
||||
AndroidViewModel(application), PlaybackStateManager.Listener {
|
||||
private val settings = Settings(application)
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
private var lastPositionJob: Job? = null
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class QueueAdapter(private val listener: Listener) : RecyclerView.Adapter<QueueS
|
|||
override fun getItemCount() = differ.currentList.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
QueueSongViewHolder.new(parent)
|
||||
QueueSongViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: QueueSongViewHolder, position: Int) =
|
||||
throw IllegalStateException()
|
||||
|
|
@ -137,13 +137,13 @@ class QueueAdapter(private val listener: Listener) : RecyclerView.Adapter<QueueS
|
|||
fun onPickUp(viewHolder: RecyclerView.ViewHolder)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PAYLOAD_UPDATE_POSITION = Any()
|
||||
private companion object {
|
||||
val PAYLOAD_UPDATE_POSITION = Any()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A [PlayingIndicatorAdapter.ViewHolder] that displays a queue [Song]. Use [new] to create an
|
||||
* A [PlayingIndicatorAdapter.ViewHolder] that displays a queue [Song]. Use [from] to create an
|
||||
* instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
|
|
@ -224,7 +224,7 @@ class QueueSongViewHolder private constructor(private val binding: ItemQueueSong
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) =
|
||||
fun from(parent: View) =
|
||||
QueueSongViewHolder(ItemQueueSongBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
|
|
|
|||
|
|
@ -114,7 +114,8 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueAdapter.
|
|||
val lmm = binding.queueRecycler.layoutManager as LinearLayoutManager
|
||||
val start = lmm.findFirstCompletelyVisibleItemPosition()
|
||||
val end = lmm.findLastCompletelyVisibleItemPosition()
|
||||
val notInitialized = start == RecyclerView.NO_POSITION || end == RecyclerView.NO_POSITION
|
||||
val notInitialized =
|
||||
start == RecyclerView.NO_POSITION || end == RecyclerView.NO_POSITION
|
||||
// When we scroll, we want to scroll to the almost-top so the user can see
|
||||
// future songs instead of past songs. The way we have to do this however is
|
||||
// dependent on where we have to scroll to get to the currently playing song.
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
|||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class QueueViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
class QueueViewModel : ViewModel(), PlaybackStateManager.Listener {
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
|
||||
private val _queue = MutableStateFlow(listOf<Song>())
|
||||
|
|
|
|||
|
|
@ -281,12 +281,11 @@ class ReplayGainAudioProcessor(context: Context) : BaseAudioProcessor() {
|
|||
private data class GainTag(val key: String, val value: Float)
|
||||
// TODO: Try to phase this out
|
||||
|
||||
companion object {
|
||||
private const val TAG_RG_TRACK = "replaygain_track_gain"
|
||||
private const val TAG_RG_ALBUM = "replaygain_album_gain"
|
||||
private const val R128_TRACK = "r128_track_gain"
|
||||
private const val R128_ALBUM = "r128_album_gain"
|
||||
|
||||
private val REPLAY_GAIN_TAGS = arrayOf(TAG_RG_TRACK, TAG_RG_ALBUM, R128_ALBUM, R128_TRACK)
|
||||
private companion object {
|
||||
const val TAG_RG_TRACK = "replaygain_track_gain"
|
||||
const val TAG_RG_ALBUM = "replaygain_album_gain"
|
||||
const val R128_TRACK = "r128_track_gain"
|
||||
const val R128_ALBUM = "r128_album_gain"
|
||||
val REPLAY_GAIN_TAGS = arrayOf(TAG_RG_TRACK, TAG_RG_ALBUM, R128_ALBUM, R128_TRACK)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,9 @@ interface InternalPlayer {
|
|||
data class Open(val uri: Uri) : Action()
|
||||
}
|
||||
|
||||
/**
|
||||
* A representation of the current state of audio playback. Use [from] to create an instance.
|
||||
*/
|
||||
class State
|
||||
private constructor(
|
||||
/** Whether the player is actively playing audio or set to play audio in the future. */
|
||||
|
|
@ -157,7 +160,7 @@ interface InternalPlayer {
|
|||
* @param isAdvancing Whether the player is actively playing audio in this moment.
|
||||
* @param positionMs The current position of the player.
|
||||
*/
|
||||
fun new(isPlaying: Boolean, isAdvancing: Boolean, positionMs: Long) =
|
||||
fun from(isPlaying: Boolean, isAdvancing: Boolean, positionMs: Long) =
|
||||
State(
|
||||
isPlaying,
|
||||
// Minor sanity check: Make sure that advancing can't occur if already paused.
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.oxycblt.auxio.music.Genre
|
|||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager.Callback
|
||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager.Listener
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logE
|
||||
|
|
@ -45,7 +45,7 @@ import org.oxycblt.auxio.util.logW
|
|||
* - If you want to use the playback state with the ExoPlayer instance or system-side things, use
|
||||
* [org.oxycblt.auxio.playback.system.PlaybackService].
|
||||
*
|
||||
* Internal consumers should usually use [Callback], however the component that manages the player
|
||||
* Internal consumers should usually use [Listener], however the component that manages the player
|
||||
* itself should instead use [InternalPlayer].
|
||||
*
|
||||
* All access should be done with [PlaybackStateManager.getInstance].
|
||||
|
|
@ -54,7 +54,7 @@ import org.oxycblt.auxio.util.logW
|
|||
*/
|
||||
class PlaybackStateManager private constructor() {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
private val callbacks = mutableListOf<Callback>()
|
||||
private val listeners = mutableListOf<Listener>()
|
||||
private var internalPlayer: InternalPlayer? = null
|
||||
private var pendingAction: InternalPlayer.Action? = null
|
||||
private var isInitialized = false
|
||||
|
|
@ -74,7 +74,7 @@ class PlaybackStateManager private constructor() {
|
|||
var index = -1
|
||||
private set
|
||||
/** The current [InternalPlayer] state. */
|
||||
var playerState = InternalPlayer.State.new(isPlaying = false, isAdvancing = false, 0)
|
||||
var playerState = InternalPlayer.State.from(isPlaying = false, isAdvancing = false, 0)
|
||||
private set
|
||||
/** The current [RepeatMode] */
|
||||
var repeatMode = RepeatMode.NONE
|
||||
|
|
@ -93,32 +93,32 @@ class PlaybackStateManager private constructor() {
|
|||
get() = internalPlayer?.audioSessionId
|
||||
|
||||
/**
|
||||
* Add a [Callback] to this instance. This can be used to receive changes in the playback state.
|
||||
* Will immediately invoke [Callback] methods to initialize the instance with the current state.
|
||||
* @param callback The [Callback] to add.
|
||||
* @see Callback
|
||||
* Add a [Listener] to this instance. This can be used to receive changes in the playback state.
|
||||
* Will immediately invoke [Listener] methods to initialize the instance with the current state.
|
||||
* @param listener The [Listener] to add.
|
||||
* @see Listener
|
||||
*/
|
||||
@Synchronized
|
||||
fun addCallback(callback: Callback) {
|
||||
fun addCallback(listener: Listener) {
|
||||
if (isInitialized) {
|
||||
callback.onNewPlayback(index, queue, parent)
|
||||
callback.onRepeatChanged(repeatMode)
|
||||
callback.onShuffledChanged(isShuffled)
|
||||
callback.onStateChanged(playerState)
|
||||
listener.onNewPlayback(index, queue, parent)
|
||||
listener.onRepeatChanged(repeatMode)
|
||||
listener.onShuffledChanged(isShuffled)
|
||||
listener.onStateChanged(playerState)
|
||||
}
|
||||
|
||||
callbacks.add(callback)
|
||||
listeners.add(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a [Callback] from this instance, preventing it from recieving any further updates.
|
||||
* @param callback The [Callback] to remove. Does nothing if the [Callback] was never added in
|
||||
* Remove a [Listener] from this instance, preventing it from recieving any further updates.
|
||||
* @param listener The [Listener] to remove. Does nothing if the [Listener] was never added in
|
||||
* the first place.
|
||||
* @see Callback
|
||||
* @see Listener
|
||||
*/
|
||||
@Synchronized
|
||||
fun removeCallback(callback: Callback) {
|
||||
callbacks.remove(callback)
|
||||
fun removeCallback(listener: Listener) {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -586,43 +586,43 @@ class PlaybackStateManager private constructor() {
|
|||
// --- CALLBACKS ---
|
||||
|
||||
private fun notifyIndexMoved() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onIndexMoved(index)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyQueueChanged() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onQueueChanged(queue)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyQueueReworked() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onQueueReworked(index, queue)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyNewPlayback() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onNewPlayback(index, queue, parent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyStateChanged() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onStateChanged(playerState)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyRepeatModeChanged() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onRepeatChanged(repeatMode)
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyShuffledChanged() {
|
||||
for (callback in callbacks) {
|
||||
for (callback in listeners) {
|
||||
callback.onShuffledChanged(isShuffled)
|
||||
}
|
||||
}
|
||||
|
|
@ -631,7 +631,7 @@ class PlaybackStateManager private constructor() {
|
|||
* The interface for receiving updates from [PlaybackStateManager]. Add the listener to
|
||||
* [PlaybackStateManager] using [addCallback], remove them on destruction with [removeCallback].
|
||||
*/
|
||||
interface Callback {
|
||||
interface Listener {
|
||||
/**
|
||||
* Called when the position of the currently playing item has changed, changing the current
|
||||
* [Song], but no other queue attribute has changed.
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ import org.oxycblt.auxio.util.logD
|
|||
* A component that mirrors the current playback state into the [MediaSessionCompat] and
|
||||
* [NotificationComponent].
|
||||
* @param context [Context] required to initialize components.
|
||||
* @param callback [Callback] to forward notification updates to.
|
||||
* @param listener [Listener] to forward notification updates to.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class MediaSessionComponent(private val context: Context, private val callback: Callback) :
|
||||
MediaSessionCompat.Callback(), PlaybackStateManager.Callback, Settings.Callback {
|
||||
class MediaSessionComponent(private val context: Context, private val listener: Listener) :
|
||||
MediaSessionCompat.Callback(), PlaybackStateManager.Listener, Settings.Listener {
|
||||
private val mediaSession =
|
||||
MediaSessionCompat(context, context.packageName).apply {
|
||||
isActive = true
|
||||
|
|
@ -113,7 +113,7 @@ class MediaSessionComponent(private val context: Context, private val callback:
|
|||
invalidateSessionState()
|
||||
notification.updatePlaying(playbackManager.playerState.isPlaying)
|
||||
if (!provider.isBusy) {
|
||||
callback.onPostNotification(notification)
|
||||
listener.onPostNotification(notification)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,7 +306,7 @@ class MediaSessionComponent(private val context: Context, private val callback:
|
|||
val metadata = builder.build()
|
||||
mediaSession.setMetadata(metadata)
|
||||
notification.updateMetadata(metadata)
|
||||
callback.onPostNotification(notification)
|
||||
listener.onPostNotification(notification)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -393,12 +393,12 @@ class MediaSessionComponent(private val context: Context, private val callback:
|
|||
}
|
||||
|
||||
if (!provider.isBusy) {
|
||||
callback.onPostNotification(notification)
|
||||
listener.onPostNotification(notification)
|
||||
}
|
||||
}
|
||||
|
||||
/** An interface for handling changes in the notification configuration. */
|
||||
interface Callback {
|
||||
interface Listener {
|
||||
/**
|
||||
* Called when the [NotificationComponent] changes, requiring it to be re-posed.
|
||||
* @param notification The new [NotificationComponent].
|
||||
|
|
|
|||
|
|
@ -148,9 +148,9 @@ class NotificationComponent(private val context: Context, sessionToken: MediaSes
|
|||
iconRes, actionName, context.newBroadcastPendingIntent(actionName))
|
||||
.build()
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** Notification channel used by solely the playback notification. */
|
||||
private val CHANNEL_INFO =
|
||||
val CHANNEL_INFO =
|
||||
ChannelInfo(
|
||||
id = BuildConfig.APPLICATION_ID + ".channel.PLAYBACK",
|
||||
nameRes = R.string.lbl_playback)
|
||||
|
|
|
|||
|
|
@ -79,9 +79,9 @@ class PlaybackService :
|
|||
Service(),
|
||||
Player.Listener,
|
||||
InternalPlayer,
|
||||
MediaSessionComponent.Callback,
|
||||
Settings.Callback,
|
||||
MusicStore.Callback {
|
||||
MediaSessionComponent.Listener,
|
||||
Settings.Listener,
|
||||
MusicStore.Listener {
|
||||
// Player components
|
||||
private lateinit var player: ExoPlayer
|
||||
private lateinit var replayGainProcessor: ReplayGainAudioProcessor
|
||||
|
|
@ -217,7 +217,7 @@ class PlaybackService :
|
|||
get() = settings.rewindWithPrev && player.currentPosition > REWIND_THRESHOLD
|
||||
|
||||
override fun getState(durationMs: Long) =
|
||||
InternalPlayer.State.new(
|
||||
InternalPlayer.State.from(
|
||||
player.playWhenReady,
|
||||
player.isPlaying,
|
||||
// The position value can be below zero or past the expected duration, make
|
||||
|
|
|
|||
|
|
@ -51,11 +51,11 @@ class SearchAdapter(private val listener: SelectableListListener) :
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
when (viewType) {
|
||||
SongViewHolder.VIEW_TYPE -> SongViewHolder.new(parent)
|
||||
AlbumViewHolder.VIEW_TYPE -> AlbumViewHolder.new(parent)
|
||||
ArtistViewHolder.VIEW_TYPE -> ArtistViewHolder.new(parent)
|
||||
GenreViewHolder.VIEW_TYPE -> GenreViewHolder.new(parent)
|
||||
HeaderViewHolder.VIEW_TYPE -> HeaderViewHolder.new(parent)
|
||||
SongViewHolder.VIEW_TYPE -> SongViewHolder.from(parent)
|
||||
AlbumViewHolder.VIEW_TYPE -> AlbumViewHolder.from(parent)
|
||||
ArtistViewHolder.VIEW_TYPE -> ArtistViewHolder.from(parent)
|
||||
GenreViewHolder.VIEW_TYPE -> GenreViewHolder.from(parent)
|
||||
HeaderViewHolder.VIEW_TYPE -> HeaderViewHolder.from(parent)
|
||||
else -> error("Invalid item type $viewType")
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +81,9 @@ class SearchAdapter(private val listener: SelectableListListener) :
|
|||
differ.submitList(newList, callback)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
private val DIFF_CALLBACK =
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleItemCallback<Item>() {
|
||||
override fun areContentsTheSame(oldItem: Item, newItem: Item) =
|
||||
when {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import org.oxycblt.auxio.util.logD
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class SearchViewModel(application: Application) :
|
||||
AndroidViewModel(application), MusicStore.Callback {
|
||||
AndroidViewModel(application), MusicStore.Listener {
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
private val settings = Settings(context)
|
||||
private var lastQuery: String? = null
|
||||
|
|
@ -212,11 +212,11 @@ class SearchViewModel(application: Application) :
|
|||
search(lastQuery)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/**
|
||||
* Converts the output of [Normalizer] to remove any junk characters added by it's
|
||||
* replacements.
|
||||
*/
|
||||
private val NORMALIZATION_SANITIZE_REGEX = Regex("\\p{InCombiningDiacriticalMarks}+")
|
||||
val NORMALIZATION_SANITIZE_REGEX = Regex("\\p{InCombiningDiacriticalMarks}+")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,14 +152,14 @@ class AboutFragment : ViewBindingFragment<FragmentAboutBinding>() {
|
|||
startActivity(chooserIntent)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** The URL to the source code. */
|
||||
private const val LINK_SOURCE = "https://github.com/OxygenCobalt/Auxio"
|
||||
const val LINK_SOURCE = "https://github.com/OxygenCobalt/Auxio"
|
||||
/** The URL to the app wiki. */
|
||||
private const val LINK_WIKI = "$LINK_SOURCE/wiki"
|
||||
const val LINK_WIKI = "$LINK_SOURCE/wiki"
|
||||
/** The URL to the licenses wiki page. */
|
||||
private const val LINK_LICENSES = "$LINK_WIKI/Licenses"
|
||||
const val LINK_LICENSES = "$LINK_WIKI/Licenses"
|
||||
/** The URL to the app author. */
|
||||
private const val LINK_AUTHOR = "https://github.com/OxygenCobalt"
|
||||
const val LINK_AUTHOR = "https://github.com/OxygenCobalt"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ import org.oxycblt.auxio.util.unlikelyToBeNull
|
|||
* mutability
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class Settings(private val context: Context, private val callback: Callback? = null) :
|
||||
class Settings(private val context: Context, private val listener: Listener? = null) :
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private val inner = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||
|
||||
init {
|
||||
if (callback != null) {
|
||||
if (listener != null) {
|
||||
inner.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ class Settings(private val context: Context, private val callback: Callback? = n
|
|||
}
|
||||
|
||||
/**
|
||||
* Release this instance and any callbacks held by it. This is not needed if no [Callback] was
|
||||
* Release this instance and any callbacks held by it. This is not needed if no [Listener] was
|
||||
* originally attached.
|
||||
*/
|
||||
fun release() {
|
||||
|
|
@ -162,11 +162,11 @@ class Settings(private val context: Context, private val callback: Callback? = n
|
|||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||
unlikelyToBeNull(callback).onSettingChanged(key)
|
||||
unlikelyToBeNull(listener).onSettingChanged(key)
|
||||
}
|
||||
|
||||
/** Simplified callback for settings changes. */
|
||||
interface Callback {
|
||||
/** Simplified listener for settings changes. */
|
||||
interface Listener {
|
||||
// TODO: Refactor this lifecycle
|
||||
/**
|
||||
* Called when a setting has changed.
|
||||
|
|
|
|||
|
|
@ -162,8 +162,8 @@ constructor(
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PREFERENCE_DEFAULT_VALUE_FIELD: Field by
|
||||
private companion object {
|
||||
val PREFERENCE_DEFAULT_VALUE_FIELD: Field by
|
||||
lazyReflectedField(Preference::class, "mDefaultValue")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import org.oxycblt.auxio.BuildConfig
|
|||
import org.oxycblt.auxio.R
|
||||
|
||||
/**
|
||||
* The companion dialog to [IntListPreference]. Use [new] to create an instance.
|
||||
* The companion dialog to [IntListPreference]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class IntListPreferenceDialog : PreferenceDialogFragmentCompat() {
|
||||
|
|
@ -62,11 +62,10 @@ class IntListPreferenceDialog : PreferenceDialogFragmentCompat() {
|
|||
* @param preference The [IntListPreference] to display.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(preference: IntListPreference): IntListPreferenceDialog {
|
||||
return IntListPreferenceDialog().apply {
|
||||
fun from(preference: IntListPreference) =
|
||||
IntListPreferenceDialog().apply {
|
||||
// Populate the key field required by PreferenceDialogFragmentCompat.
|
||||
arguments = Bundle().apply { putString(ARG_KEY, preference.key) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class PreferenceFragment : PreferenceFragmentCompat() {
|
|||
is IntListPreference -> {
|
||||
// Copy the built-in preference dialog launching code into our project so
|
||||
// we can automatically use the provided preference class.
|
||||
val dialog = IntListPreferenceDialog.new(preference)
|
||||
val dialog = IntListPreferenceDialog.from(preference)
|
||||
dialog.setTargetFragment(this, 0)
|
||||
dialog.show(parentFragmentManager, IntListPreferenceDialog.TAG)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,8 +136,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
/** @see AppBarLayout.BaseBehavior.MAX_OFFSET_ANIMATION_DURATION */
|
||||
private const val APP_BAR_LAYOUT_MAX_OFFSET_ANIMATION_DURATION = 600
|
||||
const val APP_BAR_LAYOUT_MAX_OFFSET_ANIMATION_DURATION = 600
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class AccentAdapter(private val listener: ClickableListListener) :
|
|||
|
||||
override fun getItemCount() = Accent.MAX
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = AccentViewHolder.new(parent)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
AccentViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: AccentViewHolder, position: Int) =
|
||||
throw NotImplementedError()
|
||||
|
|
@ -75,13 +76,13 @@ class AccentAdapter(private val listener: ClickableListListener) :
|
|||
notifyItemChanged(accent.index, PAYLOAD_SELECTION_CHANGED)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PAYLOAD_SELECTION_CHANGED = Any()
|
||||
private companion object {
|
||||
val PAYLOAD_SELECTION_CHANGED = Any()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays an [Accent] choice. Use [new] to create an instance.
|
||||
* A [RecyclerView.ViewHolder] that displays an [Accent] choice. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class AccentViewHolder private constructor(private val binding: ItemAccentBinding) :
|
||||
|
|
@ -124,6 +125,7 @@ class AccentViewHolder private constructor(private val binding: ItemAccentBindin
|
|||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun new(parent: View) = AccentViewHolder(ItemAccentBinding.inflate(parent.context.inflater))
|
||||
fun from(parent: View) =
|
||||
AccentViewHolder(ItemAccentBinding.inflate(parent.context.inflater))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class AccentCustomizeDialog :
|
|||
accentAdapter.setSelectedAccent(item)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_PENDING_ACCENT = BuildConfig.APPLICATION_ID + ".key.PENDING_ACCENT"
|
||||
private companion object {
|
||||
const val KEY_PENDING_ACCENT = BuildConfig.APPLICATION_ID + ".key.PENDING_ACCENT"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import org.oxycblt.auxio.util.logD
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class WidgetComponent(private val context: Context) :
|
||||
PlaybackStateManager.Callback, Settings.Callback {
|
||||
PlaybackStateManager.Listener, Settings.Listener {
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
private val settings = Settings(context, this)
|
||||
private val widgetProvider = WidgetProvider()
|
||||
|
|
|
|||
Loading…
Reference in a new issue