Added color change animation on cab creation
parent
d8c21ba7bb
commit
6cc0985ab6
|
@ -40,7 +40,7 @@ import kotlin.math.log10
|
|||
import kotlin.math.pow
|
||||
|
||||
class SongFileAdapter(
|
||||
private val activity: AppCompatActivity,
|
||||
override val activity: AppCompatActivity,
|
||||
private var dataSet: List<File>,
|
||||
private val itemLayoutRes: Int,
|
||||
private val iCallbacks: ICallbacks?,
|
||||
|
|
|
@ -39,7 +39,7 @@ import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
|||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
|
||||
open class AlbumAdapter(
|
||||
val activity: FragmentActivity,
|
||||
override val activity: FragmentActivity,
|
||||
var dataSet: List<Album>,
|
||||
var itemLayoutRes: Int,
|
||||
iCabHolder: ICabHolder?,
|
||||
|
|
|
@ -42,7 +42,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider
|
|||
import java.util.*
|
||||
|
||||
class ArtistAdapter(
|
||||
val activity: FragmentActivity,
|
||||
override val activity: FragmentActivity,
|
||||
var dataSet: List<Artist>,
|
||||
var itemLayoutRes: Int,
|
||||
val ICabHolder: ICabHolder?,
|
||||
|
|
|
@ -1,28 +1,44 @@
|
|||
package code.name.monkey.retromusic.adapter.base
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.annotation.MenuRes
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.surfaceColor
|
||||
import code.name.monkey.retromusic.interfaces.ICabHolder
|
||||
import code.name.monkey.retromusic.util.ColorAnimUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
import com.afollestad.materialcab.MaterialCab
|
||||
import java.util.*
|
||||
|
||||
abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
|
||||
context: Context, private val ICabHolder: ICabHolder?, @MenuRes menuRes: Int
|
||||
open val activity: FragmentActivity, private val ICabHolder: ICabHolder?, @MenuRes menuRes: Int
|
||||
) : RecyclerView.Adapter<V>(), MaterialCab.Callback {
|
||||
private val context: Context
|
||||
private var cab: MaterialCab? = null
|
||||
private val checked: MutableList<I>
|
||||
private var menuRes: Int
|
||||
override fun onCabCreated(materialCab: MaterialCab, menu: Menu): Boolean {
|
||||
// Animate the color change
|
||||
ColorAnimUtil.createColorAnimator(
|
||||
activity.surfaceColor(),
|
||||
RetroColorUtil.shiftBackgroundColor(activity.surfaceColor())
|
||||
).apply {
|
||||
addUpdateListener {
|
||||
// Change color of status bar too
|
||||
activity.window.statusBarColor = animatedValue as Int
|
||||
materialCab.setBackgroundColor(animatedValue as Int)
|
||||
}
|
||||
start()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onCabFinished(materialCab: MaterialCab): Boolean {
|
||||
clearChecked()
|
||||
activity.window.statusBarColor = Color.TRANSPARENT
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -31,7 +47,7 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
|
|||
checkAll()
|
||||
} else {
|
||||
onMultipleItemAction(menuItem, ArrayList(checked))
|
||||
cab!!.finish()
|
||||
cab?.finish()
|
||||
clearChecked()
|
||||
}
|
||||
return true
|
||||
|
@ -94,13 +110,13 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
|
|||
val size = checked.size
|
||||
when {
|
||||
size <= 0 -> {
|
||||
cab!!.finish()
|
||||
cab?.finish()
|
||||
}
|
||||
size == 1 -> {
|
||||
cab!!.setTitle(getName(checked[0]))
|
||||
cab?.setTitle(getName(checked[0]))
|
||||
}
|
||||
else -> {
|
||||
cab!!.setTitle(context.getString(R.string.x_selected, size))
|
||||
cab?.setTitle(activity.getString(R.string.x_selected, size))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +125,5 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
|
|||
init {
|
||||
checked = ArrayList()
|
||||
this.menuRes = menuRes
|
||||
this.context = context
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ import code.name.monkey.retromusic.model.Song
|
|||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
|
||||
class PlaylistAdapter(
|
||||
private val activity: FragmentActivity,
|
||||
override val activity: FragmentActivity,
|
||||
private var dataSet: List<PlaylistWithSongs>,
|
||||
private var itemLayoutRes: Int,
|
||||
ICabHolder: ICabHolder?,
|
||||
|
|
|
@ -50,7 +50,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider
|
|||
*/
|
||||
|
||||
open class SongAdapter(
|
||||
protected val activity: FragmentActivity,
|
||||
override val activity: FragmentActivity,
|
||||
var dataSet: MutableList<Song>,
|
||||
protected var itemLayoutRes: Int,
|
||||
ICabHolder: ICabHolder?,
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.animation.ValueAnimator
|
||||
|
||||
class ColorAnimUtil {
|
||||
companion object {
|
||||
fun createColorAnimator(
|
||||
fromColor: Int,
|
||||
toColor: Int,
|
||||
mDuration: Long = 300
|
||||
): ValueAnimator {
|
||||
return ValueAnimator.ofInt(fromColor, toColor).apply {
|
||||
setEvaluator(ArgbEvaluator())
|
||||
duration = mDuration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -205,6 +205,17 @@ public class RetroColorUtil {
|
|||
return color;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int shiftBackgroundColor(@ColorInt int backgroundColor) {
|
||||
int color = backgroundColor;
|
||||
if (ColorUtil.INSTANCE.isColorLight(color)) {
|
||||
color = ColorUtil.INSTANCE.shiftColor(color, 0.5F);
|
||||
} else {
|
||||
color = ColorUtil.INSTANCE.shiftColor(color, 1.5F);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private static class SwatchComparator implements Comparator<Palette.Swatch> {
|
||||
|
||||
private static SwatchComparator sInstance;
|
||||
|
|
Loading…
Reference in New Issue