show the fetched artists on the list
This commit is contained in:
parent
c53418719a
commit
75df0fc4b9
4 changed files with 99 additions and 1 deletions
|
@ -0,0 +1,60 @@
|
|||
package com.simplemobiletools.musicplayer.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.models.Artist
|
||||
import kotlinx.android.synthetic.main.item_artist.view.*
|
||||
import java.util.*
|
||||
|
||||
class ArtistsAdapter(activity: SimpleActivity, val artists: ArrayList<Artist>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_artists
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_artist, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val artist = artists.getOrNull(position) ?: return
|
||||
holder.bindView(artist, true, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, artist)
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
}
|
||||
|
||||
override fun getItemCount() = artists.size
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
override fun actionItemPressed(id: Int) {}
|
||||
|
||||
override fun getSelectableItemCount() = artists.size
|
||||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = artists.getOrNull(position)?.id
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = artists.indexOfFirst { it.id == key }
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
override fun onActionModeDestroyed() {}
|
||||
|
||||
private fun getItemWithKey(key: Int): Artist? = artists.firstOrNull { it.id == key }
|
||||
|
||||
private fun setupView(view: View, artist: Artist) {
|
||||
view.apply {
|
||||
artist_frame?.isSelected = selectedKeys.contains(artist.id)
|
||||
artist_title.text = artist.title
|
||||
artist_title.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,12 +9,18 @@ import com.simplemobiletools.commons.extensions.getStringValue
|
|||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.adapters.ArtistsAdapter
|
||||
import com.simplemobiletools.musicplayer.models.Artist
|
||||
import kotlinx.android.synthetic.main.fragment_artists.view.*
|
||||
|
||||
class ArtistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
override fun setupFragment(activity: SimpleActivity) {
|
||||
getArtists(activity) {
|
||||
getArtists(activity) { artists ->
|
||||
ArtistsAdapter(activity, artists, artists_list) {
|
||||
|
||||
}.apply {
|
||||
artists_list.adapter = this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
28
app/src/main/res/layout/item_artist.xml
Normal file
28
app/src/main/res/layout/item_artist.xml
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/artist_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="@drawable/selector">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/artist_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/artist_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/text_color"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
4
app/src/main/res/menu/cab_artists.xml
Normal file
4
app/src/main/res/menu/cab_artists.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu>
|
||||
|
||||
</menu>
|
Loading…
Reference in a new issue