mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-16 01:10:36 +03:00
Add scrollbar to playlist view,
implement SectionedAdapter for Artists
This commit is contained in:
parent
e337177715
commit
80e587c1aa
@ -20,6 +20,7 @@ import com.drakeet.multitype.ItemViewBinder
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.domain.ArtistOrIndex
|
||||
import org.moire.ultrasonic.domain.Identifiable
|
||||
import org.moire.ultrasonic.imageloader.ImageLoader
|
||||
import org.moire.ultrasonic.util.FileUtil
|
||||
import org.moire.ultrasonic.util.Settings
|
||||
@ -32,14 +33,16 @@ class ArtistRowBinder(
|
||||
val onContextMenuClick: (MenuItem, ArtistOrIndex) -> Boolean,
|
||||
private val imageLoader: ImageLoader,
|
||||
private val enableSections: Boolean = true
|
||||
) : ItemViewBinder<ArtistOrIndex, ArtistRowBinder.ViewHolder>(), KoinComponent {
|
||||
) : ItemViewBinder<ArtistOrIndex, ArtistRowBinder.ViewHolder>(),
|
||||
KoinComponent,
|
||||
Utils.SectionedBinder {
|
||||
|
||||
val layout = R.layout.list_item_artist
|
||||
val contextMenuLayout = R.menu.context_menu_artist
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, item: ArtistOrIndex) {
|
||||
holder.textView.text = item.name
|
||||
holder.section.text = getSectionForArtist(item)
|
||||
holder.section.text = getSectionForDisplay(item)
|
||||
holder.section.isVisible = enableSections
|
||||
holder.layout.setOnClickListener { onItemClick(item) }
|
||||
holder.layout.setOnLongClickListener {
|
||||
@ -70,7 +73,14 @@ class ArtistRowBinder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSectionForArtist(item: ArtistOrIndex): String {
|
||||
override fun getSectionName(item: Identifiable): String {
|
||||
val index = adapter.items.indexOf(item)
|
||||
if (index == -1 || item !is ArtistOrIndex) return ""
|
||||
|
||||
return getSectionFromName(item.name ?: "")
|
||||
}
|
||||
|
||||
private fun getSectionForDisplay(item: ArtistOrIndex): String {
|
||||
val index = adapter.items.indexOf(item)
|
||||
|
||||
if (index == -1) return " "
|
||||
|
@ -15,6 +15,7 @@ import androidx.recyclerview.widget.AsyncListDiffer
|
||||
import androidx.recyclerview.widget.AsyncListDiffer.ListListener
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import com.drakeet.multitype.MultiTypeAdapter
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import org.moire.ultrasonic.domain.Identifiable
|
||||
import org.moire.ultrasonic.util.BoundedTreeSet
|
||||
import timber.log.Timber
|
||||
@ -26,7 +27,7 @@ import timber.log.Timber
|
||||
* It should be kept generic enough that it can be used a Base for all lists in the app.
|
||||
*/
|
||||
@Suppress("unused", "UNUSED_PARAMETER")
|
||||
class BaseAdapter<T : Identifiable> : MultiTypeAdapter() {
|
||||
class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView.SectionedAdapter {
|
||||
|
||||
// Update the BoundedTreeSet if selection type is changed
|
||||
internal var selectionType: SelectionType = SelectionType.MULTIPLE
|
||||
@ -221,4 +222,15 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter() {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
val type = getItemViewType(position)
|
||||
val binder = types.getType<Any>(type).delegate
|
||||
|
||||
if (binder is Utils.SectionedBinder) {
|
||||
return binder.getSectionName(items[position] as Identifiable)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.view.View
|
||||
import android.widget.PopupMenu
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.domain.Identifiable
|
||||
import org.moire.ultrasonic.util.Settings
|
||||
import org.moire.ultrasonic.util.Util
|
||||
|
||||
@ -69,4 +70,8 @@ object Utils {
|
||||
playingImage = Util.getDrawableFromAttribute(context, R.attr.media_play_small)
|
||||
}
|
||||
}
|
||||
|
||||
interface SectionedBinder {
|
||||
fun getSectionName(item: Identifiable): String
|
||||
}
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
||||
private fun moreRandomTracks() {
|
||||
val listSize = arguments?.getInt(Constants.INTENT_ALBUM_LIST_SIZE, 0) ?: 0
|
||||
|
||||
moreButton!!.setOnClickListener { it: View? ->
|
||||
moreButton!!.setOnClickListener {
|
||||
val offset = requireArguments().getInt(
|
||||
Constants.INTENT_ALBUM_LIST_OFFSET, 0
|
||||
) + listSize
|
||||
|
@ -1,23 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:orientation="vertical"
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent">
|
||||
a:layout_height="fill_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
a:id="@+id/playlist_empty"
|
||||
a:text="@string/playlist.empty"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:padding="10dip"/>
|
||||
a:padding="10dip"
|
||||
a:text="@string/playlist.empty" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
<com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
a:id="@+id/playlist_view"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="0dip"
|
||||
a:layout_weight="1"
|
||||
a:fastScrollEnabled="true" />
|
||||
a:clipToPadding="false"
|
||||
a:paddingTop="8dp"
|
||||
a:paddingBottom="8dp"
|
||||
app:fastScrollAutoHide="true"
|
||||
app:fastScrollAutoHideDelay="2000"
|
||||
app:fastScrollPopupBackgroundSize="42dp"
|
||||
app:fastScrollPopupBgColor="@color/cyan"
|
||||
app:fastScrollPopupPosition="adjacent"
|
||||
app:fastScrollPopupTextColor="@android:color/primary_text_dark"
|
||||
app:fastScrollPopupTextSize="28sp"
|
||||
app:fastScrollThumbColor="@color/cyan"
|
||||
app:fastScrollTrackColor="@color/dividerColor" />
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user