Added color change animation on cab creation

This commit is contained in:
Prathamesh More 2021-09-11 16:52:47 +05:30
parent d8c21ba7bb
commit 6cc0985ab6
8 changed files with 58 additions and 13 deletions

View file

@ -40,7 +40,7 @@ import kotlin.math.log10
import kotlin.math.pow import kotlin.math.pow
class SongFileAdapter( class SongFileAdapter(
private val activity: AppCompatActivity, override val activity: AppCompatActivity,
private var dataSet: List<File>, private var dataSet: List<File>,
private val itemLayoutRes: Int, private val itemLayoutRes: Int,
private val iCallbacks: ICallbacks?, private val iCallbacks: ICallbacks?,

View file

@ -39,7 +39,7 @@ import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import me.zhanghai.android.fastscroll.PopupTextProvider import me.zhanghai.android.fastscroll.PopupTextProvider
open class AlbumAdapter( open class AlbumAdapter(
val activity: FragmentActivity, override val activity: FragmentActivity,
var dataSet: List<Album>, var dataSet: List<Album>,
var itemLayoutRes: Int, var itemLayoutRes: Int,
iCabHolder: ICabHolder?, iCabHolder: ICabHolder?,

View file

@ -42,7 +42,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider
import java.util.* import java.util.*
class ArtistAdapter( class ArtistAdapter(
val activity: FragmentActivity, override val activity: FragmentActivity,
var dataSet: List<Artist>, var dataSet: List<Artist>,
var itemLayoutRes: Int, var itemLayoutRes: Int,
val ICabHolder: ICabHolder?, val ICabHolder: ICabHolder?,

View file

@ -1,28 +1,44 @@
package code.name.monkey.retromusic.adapter.base package code.name.monkey.retromusic.adapter.base
import android.content.Context import android.graphics.Color
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.annotation.MenuRes import androidx.annotation.MenuRes
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R 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.interfaces.ICabHolder
import code.name.monkey.retromusic.util.ColorAnimUtil
import code.name.monkey.retromusic.util.RetroColorUtil
import com.afollestad.materialcab.MaterialCab import com.afollestad.materialcab.MaterialCab
import java.util.* import java.util.*
abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>( 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 { ) : RecyclerView.Adapter<V>(), MaterialCab.Callback {
private val context: Context
private var cab: MaterialCab? = null private var cab: MaterialCab? = null
private val checked: MutableList<I> private val checked: MutableList<I>
private var menuRes: Int private var menuRes: Int
override fun onCabCreated(materialCab: MaterialCab, menu: Menu): Boolean { 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 return true
} }
override fun onCabFinished(materialCab: MaterialCab): Boolean { override fun onCabFinished(materialCab: MaterialCab): Boolean {
clearChecked() clearChecked()
activity.window.statusBarColor = Color.TRANSPARENT
return true return true
} }
@ -31,7 +47,7 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
checkAll() checkAll()
} else { } else {
onMultipleItemAction(menuItem, ArrayList(checked)) onMultipleItemAction(menuItem, ArrayList(checked))
cab!!.finish() cab?.finish()
clearChecked() clearChecked()
} }
return true return true
@ -94,13 +110,13 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
val size = checked.size val size = checked.size
when { when {
size <= 0 -> { size <= 0 -> {
cab!!.finish() cab?.finish()
} }
size == 1 -> { size == 1 -> {
cab!!.setTitle(getName(checked[0])) cab?.setTitle(getName(checked[0]))
} }
else -> { 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 { init {
checked = ArrayList() checked = ArrayList()
this.menuRes = menuRes this.menuRes = menuRes
this.context = context
} }
} }

View file

@ -41,7 +41,7 @@ import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
class PlaylistAdapter( class PlaylistAdapter(
private val activity: FragmentActivity, override val activity: FragmentActivity,
private var dataSet: List<PlaylistWithSongs>, private var dataSet: List<PlaylistWithSongs>,
private var itemLayoutRes: Int, private var itemLayoutRes: Int,
ICabHolder: ICabHolder?, ICabHolder: ICabHolder?,

View file

@ -50,7 +50,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider
*/ */
open class SongAdapter( open class SongAdapter(
protected val activity: FragmentActivity, override val activity: FragmentActivity,
var dataSet: MutableList<Song>, var dataSet: MutableList<Song>,
protected var itemLayoutRes: Int, protected var itemLayoutRes: Int,
ICabHolder: ICabHolder?, ICabHolder: ICabHolder?,

View file

@ -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
}
}
}
}

View file

@ -205,6 +205,17 @@ public class RetroColorUtil {
return color; 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 class SwatchComparator implements Comparator<Palette.Swatch> {
private static SwatchComparator sInstance; private static SwatchComparator sInstance;