Fix crashing, loading albums
This commit is contained in:
parent
397f42a54a
commit
d7ab358e60
59 changed files with 370 additions and 405 deletions
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.adapter.base;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
|
||||
@Nullable
|
||||
public TextView title;
|
||||
|
||||
@Nullable
|
||||
public TextView text;
|
||||
|
||||
@Nullable
|
||||
public TextView time;
|
||||
|
||||
@Nullable
|
||||
public TextView imageText;
|
||||
|
||||
@Nullable
|
||||
public ViewGroup imageContainer;
|
||||
|
||||
@Nullable
|
||||
public MaterialCardView imageContainerCard;
|
||||
|
||||
@Nullable
|
||||
public View menu;
|
||||
|
||||
@Nullable
|
||||
public View dragView;
|
||||
|
||||
@Nullable
|
||||
public View paletteColorContainer;
|
||||
|
||||
@Nullable
|
||||
public RecyclerView recyclerView;
|
||||
|
||||
@Nullable
|
||||
public ImageButton playSongs;
|
||||
|
||||
@Nullable
|
||||
public View mask;
|
||||
|
||||
@Nullable
|
||||
public MaterialCardView imageTextContainer;
|
||||
|
||||
@Nullable
|
||||
public ImageView image;
|
||||
|
||||
public MediaEntryViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
text = itemView.findViewById(R.id.text);
|
||||
|
||||
image = itemView.findViewById(R.id.image);
|
||||
time = itemView.findViewById(R.id.time);
|
||||
|
||||
imageText = itemView.findViewById(R.id.image_text);
|
||||
imageContainer = itemView.findViewById(R.id.image_container);
|
||||
imageTextContainer = itemView.findViewById(R.id.image_text_container);
|
||||
imageContainerCard = itemView.findViewById(R.id.image_container_card);
|
||||
|
||||
menu = itemView.findViewById(R.id.menu);
|
||||
dragView = itemView.findViewById(R.id.drag_view);
|
||||
paletteColorContainer = itemView.findViewById(R.id.palette_color_container);
|
||||
recyclerView = itemView.findViewById(R.id.recycler_view);
|
||||
mask = itemView.findViewById(R.id.mask);
|
||||
playSongs = itemView.findViewById(R.id.playSongs);
|
||||
|
||||
if (imageContainerCard != null) {
|
||||
imageContainerCard.setCardBackgroundColor(ThemeStore.Companion.primaryColor(itemView.getContext()));
|
||||
}
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
|
||||
public void setImageTransitionName(@NonNull String transitionName) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && image != null) {
|
||||
image.setTransitionName(transitionName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package code.name.monkey.retromusic.adapter.base
|
||||
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
|
||||
open class MediaEntryViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener, View.OnLongClickListener {
|
||||
override fun onLongClick(v: View?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
|
||||
}
|
||||
|
||||
var image: ImageView? = null
|
||||
var imageText: TextView? = null
|
||||
var title: TextView? = null
|
||||
var text: TextView? = null
|
||||
var imageContainer: ViewGroup? = null
|
||||
var imageContainerCard: CardView? = null
|
||||
var menu: View? = null
|
||||
var dragView: View? = null
|
||||
var paletteColorContainer: View? = null
|
||||
var time: TextView? = null
|
||||
var recyclerView: RecyclerView? = null
|
||||
var playSongs: ImageButton? = null
|
||||
var mask: View? = null
|
||||
var imageTextContainer: CardView? = null
|
||||
|
||||
init {
|
||||
|
||||
|
||||
title = view.findViewById(R.id.title)
|
||||
text = view.findViewById(R.id.text)
|
||||
|
||||
image = view.findViewById(R.id.image)
|
||||
imageContainer = view.findViewById(R.id.image_container)
|
||||
imageTextContainer = view.findViewById(R.id.image_text_container)
|
||||
imageContainerCard = view.findViewById(R.id.image_container_card)
|
||||
|
||||
imageText = view.findViewById(R.id.image_text)
|
||||
|
||||
menu = view.findViewById(R.id.menu)
|
||||
dragView = view.findViewById(R.id.drag_view)
|
||||
|
||||
paletteColorContainer = view.findViewById(R.id.palette_color_container)
|
||||
|
||||
time = view.findViewById(R.id.time);
|
||||
recyclerView = view.findViewById(R.id.recycler_view)
|
||||
|
||||
mask = view.findViewById(R.id.mask)
|
||||
playSongs = view.findViewById(R.id.playSongs)
|
||||
|
||||
view.setOnClickListener(this@MediaEntryViewHolder)
|
||||
view.setOnLongClickListener(this@MediaEntryViewHolder)
|
||||
|
||||
imageContainerCard?.setCardBackgroundColor(ThemeStore.primaryColor(itemView.context))
|
||||
|
||||
}
|
||||
|
||||
fun setImageTransitionName(transitionName: String) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && image != null) {
|
||||
image!!.transitionName = transitionName
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package code.name.monkey.retromusic.adapter.song
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.util.Pair
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
||||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||
|
@ -33,9 +33,14 @@ import java.util.*
|
|||
* Created by hemanths on 13/08/17.
|
||||
*/
|
||||
|
||||
open class SongAdapter @JvmOverloads constructor(protected val activity: AppCompatActivity, dataSet: ArrayList<Song>,
|
||||
@param:LayoutRes protected var itemLayoutRes: Int, usePalette: Boolean, cabHolder: CabHolder?,
|
||||
showSectionName: Boolean = true) : AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song>(activity, cabHolder, code.name.monkey.retromusic.R.menu.menu_media_selection), MaterialCab.Callback, FastScrollRecyclerView.SectionedAdapter {
|
||||
open class SongAdapter @JvmOverloads constructor(
|
||||
protected val activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
protected var itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?,
|
||||
showSectionName: Boolean = true
|
||||
) : AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song>(activity, cabHolder, code.name.monkey.retromusic.R.menu.menu_media_selection), MaterialCab.Callback, FastScrollRecyclerView.SectionedAdapter {
|
||||
var dataSet: ArrayList<Song>
|
||||
|
||||
protected var usePalette = false
|
||||
|
@ -83,9 +88,7 @@ open class SongAdapter @JvmOverloads constructor(protected val activity: AppComp
|
|||
if (holder.text != null) {
|
||||
holder.text!!.text = getSongText(song)
|
||||
}
|
||||
|
||||
loadAlbumCover(song, holder)
|
||||
|
||||
}
|
||||
|
||||
private fun setColors(color: Int, holder: ViewHolder) {
|
||||
|
@ -161,41 +164,35 @@ open class SongAdapter @JvmOverloads constructor(protected val activity: AppComp
|
|||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
return MusicUtil.getSectionName(sectionName)
|
||||
}
|
||||
|
||||
open inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
|
||||
|
||||
protected open var songMenuRes = SongMenuHelper.MENU_RES
|
||||
|
||||
protected open val song: Song
|
||||
get() = dataSet[adapterPosition]
|
||||
|
||||
init {
|
||||
setImageTransitionName(activity.getString(code.name.monkey.retromusic.R.string.transition_album_art))
|
||||
if (menu != null) {
|
||||
menu!!.setOnClickListener(object : SongMenuHelper.OnClickSongMenu(activity) {
|
||||
override val song: Song
|
||||
get() = this@ViewHolder.song
|
||||
setImageTransitionName(activity.getString(R.string.transition_album_art))
|
||||
menu?.setOnClickListener(object : SongMenuHelper.OnClickSongMenu(activity) {
|
||||
override val song: Song
|
||||
get() = this@ViewHolder.song
|
||||
|
||||
override val menuRes: Int
|
||||
get() = songMenuRes
|
||||
override val menuRes: Int
|
||||
get() = songMenuRes
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
return onSongMenuItemClick(item) || super.onMenuItemClick(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
return onSongMenuItemClick(item) || super.onMenuItemClick(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
protected open fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
if (image != null && image!!.visibility == View.VISIBLE) {
|
||||
when (item.itemId) {
|
||||
code.name.monkey.retromusic.R.id.action_go_to_album -> {
|
||||
val albumPairs = arrayOf<Pair<*, *>>(Pair.create(imageContainer,
|
||||
activity.resources.getString(code.name.monkey.retromusic.R.string.transition_album_art)))
|
||||
NavigationUtil.goToAlbum(activity, song.albumId, *albumPairs)
|
||||
R.id.action_go_to_album -> {
|
||||
val options: ActivityOptions = ActivityOptions.makeSceneTransitionAnimation(activity, image, activity.getString(R.string.transition_album_art))
|
||||
NavigationUtil.goToAlbumOptions(activity, song.albumId, options)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue