Add light animation when scrolling listings.

This commit is contained in:
Antoine POPINEAU 2020-06-15 00:26:22 +02:00
parent 098048ac49
commit 13f3c2d465
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
3 changed files with 46 additions and 5 deletions

View File

@ -1,14 +1,10 @@
package com.github.apognu.otter.fragments
import android.content.Context
import android.graphics.Bitmap
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.drawable.toDrawable
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
@ -25,7 +21,6 @@ import com.github.apognu.otter.views.LoadingFlotingActionButton
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.fragment_albums.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
@ -139,6 +134,24 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
}
}
override fun onResume() {
super.onResume()
var coverHeight: Float? = null
scroller.setOnScrollChangeListener { _: View?, _: Int, scrollY: Int, _: Int, _: Int ->
if (coverHeight == null) {
coverHeight = cover.measuredHeight.toFloat()
}
cover.translationY = (scrollY / 2).toFloat()
coverHeight?.let { height ->
cover.alpha = (height - scrollY.toFloat()) / height
}
}
}
inner class OnAlbumClickListener : AlbumsAdapter.OnAlbumClickListener {
override fun onClick(view: View?, album: Album) {
openTracks(context, album, fragment = this@AlbumsFragment)

View File

@ -80,6 +80,20 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd
}
}
var coverHeight: Float? = null
scroller.setOnScrollChangeListener { _: View?, _: Int, scrollY: Int, _: Int, _: Int ->
if (coverHeight == null) {
coverHeight = covers.measuredHeight.toFloat()
}
covers.translationY = (scrollY / 2).toFloat()
coverHeight?.let { height ->
covers.alpha = (height - scrollY.toFloat()) / height
}
}
play.setOnClickListener {
CommandBus.send(Command.ReplaceQueue(adapter.data.map { it.track }.shuffled()))

View File

@ -92,6 +92,20 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() {
refreshDownloadedTracks()
}
var coverHeight: Float? = null
scroller.setOnScrollChangeListener { _: View?, _: Int, scrollY: Int, _: Int, _: Int ->
if (coverHeight == null) {
coverHeight = cover.measuredHeight.toFloat()
}
cover.translationY = (scrollY / 2).toFloat()
coverHeight?.let { height ->
cover.alpha = (height - scrollY.toFloat()) / height
}
}
play.setOnClickListener {
CommandBus.send(Command.ReplaceQueue(adapter.data.shuffled()))