Added grid layout change option
This commit is contained in:
parent
fc7c3b30f5
commit
6210065221
49 changed files with 1571 additions and 1428 deletions
|
@ -22,22 +22,39 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.checkbox.MaterialCheckBox;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.model.CategoryInfo;
|
||||
import code.name.monkey.retromusic.util.SwipeAndDragHelper;
|
||||
import com.google.android.material.checkbox.MaterialCheckBox;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapter.ViewHolder>
|
||||
implements SwipeAndDragHelper.ActionCompletionContract {
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
MaterialCheckBox checkBox;
|
||||
|
||||
View dragView;
|
||||
|
||||
TextView title;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
checkBox = view.findViewById(R.id.checkbox);
|
||||
checkBox.setButtonTintList(
|
||||
ColorStateList.valueOf(ThemeStore.Companion.accentColor(checkBox.getContext())));
|
||||
title = view.findViewById(R.id.title);
|
||||
dragView = view.findViewById(R.id.drag_view);
|
||||
}
|
||||
}
|
||||
|
||||
public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapter.ViewHolder> implements SwipeAndDragHelper.ActionCompletionContract {
|
||||
private List<CategoryInfo> categoryInfos;
|
||||
|
||||
private ItemTouchHelper touchHelper;
|
||||
|
||||
public CategoryInfoAdapter(@NonNull List<CategoryInfo> categoryInfos) {
|
||||
|
@ -46,52 +63,6 @@ public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapte
|
|||
touchHelper = new ItemTouchHelper(swipeAndDragHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public CategoryInfoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.preference_dialog_library_categories_listitem, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CategoryInfoAdapter.ViewHolder holder, int position) {
|
||||
CategoryInfo categoryInfo = categoryInfos.get(position);
|
||||
|
||||
holder.checkBox.setChecked(categoryInfo.visible);
|
||||
holder.title.setText(holder.title.getResources().getString(categoryInfo.category.stringRes));
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (!(categoryInfo.visible && isLastCheckedCategory(categoryInfo))) {
|
||||
categoryInfo.visible = !categoryInfo.visible;
|
||||
holder.checkBox.setChecked(categoryInfo.visible);
|
||||
} else {
|
||||
Toast.makeText(holder.itemView.getContext(), R.string.you_have_to_select_at_least_one_category, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
holder.dragView.setOnTouchListener((view, event) -> {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
touchHelper.startDrag(holder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return categoryInfos.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewMoved(int oldPosition, int newPosition) {
|
||||
CategoryInfo categoryInfo = categoryInfos.get(oldPosition);
|
||||
categoryInfos.remove(oldPosition);
|
||||
categoryInfos.add(newPosition, categoryInfo);
|
||||
notifyItemMoved(oldPosition, newPosition);
|
||||
}
|
||||
|
||||
public void attachToRecyclerView(RecyclerView recyclerView) {
|
||||
touchHelper.attachToRecyclerView(recyclerView);
|
||||
}
|
||||
|
@ -106,26 +77,62 @@ public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapte
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return categoryInfos.size();
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CategoryInfoAdapter.ViewHolder holder, int position) {
|
||||
CategoryInfo categoryInfo = categoryInfos.get(position);
|
||||
|
||||
holder.checkBox.setChecked(categoryInfo.visible);
|
||||
holder.title.setText(holder.title.getResources().getString(categoryInfo.category.stringRes));
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (!(categoryInfo.visible && isLastCheckedCategory(categoryInfo))) {
|
||||
categoryInfo.visible = !categoryInfo.visible;
|
||||
holder.checkBox.setChecked(categoryInfo.visible);
|
||||
} else {
|
||||
Toast.makeText(holder.itemView.getContext(), R.string.you_have_to_select_at_least_one_category,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
holder.dragView.setOnTouchListener((view, event) -> {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
touchHelper.startDrag(holder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public CategoryInfoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.preference_dialog_library_categories_listitem, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewMoved(int oldPosition, int newPosition) {
|
||||
CategoryInfo categoryInfo = categoryInfos.get(oldPosition);
|
||||
categoryInfos.remove(oldPosition);
|
||||
categoryInfos.add(newPosition, categoryInfo);
|
||||
notifyItemMoved(oldPosition, newPosition);
|
||||
}
|
||||
|
||||
private boolean isLastCheckedCategory(CategoryInfo categoryInfo) {
|
||||
if (categoryInfo.visible) {
|
||||
for (CategoryInfo c : categoryInfos) {
|
||||
if (c != categoryInfo && c.visible) return false;
|
||||
if (c != categoryInfo && c.visible) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
MaterialCheckBox checkBox;
|
||||
TextView title;
|
||||
View dragView;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
checkBox = view.findViewById(R.id.checkbox);
|
||||
checkBox.setButtonTintList(ColorStateList.valueOf(ThemeStore.Companion.accentColor(checkBox.getContext())));
|
||||
title = view.findViewById(R.id.title);
|
||||
dragView = view.findViewById(R.id.drag_view);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
|
@ -11,64 +13,64 @@ import code.name.monkey.retromusic.views.CircularImageView
|
|||
import com.bumptech.glide.Glide
|
||||
|
||||
class ContributorAdapter(
|
||||
private var contributors: List<Contributor>
|
||||
private var contributors: List<Contributor>
|
||||
) : RecyclerView.Adapter<ContributorAdapter.ViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return if (viewType == HEADER) {
|
||||
ViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(
|
||||
R.layout.item_contributor_header,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
} else ViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(
|
||||
R.layout.item_contributor,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return if (viewType == HEADER) {
|
||||
ViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(
|
||||
R.layout.item_contributor_header,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
} else ViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(
|
||||
R.layout.item_contributor,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val HEADER: Int = 0
|
||||
const val ITEM: Int = 1
|
||||
}
|
||||
companion object {
|
||||
const val HEADER: Int = 0
|
||||
const val ITEM: Int = 1
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (position == 0) {
|
||||
HEADER
|
||||
} else {
|
||||
ITEM
|
||||
}
|
||||
}
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (position == 0) {
|
||||
HEADER
|
||||
} else {
|
||||
ITEM
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val contributor = contributors[position]
|
||||
holder.bindData(contributor)
|
||||
holder.itemView.setOnClickListener {
|
||||
openUrl(it?.context as Activity, contributors[position].link)
|
||||
}
|
||||
}
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val contributor = contributors[position]
|
||||
holder.bindData(contributor)
|
||||
holder.itemView.setOnClickListener {
|
||||
openUrl(it?.context as Activity, contributors[position].link)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return contributors.size
|
||||
}
|
||||
override fun getItemCount(): Int {
|
||||
return contributors.size
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val title: TextView = itemView.findViewById(R.id.title)
|
||||
val text: TextView = itemView.findViewById(R.id.text)
|
||||
val image: CircularImageView = itemView.findViewById(R.id.icon)
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val title: TextView = itemView.findViewById(R.id.title)
|
||||
val text: TextView = itemView.findViewById(R.id.text)
|
||||
val image: CircularImageView = itemView.findViewById(R.id.icon)
|
||||
|
||||
internal fun bindData(contributor: Contributor) {
|
||||
title.text = contributor.name
|
||||
text.text = contributor.summary
|
||||
println(contributor.profileImage)
|
||||
Glide.with(image.context).load(contributor.profileImage)
|
||||
.error(R.drawable.ic_account_white_24dp)
|
||||
.placeholder(R.drawable.ic_account_white_24dp).dontAnimate().into(image)
|
||||
}
|
||||
}
|
||||
internal fun bindData(contributor: Contributor) {
|
||||
title.text = contributor.name
|
||||
text.text = contributor.summary
|
||||
println(contributor.profileImage)
|
||||
Glide.with(image.context).load(contributor.profileImage)
|
||||
.error(R.drawable.ic_account_white_24dp)
|
||||
.placeholder(R.drawable.ic_account_white_24dp).dontAnimate().into(image)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,15 +9,19 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.model.Genre
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
*/
|
||||
|
||||
class GenreAdapter(
|
||||
private val activity: Activity, dataSet: ArrayList<Genre>, private val mItemLayoutRes: Int
|
||||
private val activity: Activity,
|
||||
dataSet: ArrayList<Genre>,
|
||||
private val mItemLayoutRes: Int
|
||||
) : RecyclerView.Adapter<GenreAdapter.ViewHolder>() {
|
||||
|
||||
var dataSet = ArrayList<Genre>()
|
||||
private set
|
||||
|
||||
|
@ -32,7 +36,12 @@ class GenreAdapter(
|
|||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val genre = dataSet[position]
|
||||
holder.title?.text = genre.name
|
||||
holder.text?.text = String.format(Locale.getDefault(), "%d %s", genre.songCount, if (genre.songCount > 1) activity.getString(R.string.songs) else activity.getString(R.string.song))
|
||||
holder.text?.text = String.format(
|
||||
Locale.getDefault(),
|
||||
"%d %s",
|
||||
genre.songCount,
|
||||
if (genre.songCount > 1) activity.getString(R.string.songs) else activity.getString(R.string.song)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
|
|
@ -23,7 +23,8 @@ import code.name.monkey.retromusic.model.Playlist
|
|||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
|
||||
class HomeAdapter(
|
||||
private val activity: AppCompatActivity, private val displayMetrics: DisplayMetrics
|
||||
private val activity: AppCompatActivity,
|
||||
private val displayMetrics: DisplayMetrics
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
private var list = ArrayList<Home>()
|
||||
|
@ -137,14 +138,9 @@ class HomeAdapter(
|
|||
if (songs.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
val songAdapter = SongAdapter(
|
||||
activity, songs, R.layout.item_album_card, false, null
|
||||
)
|
||||
layoutManager = GridLayoutManager(
|
||||
activity, 1, GridLayoutManager.HORIZONTAL, false
|
||||
)
|
||||
val songAdapter = SongAdapter(activity, songs, R.layout.item_album_card, null)
|
||||
layoutManager = GridLayoutManager(activity, 1, GridLayoutManager.HORIZONTAL, false)
|
||||
adapter = songAdapter
|
||||
|
||||
}
|
||||
title.text = activity.getString(titleRes)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ import com.bumptech.glide.Glide
|
|||
import android.util.Pair as UtilPair
|
||||
|
||||
class SearchAdapter(
|
||||
private val activity: AppCompatActivity, private var dataSet: List<Any>?
|
||||
private val activity: AppCompatActivity,
|
||||
private var dataSet: List<Any>?
|
||||
) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {
|
||||
|
||||
fun swapDataSet(dataSet: MutableList<Any>) {
|
||||
|
@ -39,7 +40,13 @@ class SearchAdapter(
|
|||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return if (viewType == HEADER) ViewHolder(LayoutInflater.from(activity).inflate(R.layout.sub_header, parent, false), viewType)
|
||||
return if (viewType == HEADER) ViewHolder(
|
||||
LayoutInflater.from(activity).inflate(
|
||||
R.layout.sub_header,
|
||||
parent,
|
||||
false
|
||||
), viewType
|
||||
)
|
||||
else
|
||||
ViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_list, parent, false), viewType)
|
||||
}
|
||||
|
@ -51,14 +58,14 @@ class SearchAdapter(
|
|||
holder.title?.text = album.title
|
||||
holder.text?.text = album.artistName
|
||||
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
||||
.checkIgnoreMediaStore(activity).build().into(holder.image)
|
||||
.checkIgnoreMediaStore(activity).build().into(holder.image)
|
||||
}
|
||||
ARTIST -> {
|
||||
val artist = dataSet?.get(position) as Artist
|
||||
holder.title?.text = artist.name
|
||||
holder.text?.text = MusicUtil.getArtistInfoString(activity, artist)
|
||||
ArtistGlideRequest.Builder.from(Glide.with(activity), artist).build()
|
||||
.into(holder.image)
|
||||
.into(holder.image)
|
||||
}
|
||||
SONG -> {
|
||||
val song = dataSet?.get(position) as Song
|
||||
|
@ -108,11 +115,17 @@ class SearchAdapter(
|
|||
val item = dataSet!![adapterPosition]
|
||||
when (itemViewType) {
|
||||
ALBUM -> {
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(activity, UtilPair.create(image, activity.getString(R.string.transition_album_art)))
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
UtilPair.create(image, activity.getString(R.string.transition_album_art))
|
||||
)
|
||||
NavigationUtil.goToAlbumOptions(activity, (item as Album).id, options)
|
||||
}
|
||||
ARTIST -> {
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(activity, UtilPair.create(image, activity.getString(R.string.transition_artist_image)))
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
UtilPair.create(image, activity.getString(R.string.transition_artist_image))
|
||||
)
|
||||
NavigationUtil.goToArtistOptions(activity, (item as Artist).id, options)
|
||||
}
|
||||
GENRE -> {
|
||||
|
|
|
@ -12,37 +12,38 @@ import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
|||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCover
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.signature.MediaStoreSignature
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
import java.io.File
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
class SongFileAdapter(
|
||||
private val activity: AppCompatActivity,
|
||||
private var dataSet: List<File>?,
|
||||
private val itemLayoutRes: Int,
|
||||
private val callbacks: Callbacks?,
|
||||
cabHolder: CabHolder?
|
||||
private val activity: AppCompatActivity,
|
||||
private var dataSet: List<File>,
|
||||
private val itemLayoutRes: Int,
|
||||
private val callbacks: Callbacks?,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsMultiSelectAdapter<SongFileAdapter.ViewHolder, File>(
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
), FastScrollRecyclerView.SectionedAdapter {
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
), PopupTextProvider {
|
||||
|
||||
init {
|
||||
this.setHasStableIds(true)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (dataSet!![position].isDirectory) FOLDER else FILE
|
||||
return if (dataSet[position].isDirectory) FOLDER else FILE
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return dataSet!![position].hashCode().toLong()
|
||||
return dataSet[position].hashCode().toLong()
|
||||
}
|
||||
|
||||
fun swapDataSet(songFiles: List<File>) {
|
||||
|
@ -55,7 +56,7 @@ class SongFileAdapter(
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, index: Int) {
|
||||
val file = dataSet!![index]
|
||||
val file = dataSet[index]
|
||||
holder.itemView.isActivated = isChecked(file)
|
||||
holder.title?.text = getFileTitle(file)
|
||||
if (holder.text != null) {
|
||||
|
@ -87,24 +88,23 @@ class SongFileAdapter(
|
|||
it.setImageResource(R.drawable.ic_folder_white_24dp)
|
||||
}
|
||||
holder.imageTextContainer?.setCardBackgroundColor(ATHUtil.resolveColor(activity, R.attr.colorSurface))
|
||||
|
||||
} else {
|
||||
val error = RetroUtil.getTintedVectorDrawable(
|
||||
activity, R.drawable.ic_file_music_white_24dp, iconColor
|
||||
activity, R.drawable.ic_file_music_white_24dp, iconColor
|
||||
)
|
||||
Glide.with(activity).load(AudioFileCover(file.path))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE).error(error).placeholder(error)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.signature(MediaStoreSignature("", file.lastModified(), 0)).into(holder.image)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE).error(error).placeholder(error)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.signature(MediaStoreSignature("", file.lastModified(), 0)).into(holder.image)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet!!.size
|
||||
return dataSet.size
|
||||
}
|
||||
|
||||
override fun getIdentifier(position: Int): File? {
|
||||
return dataSet!![position]
|
||||
return dataSet[position]
|
||||
}
|
||||
|
||||
override fun getName(`object`: File): String {
|
||||
|
@ -116,8 +116,12 @@ class SongFileAdapter(
|
|||
callbacks.onMultipleItemAction(menuItem, selection)
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
return dataSet!![position].name[0].toString().toUpperCase()
|
||||
override fun getPopupText(position: Int): String {
|
||||
return getSectionName(position)
|
||||
}
|
||||
|
||||
private fun getSectionName(position: Int): String {
|
||||
return MusicUtil.getSectionName(dataSet[position].name)
|
||||
}
|
||||
|
||||
interface Callbacks {
|
||||
|
@ -135,7 +139,7 @@ class SongFileAdapter(
|
|||
menu?.setOnClickListener { v ->
|
||||
val position = adapterPosition
|
||||
if (isPositionInRange(position)) {
|
||||
callbacks.onFileMenuClicked(dataSet!![position], v)
|
||||
callbacks.onFileMenuClicked(dataSet[position], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +154,7 @@ class SongFileAdapter(
|
|||
if (isInQuickSelectMode) {
|
||||
toggleChecked(position)
|
||||
} else {
|
||||
callbacks?.onFileSelected(dataSet!![position])
|
||||
callbacks?.onFileSelected(dataSet[position])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +165,7 @@ class SongFileAdapter(
|
|||
}
|
||||
|
||||
private fun isPositionInRange(position: Int): Boolean {
|
||||
return position >= 0 && position < dataSet!!.size
|
||||
return position >= 0 && position < dataSet.size
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import code.name.monkey.retromusic.util.MusicUtil
|
|||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
|
||||
open class AlbumAdapter(
|
||||
protected val activity: AppCompatActivity,
|
||||
|
@ -37,7 +37,7 @@ open class AlbumAdapter(
|
|||
activity,
|
||||
cabHolder,
|
||||
R.menu.menu_media_selection
|
||||
), FastScrollRecyclerView.SectionedAdapter {
|
||||
), PopupTextProvider {
|
||||
|
||||
var dataSet: ArrayList<Album>
|
||||
protected set
|
||||
|
@ -168,7 +168,11 @@ open class AlbumAdapter(
|
|||
return songs
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
override fun getPopupText(position: Int): String {
|
||||
return getSectionName(position)
|
||||
}
|
||||
|
||||
private fun getSectionName(position: Int): String {
|
||||
var sectionName: String? = null
|
||||
when (PreferenceUtil.getInstance(activity).albumSortOrder) {
|
||||
SortOrder.AlbumSortOrder.ALBUM_A_Z, SortOrder.AlbumSortOrder.ALBUM_Z_A -> sectionName =
|
||||
|
|
|
@ -70,7 +70,7 @@ class AlbumCoverPagerAdapter(
|
|||
|
||||
private val layout: Int
|
||||
get() {
|
||||
return when (PreferenceUtil.getInstance(activity).albumCoverStyle) {
|
||||
return when (PreferenceUtil.getInstance(requireContext()).albumCoverStyle) {
|
||||
AlbumCoverStyle.NORMAL -> R.layout.fragment_album_cover
|
||||
AlbumCoverStyle.FLAT -> R.layout.fragment_album_flat_cover
|
||||
AlbumCoverStyle.CIRCLE -> R.layout.fragment_album_circle_cover
|
||||
|
@ -95,7 +95,7 @@ class AlbumCoverPagerAdapter(
|
|||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val finalLayout = when {
|
||||
PreferenceUtil.getInstance(activity).carouselEffect() -> R.layout.fragment_album_carousel_cover
|
||||
PreferenceUtil.getInstance(requireContext()).carouselEffect() -> R.layout.fragment_album_carousel_cover
|
||||
else -> layout
|
||||
}
|
||||
val view = inflater.inflate(finalLayout, container, false)
|
||||
|
|
|
@ -13,59 +13,59 @@ import code.name.monkey.retromusic.interfaces.CabHolder
|
|||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
|
||||
class HorizontalAlbumAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Album>,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Album>,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
) : AlbumAdapter(
|
||||
activity, dataSet, HorizontalAdapterHelper.LAYOUT_RES, usePalette, cabHolder
|
||||
activity, dataSet, HorizontalAdapterHelper.LAYOUT_RES, usePalette, cabHolder
|
||||
) {
|
||||
|
||||
override fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
||||
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
||||
HorizontalAdapterHelper.applyMarginToLayoutParams(activity, params, viewType)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
override fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
||||
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
||||
HorizontalAdapterHelper.applyMarginToLayoutParams(activity, params, viewType)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun setColors(color: Int, holder: ViewHolder) {
|
||||
holder.title?.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
holder.text?.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
}
|
||||
override fun setColors(color: Int, holder: ViewHolder) {
|
||||
holder.title?.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
holder.text?.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
}
|
||||
|
||||
override fun loadAlbumCover(album: Album, holder: ViewHolder) {
|
||||
if (holder.image == null) return
|
||||
override fun loadAlbumCover(album: Album, holder: ViewHolder) {
|
||||
if (holder.image == null) return
|
||||
|
||||
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
||||
.checkIgnoreMediaStore(activity).generatePalette(activity).build()
|
||||
.into(object : RetroMusicColoredTarget(holder.image!!) {
|
||||
override fun onLoadCleared(placeholder: Drawable?) {
|
||||
super.onLoadCleared(placeholder)
|
||||
setColors(albumArtistFooterColor, holder)
|
||||
}
|
||||
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
||||
.checkIgnoreMediaStore(activity).generatePalette(activity).build()
|
||||
.into(object : RetroMusicColoredTarget(holder.image!!) {
|
||||
override fun onLoadCleared(placeholder: Drawable?) {
|
||||
super.onLoadCleared(placeholder)
|
||||
setColors(albumArtistFooterColor, holder)
|
||||
}
|
||||
|
||||
override fun onColorReady(color: Int) {
|
||||
if (usePalette) setColors(color, holder)
|
||||
else setColors(albumArtistFooterColor, holder)
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun onColorReady(color: Int) {
|
||||
if (usePalette) setColors(color, holder)
|
||||
else setColors(albumArtistFooterColor, holder)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun getAlbumText(album: Album): String? {
|
||||
return MusicUtil.getYearString(album.year)
|
||||
}
|
||||
override fun getAlbumText(album: Album): String? {
|
||||
return MusicUtil.getYearString(album.year)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return HorizontalAdapterHelper.getItemViewtype(position, itemCount)
|
||||
}
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return HorizontalAdapterHelper.getItemViewtype(position, itemCount)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = AlbumAdapter::class.java.simpleName
|
||||
}
|
||||
companion object {
|
||||
val TAG: String = AlbumAdapter::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import code.name.monkey.retromusic.model.Song
|
|||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
import java.util.ArrayList
|
||||
|
||||
class ArtistAdapter(
|
||||
|
@ -34,7 +34,7 @@ class ArtistAdapter(
|
|||
cabHolder: CabHolder?
|
||||
) : AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist>(
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
), FastScrollRecyclerView.SectionedAdapter {
|
||||
), PopupTextProvider {
|
||||
|
||||
fun swapDataSet(dataSet: ArrayList<Artist>) {
|
||||
this.dataSet = dataSet
|
||||
|
@ -70,7 +70,7 @@ class ArtistAdapter(
|
|||
|
||||
fun setColors(color: Int, holder: ViewHolder) {
|
||||
if (holder.paletteColorContainer != null) {
|
||||
holder.paletteColorContainer?.backgroundTintList = ColorStateList.valueOf(color)
|
||||
holder.paletteColorContainer?.setBackgroundColor(color)
|
||||
holder.title?.setTextColor(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
activity, ColorUtil.isColorLight(
|
||||
|
@ -126,7 +126,11 @@ class ArtistAdapter(
|
|||
return songs
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
override fun getPopupText(position: Int): String {
|
||||
return getSectionName(position)
|
||||
}
|
||||
|
||||
private fun getSectionName(position: Int): String {
|
||||
return MusicUtil.getSectionName(dataSet[position].name)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,26 +3,28 @@ package code.name.monkey.retromusic.adapter.base;
|
|||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.MenuRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder;
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder, I> extends RecyclerView.Adapter<VH> implements MaterialCab.Callback {
|
||||
public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder, I> extends RecyclerView.Adapter<VH>
|
||||
implements MaterialCab.Callback {
|
||||
|
||||
private MaterialCab cab;
|
||||
|
||||
@Nullable
|
||||
private final CabHolder cabHolder;
|
||||
private final Context context;
|
||||
private MaterialCab cab;
|
||||
|
||||
private ArrayList<I> checked;
|
||||
|
||||
private final Context context;
|
||||
|
||||
private int menuRes;
|
||||
|
||||
public AbsMultiSelectAdapter(@NonNull Context context, @Nullable CabHolder cabHolder, @MenuRes int menuRes) {
|
||||
|
@ -32,22 +34,27 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
protected void setMultiSelectMenuRes(@MenuRes int menuRes) {
|
||||
this.menuRes = menuRes;
|
||||
@Override
|
||||
public boolean onCabCreated(MaterialCab materialCab, Menu menu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean toggleChecked(final int position) {
|
||||
if (cabHolder != null) {
|
||||
I identifier = getIdentifier(position);
|
||||
if (identifier == null) return false;
|
||||
@Override
|
||||
public boolean onCabFinished(MaterialCab materialCab) {
|
||||
clearChecked();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!checked.remove(identifier)) checked.add(identifier);
|
||||
|
||||
notifyItemChanged(position);
|
||||
updateCab();
|
||||
return true;
|
||||
@Override
|
||||
public boolean onCabItemClicked(MenuItem menuItem) {
|
||||
if (menuItem.getItemId() == R.id.action_multi_select_adapter_check_all) {
|
||||
checkAll();
|
||||
} else {
|
||||
onMultipleItemAction(menuItem, new ArrayList<>(checked));
|
||||
cab.finish();
|
||||
clearChecked();
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void checkAll() {
|
||||
|
@ -64,21 +71,11 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
}
|
||||
}
|
||||
|
||||
private void updateCab() {
|
||||
if (cabHolder != null) {
|
||||
if (cab == null || !cab.isActive()) {
|
||||
cab = cabHolder.openCab(menuRes, this);
|
||||
}
|
||||
final int size = checked.size();
|
||||
if (size <= 0) cab.finish();
|
||||
else if (size == 1) cab.setTitle(getName(checked.get(0)));
|
||||
else cab.setTitle(context.getString(R.string.x_selected, size));
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
protected abstract I getIdentifier(int position);
|
||||
|
||||
private void clearChecked() {
|
||||
checked.clear();
|
||||
notifyDataSetChanged();
|
||||
protected String getName(I object) {
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
protected boolean isChecked(I identifier) {
|
||||
|
@ -89,35 +86,48 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
return cab != null && cab.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCabCreated(MaterialCab materialCab, Menu menu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCabItemClicked(MenuItem menuItem) {
|
||||
if (menuItem.getItemId() == R.id.action_multi_select_adapter_check_all) {
|
||||
checkAll();
|
||||
} else {
|
||||
onMultipleItemAction(menuItem, new ArrayList<>(checked));
|
||||
cab.finish();
|
||||
clearChecked();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCabFinished(MaterialCab materialCab) {
|
||||
clearChecked();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String getName(I object) {
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract I getIdentifier(int position);
|
||||
|
||||
protected abstract void onMultipleItemAction(MenuItem menuItem, ArrayList<I> selection);
|
||||
|
||||
protected void setMultiSelectMenuRes(@MenuRes int menuRes) {
|
||||
this.menuRes = menuRes;
|
||||
}
|
||||
|
||||
protected boolean toggleChecked(final int position) {
|
||||
if (cabHolder != null) {
|
||||
I identifier = getIdentifier(position);
|
||||
if (identifier == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!checked.remove(identifier)) {
|
||||
checked.add(identifier);
|
||||
}
|
||||
|
||||
notifyItemChanged(position);
|
||||
updateCab();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void clearChecked() {
|
||||
checked.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void updateCab() {
|
||||
if (cabHolder != null) {
|
||||
if (cab == null || !cab.isActive()) {
|
||||
cab = cabHolder.openCab(menuRes, this);
|
||||
}
|
||||
final int size = checked.size();
|
||||
if (size <= 0) {
|
||||
cab.finish();
|
||||
} else if (size == 1) {
|
||||
cab.setTitle(getName(checked.get(0)));
|
||||
} else {
|
||||
cab.setTitle(context.getString(R.string.x_selected, size));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package code.name.monkey.retromusic.adapter.base;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -22,7 +23,6 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
|
||||
|
@ -97,8 +97,7 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
|
|||
dummyContainer = itemView.findViewById(R.id.dummy_view);
|
||||
|
||||
if (imageContainerCard != null) {
|
||||
imageContainerCard.setCardBackgroundColor(
|
||||
ATHUtil.INSTANCE.resolveColor(itemView.getContext(), R.attr.colorSurface));
|
||||
imageContainerCard.setCardBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package code.name.monkey.retromusic.adapter.playlist
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
|
@ -15,6 +16,8 @@ import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
|||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.dialogs.ClearSmartPlaylistDialog
|
||||
import code.name.monkey.retromusic.dialogs.DeletePlaylistDialog
|
||||
import code.name.monkey.retromusic.extensions.hide
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper
|
||||
import code.name.monkey.retromusic.helper.menu.SongsMenuHelper
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
|
@ -26,17 +29,17 @@ import code.name.monkey.retromusic.model.smartplaylist.AbsSmartPlaylist
|
|||
import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
|
||||
class PlaylistAdapter(
|
||||
private val activity: AppCompatActivity,
|
||||
var dataSet: ArrayList<Playlist>,
|
||||
private var itemLayoutRes: Int,
|
||||
cabHolder: CabHolder?
|
||||
private val activity: AppCompatActivity,
|
||||
var dataSet: ArrayList<Playlist>,
|
||||
private var itemLayoutRes: Int,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsMultiSelectAdapter<PlaylistAdapter.ViewHolder, Playlist>(
|
||||
activity,
|
||||
cabHolder,
|
||||
R.menu.menu_playlists_selection
|
||||
activity,
|
||||
cabHolder,
|
||||
R.menu.menu_playlists_selection
|
||||
) {
|
||||
|
||||
var songs = ArrayList<Song>()
|
||||
|
@ -77,12 +80,26 @@ class PlaylistAdapter(
|
|||
holder.title?.text = getPlaylistTitle(playlist)
|
||||
holder.text?.text = getPlaylistText(playlist)
|
||||
holder.image?.setImageDrawable(getIconRes(playlist))
|
||||
val isChecked = isChecked(playlist)
|
||||
if (isChecked) {
|
||||
holder.menu?.hide()
|
||||
} else {
|
||||
holder.menu?.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIconRes(playlist: Playlist): Drawable {
|
||||
return if (MusicUtil.isFavoritePlaylist(activity, playlist))
|
||||
TintHelper.createTintedDrawable(activity, R.drawable.ic_favorite_white_24dp, ThemeStore.accentColor(activity))!!
|
||||
else TintHelper.createTintedDrawable(activity, R.drawable.ic_playlist_play_white_24dp, ATHUtil.resolveColor(activity, R.attr.colorControlNormal))!!
|
||||
TintHelper.createTintedDrawable(
|
||||
activity,
|
||||
R.drawable.ic_favorite_white_24dp,
|
||||
ThemeStore.accentColor(activity)
|
||||
)
|
||||
else TintHelper.createTintedDrawable(
|
||||
activity,
|
||||
R.drawable.ic_playlist_play_white_24dp,
|
||||
ATHUtil.resolveColor(activity, R.attr.colorControlNormal)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
|
@ -109,7 +126,7 @@ class PlaylistAdapter(
|
|||
val playlist = selection[i]
|
||||
if (playlist is AbsSmartPlaylist) {
|
||||
ClearSmartPlaylistDialog.create(playlist).show(
|
||||
activity.supportFragmentManager, "CLEAR_PLAYLIST_" + playlist.name
|
||||
activity.supportFragmentManager, "CLEAR_PLAYLIST_" + playlist.name
|
||||
)
|
||||
selection.remove(playlist)
|
||||
i--
|
||||
|
@ -118,13 +135,13 @@ class PlaylistAdapter(
|
|||
}
|
||||
if (selection.size > 0) {
|
||||
DeletePlaylistDialog.create(selection)
|
||||
.show(activity.supportFragmentManager, "DELETE_PLAYLIST")
|
||||
.show(activity.supportFragmentManager, "DELETE_PLAYLIST")
|
||||
}
|
||||
}
|
||||
else -> SongsMenuHelper.handleMenuClick(
|
||||
activity,
|
||||
getSongList(selection),
|
||||
menuItem.itemId
|
||||
activity,
|
||||
getSongList(selection),
|
||||
menuItem.itemId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -157,15 +174,14 @@ class PlaylistAdapter(
|
|||
image?.apply {
|
||||
val iconPadding = activity.resources.getDimensionPixelSize(R.dimen.list_item_image_icon_padding)
|
||||
setPadding(iconPadding, iconPadding, iconPadding, iconPadding)
|
||||
//setColorFilter(ATHUtil.resolveColor(activity, R.attr.iconColor), PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
|
||||
menu?.setOnClickListener { view ->
|
||||
val playlist = dataSet[adapterPosition]
|
||||
val popupMenu = PopupMenu(activity, view)
|
||||
popupMenu.inflate(
|
||||
if (itemViewType == SMART_PLAYLIST) R.menu.menu_item_smart_playlist
|
||||
else R.menu.menu_item_playlist
|
||||
if (itemViewType == SMART_PLAYLIST) R.menu.menu_item_smart_playlist
|
||||
else R.menu.menu_item_playlist
|
||||
)
|
||||
if (playlist is LastAddedPlaylist) {
|
||||
popupMenu.menu.findItem(R.id.action_clear_playlist).isVisible = false
|
||||
|
@ -174,14 +190,14 @@ class PlaylistAdapter(
|
|||
if (item.itemId == R.id.action_clear_playlist) {
|
||||
if (playlist is AbsSmartPlaylist) {
|
||||
ClearSmartPlaylistDialog.create(playlist).show(
|
||||
activity.supportFragmentManager,
|
||||
"CLEAR_SMART_PLAYLIST_" + playlist.name
|
||||
activity.supportFragmentManager,
|
||||
"CLEAR_SMART_PLAYLIST_" + playlist.name
|
||||
)
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
}
|
||||
PlaylistMenuHelper.handleMenuClick(
|
||||
activity, dataSet[adapterPosition], item
|
||||
activity, dataSet[adapterPosition], item
|
||||
)
|
||||
}
|
||||
popupMenu.show()
|
||||
|
@ -189,7 +205,7 @@ class PlaylistAdapter(
|
|||
|
||||
imageTextContainer?.apply {
|
||||
cardElevation = 0f
|
||||
setCardBackgroundColor(ATHUtil.resolveColor(activity, R.attr.colorSurface))
|
||||
setCardBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,95 +1,80 @@
|
|||
package code.name.monkey.retromusic.adapter.song
|
||||
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
|
||||
abstract class AbsOffsetSongAdapter : SongAdapter {
|
||||
abstract class AbsOffsetSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
@LayoutRes itemLayoutRes: Int,
|
||||
cabHolder: CabHolder?
|
||||
) : SongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||
|
||||
constructor(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>, @LayoutRes itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
) : super(activity, dataSet, itemLayoutRes, usePalette, cabHolder)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongAdapter.ViewHolder {
|
||||
if (viewType == OFFSET_ITEM) {
|
||||
val view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.item_list_quick_actions, parent, false)
|
||||
return createViewHolder(view)
|
||||
}
|
||||
return super.onCreateViewHolder(parent, viewType)
|
||||
}
|
||||
|
||||
constructor(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>, @LayoutRes itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?,
|
||||
showSectionName: Boolean
|
||||
) : super(activity, dataSet, itemLayoutRes, usePalette, cabHolder, showSectionName) {
|
||||
}
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongAdapter.ViewHolder {
|
||||
if (viewType == OFFSET_ITEM) {
|
||||
val view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.item_list_quick_actions, parent, false)
|
||||
return createViewHolder(view)
|
||||
}
|
||||
return super.onCreateViewHolder(parent, viewType)
|
||||
}
|
||||
override fun getItemId(position: Int): Long {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
return if (positionFinal < 0) -2 else super.getItemId(positionFinal)
|
||||
}
|
||||
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
override fun getIdentifier(position: Int): Song? {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
return if (positionFinal < 0) null else super.getIdentifier(positionFinal)
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
return if (positionFinal < 0) -2 else super.getItemId(positionFinal)
|
||||
}
|
||||
override fun getItemCount(): Int {
|
||||
val superItemCount = super.getItemCount()
|
||||
return if (superItemCount == 0) 0 else superItemCount + 1
|
||||
}
|
||||
|
||||
override fun getIdentifier(position: Int): Song? {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
return if (positionFinal < 0) null else super.getIdentifier(positionFinal)
|
||||
}
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (position == 0) OFFSET_ITEM else SONG
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
val superItemCount = super.getItemCount()
|
||||
return if (superItemCount == 0) 0 else superItemCount + 1
|
||||
}
|
||||
open inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView) {
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (position == 0) OFFSET_ITEM else SONG
|
||||
}
|
||||
override // could also return null, just to be safe return empty song
|
||||
val song: Song
|
||||
get() = if (itemViewType == OFFSET_ITEM) Song.emptySong else dataSet[adapterPosition - 1]
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
var positionF = position
|
||||
positionF--
|
||||
return if (positionF < 0) "" else super.getSectionName(positionF)
|
||||
}
|
||||
override fun onClick(v: View?) {
|
||||
if (isInQuickSelectMode && itemViewType != OFFSET_ITEM) {
|
||||
toggleChecked(adapterPosition)
|
||||
} else {
|
||||
MusicPlayerRemote.openQueue(dataSet, adapterPosition - 1, true)
|
||||
}
|
||||
}
|
||||
|
||||
open inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView) {
|
||||
override fun onLongClick(v: View?): Boolean {
|
||||
if (itemViewType == OFFSET_ITEM) return false
|
||||
toggleChecked(adapterPosition)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
override // could also return null, just to be safe return empty song
|
||||
val song: Song
|
||||
get() = if (itemViewType == OFFSET_ITEM) Song.emptySong else dataSet[adapterPosition - 1]
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
if (isInQuickSelectMode && itemViewType != OFFSET_ITEM) {
|
||||
toggleChecked(adapterPosition)
|
||||
} else {
|
||||
MusicPlayerRemote.openQueue(dataSet, adapterPosition - 1, true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View?): Boolean {
|
||||
if (itemViewType == OFFSET_ITEM) return false
|
||||
toggleChecked(adapterPosition)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val OFFSET_ITEM = 0
|
||||
const val SONG = 1
|
||||
}
|
||||
companion object {
|
||||
const val OFFSET_ITEM = 0
|
||||
const val SONG = 1
|
||||
}
|
||||
}
|
|
@ -1,134 +1,138 @@
|
|||
package code.name.monkey.retromusic.adapter.song
|
||||
|
||||
import android.view.*
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.R.menu
|
||||
import code.name.monkey.retromusic.dialogs.RemoveFromPlaylistDialog
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.model.PlaylistSong
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.*
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemViewHolder
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableItemStateFlags
|
||||
|
||||
class OrderablePlaylistSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?,
|
||||
private val onMoveItemListener: OnMoveItemListener?
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
cabHolder: CabHolder?,
|
||||
private val onMoveItemListener: OnMoveItemListener?
|
||||
) : PlaylistSongAdapter(
|
||||
activity, dataSet, itemLayoutRes, usePalette, cabHolder
|
||||
activity, dataSet, itemLayoutRes, cabHolder
|
||||
), DraggableItemAdapter<OrderablePlaylistSongAdapter.ViewHolder> {
|
||||
|
||||
init {
|
||||
setMultiSelectMenuRes(code.name.monkey.retromusic.R.menu.menu_playlists_songs_selection)
|
||||
}
|
||||
init {
|
||||
setMultiSelectMenuRes(menu.menu_playlists_songs_selection)
|
||||
}
|
||||
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
override fun getItemId(position: Int): Long {
|
||||
var positionFinal = position
|
||||
positionFinal--
|
||||
|
||||
var long: Long = 0
|
||||
if (positionFinal < 0) {
|
||||
long = -2
|
||||
} else {
|
||||
if (dataSet[positionFinal] is PlaylistSong) {
|
||||
long = (dataSet[positionFinal] as PlaylistSong).idInPlayList.toLong()
|
||||
}
|
||||
}
|
||||
return long
|
||||
}
|
||||
var long: Long = 0
|
||||
if (positionFinal < 0) {
|
||||
long = -2
|
||||
} else {
|
||||
if (dataSet[positionFinal] is PlaylistSong) {
|
||||
long = (dataSet[positionFinal] as PlaylistSong).idInPlayList.toLong()
|
||||
}
|
||||
}
|
||||
return long
|
||||
}
|
||||
|
||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: ArrayList<Song>) {
|
||||
when (menuItem.itemId) {
|
||||
R.id.action_remove_from_playlist -> {
|
||||
RemoveFromPlaylistDialog.create(selection as ArrayList<PlaylistSong>)
|
||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||
return
|
||||
}
|
||||
}
|
||||
super.onMultipleItemAction(menuItem, selection)
|
||||
}
|
||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: ArrayList<Song>) {
|
||||
when (menuItem.itemId) {
|
||||
R.id.action_remove_from_playlist -> {
|
||||
RemoveFromPlaylistDialog.create(selection as ArrayList<PlaylistSong>)
|
||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||
return
|
||||
}
|
||||
}
|
||||
super.onMultipleItemAction(menuItem, selection)
|
||||
}
|
||||
|
||||
override fun onCheckCanStartDrag(holder: ViewHolder, position: Int, x: Int, y: Int): Boolean {
|
||||
return onMoveItemListener != null && position > 0 && (ViewUtil.hitTest(
|
||||
holder.dragView!!, x, y
|
||||
) || ViewUtil.hitTest(holder.image!!, x, y))
|
||||
}
|
||||
override fun onCheckCanStartDrag(holder: ViewHolder, position: Int, x: Int, y: Int): Boolean {
|
||||
return onMoveItemListener != null && position > 0 && (ViewUtil.hitTest(
|
||||
holder.dragView!!, x, y
|
||||
) || ViewUtil.hitTest(holder.image!!, x, y))
|
||||
}
|
||||
|
||||
override fun onGetItemDraggableRange(holder: ViewHolder, position: Int): ItemDraggableRange {
|
||||
return ItemDraggableRange(1, dataSet.size)
|
||||
}
|
||||
override fun onGetItemDraggableRange(holder: ViewHolder, position: Int): ItemDraggableRange {
|
||||
return ItemDraggableRange(1, dataSet.size)
|
||||
}
|
||||
|
||||
override fun onMoveItem(fromPosition: Int, toPosition: Int) {
|
||||
if (onMoveItemListener != null && fromPosition != toPosition) {
|
||||
onMoveItemListener.onMoveItem(fromPosition - 1, toPosition - 1)
|
||||
}
|
||||
}
|
||||
override fun onMoveItem(fromPosition: Int, toPosition: Int) {
|
||||
if (onMoveItemListener != null && fromPosition != toPosition) {
|
||||
onMoveItemListener.onMoveItem(fromPosition - 1, toPosition - 1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCheckCanDrop(draggingPosition: Int, dropPosition: Int): Boolean {
|
||||
return dropPosition > 0
|
||||
}
|
||||
override fun onCheckCanDrop(draggingPosition: Int, dropPosition: Int): Boolean {
|
||||
return dropPosition > 0
|
||||
}
|
||||
|
||||
override fun onItemDragStarted(position: Int) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onItemDragStarted(position: Int) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onItemDragFinished(fromPosition: Int, toPosition: Int, result: Boolean) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onItemDragFinished(fromPosition: Int, toPosition: Int, result: Boolean) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
interface OnMoveItemListener {
|
||||
fun onMoveItem(fromPosition: Int, toPosition: Int)
|
||||
}
|
||||
interface OnMoveItemListener {
|
||||
fun onMoveItem(fromPosition: Int, toPosition: Int)
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : PlaylistSongAdapter.ViewHolder(itemView), DraggableItemViewHolder {
|
||||
@DraggableItemStateFlags
|
||||
private var mDragStateFlags: Int = 0
|
||||
inner class ViewHolder(itemView: View) : PlaylistSongAdapter.ViewHolder(itemView), DraggableItemViewHolder {
|
||||
@DraggableItemStateFlags
|
||||
private var mDragStateFlags: Int = 0
|
||||
|
||||
override var songMenuRes: Int
|
||||
get() = code.name.monkey.retromusic.R.menu.menu_item_playlist_song
|
||||
set(value) {
|
||||
super.songMenuRes = value
|
||||
}
|
||||
override var songMenuRes: Int
|
||||
get() = code.name.monkey.retromusic.R.menu.menu_item_playlist_song
|
||||
set(value) {
|
||||
super.songMenuRes = value
|
||||
}
|
||||
|
||||
init {
|
||||
if (dragView != null) {
|
||||
if (onMoveItemListener != null) {
|
||||
dragView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
dragView?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
if (dragView != null) {
|
||||
if (onMoveItemListener != null) {
|
||||
dragView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
dragView?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
code.name.monkey.retromusic.R.id.action_remove_from_playlist -> {
|
||||
RemoveFromPlaylistDialog.create(song as PlaylistSong)
|
||||
.show(activity.supportFragmentManager, "REMOVE_FROM_PLAYLIST")
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onSongMenuItemClick(item)
|
||||
}
|
||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
code.name.monkey.retromusic.R.id.action_remove_from_playlist -> {
|
||||
RemoveFromPlaylistDialog.create(song as PlaylistSong)
|
||||
.show(activity.supportFragmentManager, "REMOVE_FROM_PLAYLIST")
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onSongMenuItemClick(item)
|
||||
}
|
||||
|
||||
@DraggableItemStateFlags
|
||||
override fun getDragStateFlags(): Int {
|
||||
return mDragStateFlags
|
||||
}
|
||||
@DraggableItemStateFlags
|
||||
override fun getDragStateFlags(): Int {
|
||||
return mDragStateFlags
|
||||
}
|
||||
|
||||
override fun setDragStateFlags(@DraggableItemStateFlags flags: Int) {
|
||||
mDragStateFlags = flags
|
||||
}
|
||||
}
|
||||
override fun setDragStateFlags(@DraggableItemStateFlags flags: Int) {
|
||||
mDragStateFlags = flags
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = OrderablePlaylistSongAdapter::class.java.simpleName
|
||||
}
|
||||
companion object {
|
||||
val TAG: String = OrderablePlaylistSongAdapter::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package code.name.monkey.retromusic.adapter.song
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff.Mode
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
@ -31,7 +30,7 @@ class PlayingQueueAdapter(
|
|||
private var current: Int,
|
||||
itemLayoutRes: Int
|
||||
) : SongAdapter(
|
||||
activity, dataSet, itemLayoutRes, false, null
|
||||
activity, dataSet, itemLayoutRes, null
|
||||
), DraggableItemAdapter<PlayingQueueAdapter.ViewHolder>, SwipeableItemAdapter<PlayingQueueAdapter.ViewHolder> {
|
||||
|
||||
private var color = -1
|
||||
|
@ -48,9 +47,6 @@ class PlayingQueueAdapter(
|
|||
if (holder.itemViewType == HISTORY || holder.itemViewType == CURRENT) {
|
||||
setAlpha(holder, 0.5f)
|
||||
}
|
||||
if (usePalette) {
|
||||
setColor(holder, Color.WHITE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setColor(holder: SongAdapter.ViewHolder, white: Int) {
|
||||
|
@ -70,12 +66,6 @@ class PlayingQueueAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
override fun usePalette(usePalette: Boolean) {
|
||||
super.usePalette(usePalette)
|
||||
this.usePalette = usePalette
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
if (position < current) {
|
||||
return HISTORY
|
||||
|
|
|
@ -16,9 +16,8 @@ open class PlaylistSongAdapter(
|
|||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, usePalette, cabHolder, false) {
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||
|
||||
init {
|
||||
this.setMultiSelectMenuRes(R.menu.menu_cannot_delete_single_songs_playlist_songs_selection)
|
||||
|
|
|
@ -7,48 +7,47 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
|||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
|
||||
class ShuffleButtonSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, usePalette, cabHolder) {
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
||||
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
||||
if (holder.itemViewType == OFFSET_ITEM) {
|
||||
val viewHolder = holder as ViewHolder
|
||||
viewHolder.playAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
||||
}
|
||||
}
|
||||
viewHolder.shuffleAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onBindViewHolder(holder, position - 1)
|
||||
}
|
||||
}
|
||||
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
||||
if (holder.itemViewType == OFFSET_ITEM) {
|
||||
val viewHolder = holder as ViewHolder
|
||||
viewHolder.playAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
||||
}
|
||||
}
|
||||
viewHolder.shuffleAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onBindViewHolder(holder, position - 1)
|
||||
}
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
||||
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
||||
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
||||
inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
||||
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
||||
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
if (itemViewType == OFFSET_ITEM) {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
return
|
||||
}
|
||||
super.onClick(v)
|
||||
}
|
||||
}
|
||||
override fun onClick(v: View?) {
|
||||
if (itemViewType == OFFSET_ITEM) {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
return
|
||||
}
|
||||
super.onClick(v)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,14 +6,14 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import java.util.*
|
||||
import java.util.ArrayList
|
||||
|
||||
class SimpleSongAdapter(
|
||||
context: AppCompatActivity,
|
||||
songs: ArrayList<Song>,
|
||||
i: Int,
|
||||
cabHolder: CabHolder?
|
||||
) : SongAdapter(context, songs, i, false, cabHolder) {
|
||||
context: AppCompatActivity,
|
||||
songs: ArrayList<Song>,
|
||||
layoutRes: Int,
|
||||
cabHolder: CabHolder?
|
||||
) : SongAdapter(context, songs, layoutRes, cabHolder) {
|
||||
|
||||
override fun swapDataSet(dataSet: ArrayList<Song>) {
|
||||
this.dataSet.clear()
|
||||
|
|
|
@ -25,7 +25,7 @@ import code.name.monkey.retromusic.util.NavigationUtil
|
|||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialcab.MaterialCab
|
||||
import com.bumptech.glide.Glide
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
|
@ -36,21 +36,17 @@ open class SongAdapter(
|
|||
protected val activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
protected var itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?,
|
||||
showSectionName: Boolean = true
|
||||
) : AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song>(
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
), MaterialCab.Callback, FastScrollRecyclerView.SectionedAdapter {
|
||||
), MaterialCab.Callback, PopupTextProvider {
|
||||
|
||||
var dataSet: ArrayList<Song>
|
||||
|
||||
protected var usePalette = false
|
||||
private var showSectionName = true
|
||||
|
||||
init {
|
||||
this.dataSet = dataSet
|
||||
this.usePalette = usePalette
|
||||
this.showSectionName = showSectionName
|
||||
this.setHasStableIds(true)
|
||||
}
|
||||
|
@ -60,11 +56,6 @@ open class SongAdapter(
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
open fun usePalette(usePalette: Boolean) {
|
||||
this.usePalette = usePalette
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return dataSet[position].id.toLong()
|
||||
}
|
||||
|
@ -113,8 +104,7 @@ open class SongAdapter(
|
|||
}
|
||||
|
||||
override fun onColorReady(color: Int) {
|
||||
if (usePalette) setColors(color, holder)
|
||||
else setColors(defaultFooterColor, holder)
|
||||
setColors(color, holder)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -143,10 +133,7 @@ open class SongAdapter(
|
|||
SongsMenuHelper.handleMenuClick(activity, selection, menuItem.itemId)
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
if (!showSectionName) {
|
||||
return ""
|
||||
}
|
||||
override fun getPopupText(position: Int): String {
|
||||
val sectionName: String? = when (PreferenceUtil.getInstance(activity).songSortOrder) {
|
||||
SortOrder.SongSortOrder.SONG_A_Z, SortOrder.SongSortOrder.SONG_Z_A -> dataSet[position].title
|
||||
SortOrder.SongSortOrder.SONG_ALBUM -> dataSet[position].albumName
|
||||
|
@ -157,6 +144,7 @@ open class SongAdapter(
|
|||
return ""
|
||||
}
|
||||
}
|
||||
println("File name -> $sectionName")
|
||||
return MusicUtil.getSectionName(sectionName)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue