ui: minor tweaks

More miscellanious tweaks I can't categorize since I have no time.

It's mostly attempts at improving animation visuals an failing. Really
want to switch to material animations once I can finally get the things
working.
This commit is contained in:
Alexander Capehart
2022-12-05 21:14:41 -07:00
parent f5ec295b2c
commit cf64536118
13 changed files with 54 additions and 31 deletions
@@ -46,7 +46,7 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
*
* TODO: Use proper material attributes (Not the weird dimen attributes I currently have)
*
* TODO: Test out material animation system
* TODO: Migrate to material animation system
*
* @author OxygenCobalt
*/
@@ -28,7 +28,9 @@ import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.transition.MaterialFade
import java.lang.reflect.Field
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.AuxioAppBarLayout
@@ -111,7 +113,11 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
this.titleAnimator =
ValueAnimator.ofFloat(from, to).apply {
addUpdateListener { titleView.alpha = it.animatedValue as Float }
duration = TOOLBAR_FADE_DURATION
duration = if (titleShown == true) {
context.resources.getInteger(R.integer.anim_fade_enter_duration).toLong()
} else {
context.resources.getInteger(R.integer.anim_fade_exit_duration).toLong()
}
start()
}
}
@@ -142,8 +148,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
companion object {
private const val TOOLBAR_FADE_DURATION = 150L
private val TOOLBAR_TITLE_TEXT_FIELD: Field by
lazyReflectedField(Toolbar::class, "mTitleTextView")
}
@@ -161,10 +161,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
if (isActivated) {
targetVis = VISIBLE
targetDuration = 150L
targetDuration = context.resources.getInteger(R.integer.anim_fade_enter_duration).toLong()
} else {
targetVis = INVISIBLE
targetDuration = 84L
targetDuration = context.resources.getInteger(R.integer.anim_fade_exit_duration).toLong()
}
if (selectionIndicator.visibility == targetVis) {
@@ -21,6 +21,7 @@ import android.animation.ValueAnimator
import android.content.Context
import android.util.AttributeSet
import com.google.android.material.button.MaterialButton
import org.oxycblt.auxio.R
/**
* A [MaterialButton] that automatically morphs from a circle to a squircle shape appearance when it
@@ -46,7 +47,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
animator?.cancel()
animator =
ValueAnimator.ofFloat(currentCornerRadiusRatio, target).apply {
duration = ACTIVATION_DURATION
duration = context.resources.getInteger(R.integer.anim_fade_enter_duration).toLong()
addUpdateListener { updateCornerRadiusRatio(animatedValue as Float) }
start()
}
@@ -56,8 +57,4 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
currentCornerRadiusRatio = ratio
shapeAppearanceModel = shapeAppearanceModel.withCornerSize { it.width() * ratio }
}
companion object {
const val ACTIVATION_DURATION = 150L
}
}
@@ -70,7 +70,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
// Sanity check 2: Ensure that this value is within the duration and will not crash
// the app, and that the user is not currently seeking (which would cause the SeekBar
// to jump around).
if (from <= durationDs && !isSelected) {
if (from <= durationDs && !isActivated) {
binding.seekBarSlider.value = from.toFloat()
// We would want to keep this in the callback, but the callback only fires when
@@ -106,13 +106,13 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
logD("Starting seek mode")
// User has begun seeking, place the SeekBar into a "Suspended" mode in which no
// position updates are sent and is indicated by the position value turning accented.
isSelected = true
isActivated = true
}
override fun onStopTrackingTouch(slider: Slider) {
logD("Confirming seek")
// End of seek event, send off new value to callback.
isSelected = false
isActivated = false
callback?.seekTo(slider.value.toLong())
}
@@ -33,13 +33,17 @@ import androidx.core.view.isInvisible
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
import com.google.android.material.transition.MaterialFade
import kotlin.math.abs
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.recycler.AuxioRecyclerView
import org.oxycblt.auxio.util.getDimen
import org.oxycblt.auxio.util.getDimenSize
import org.oxycblt.auxio.util.getDrawableCompat
import org.oxycblt.auxio.util.isRtl
import org.oxycblt.auxio.util.isUnder
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
@@ -431,7 +435,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
showingThumb = true
animateView(thumbView, 1f)
animateViewIn(thumbView)
}
private fun hideScrollbar() {
@@ -440,7 +444,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
showingThumb = false
animateView(thumbView, 0f)
animateViewOut(thumbView)
}
private fun showPopup() {
@@ -449,7 +453,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
showingPopup = true
animateView(popupView, 1f)
animateViewIn(popupView)
}
private fun hidePopup() {
@@ -458,11 +462,22 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
showingPopup = false
animateView(popupView, 0f)
animateViewOut(popupView)
}
private fun animateView(view: View, alpha: Float) {
view.animate().alpha(alpha).setDuration(ANIM_MILLIS).start()
private fun animateViewIn(view: View) {
logD(view.translationX)
view.animate()
.alpha(1f)
.setDuration(context.resources.getInteger(R.integer.anim_fade_enter_duration).toLong())
.start()
}
private fun animateViewOut(view: View) {
view.animate()
.alpha(0f)
.setDuration(context.resources.getInteger(R.integer.anim_fade_exit_duration).toLong())
.start()
}
// --- LAYOUT STATE ---