Skip to content

Commit

Permalink
- Fix issue that active control button was not always shown
Browse files Browse the repository at this point in the history
- Update dependencies
  • Loading branch information
thetwom committed Jan 16, 2022
1 parent 7b482f8 commit dc41544
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "de.moekadu.metronome"
minSdkVersion 23
targetSdkVersion 31
versionCode 45
versionName "4.3.1"
versionCode 46
versionName "4.3.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand All @@ -32,12 +32,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0-rc01'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.fragment:fragment-ktx:1.4.0-rc01'
implementation 'com.google.android.material:material:1.5.0-beta01'
implementation 'androidx.fragment:fragment-ktx:1.4.0'
implementation 'com.google.android.material:material:1.6.0-alpha01'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.media:media:1.4.3'
implementation 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03'
implementation 'androidx.preference:preference-ktx:1.1.1'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/de/moekadu/metronome/SoundChooser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.graphics.Rect
import android.os.Bundle
import android.os.Parcelable
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -1141,7 +1142,7 @@ class SoundChooser(context : Context, attrs : AttributeSet?, defStyleAttr: Int)
// Log.v("Metronome", "SoundChooser.setNoteList: noteList[0] = ${noteList[0].duration}")
noteView.setNoteList(noteList, animationDuration)
volumeSliders.setNoteList(this, noteList, animationDuration)

// Log.v("Metronome", "SoundChooser.setNoteList: uid=${activeControlButton?.uid}, activeControlButton.visibility==VISIBLE=${activeControlButton?.visibility == VISIBLE}, activeControlButton.alpha=${activeControlButton?.alpha}, VISIBLE=$VISIBLE, GONE=$GONE, INVISIBLE=$INVISIBLE")
val noteDurationBefore = activeControlButton?.noteDuration

// update control buttons if uid did not change
Expand Down
52 changes: 31 additions & 21 deletions app/src/main/java/de/moekadu/metronome/SoundChooserControlButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package de.moekadu.metronome
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.util.Log

@SuppressLint("ViewConstructor")
class SoundChooserControlButton(
Expand Down Expand Up @@ -60,10 +61,13 @@ class SoundChooserControlButton(
val noteId get() = note.id
val noteDuration get() = note.duration

private var cachedVisibility: Int? = null
private var cachedAlpha: Float? = null
//private var cachedVisibility: Int? = null
//private var cachedAlpha: Float? = null
private var cachedEndAction: (()->Unit)? = null

private var targetVisibility = GONE
private var targetAlpha = 1.0f

init {
setBackgroundResource(R.drawable.control_button_background)
this.elevation = elevation
Expand Down Expand Up @@ -165,52 +169,58 @@ class SoundChooserControlButton(
//// }
// }

private fun changeState(animationDuration: Long, alphaTarget: Float? = null,
private fun changeState(animationDuration: Long, alphaEnd: Float? = null,
visibilityStart: Int? = null, visibilityEnd: Int? = null,
endAction: (()->Unit)? = null) {
val animationDurationCorrected = if (visibility == VISIBLE || visibilityStart == VISIBLE) animationDuration else 0L
val alphaEnd = alphaTarget ?: cachedAlpha ?: alpha
require(!(visibilityStart != null && visibilityEnd != null))
val alphaEndResolved = alphaEnd ?: targetAlpha

if (alphaEnd != null)
targetAlpha = alphaEnd

if (visibilityStart != null)
targetVisibility = visibilityStart
if (visibilityEnd != null)
targetVisibility = visibilityEnd

cachedEndAction?.let {it()}
cachedEndAction = endAction

require(!(visibilityStart != null && visibilityEnd != null))
// Log.v("Metronome", "SoundChooserControlButton: changeState: uid=$uid, visibilityStart=$visibilityStart, visibilityEnd=$visibilityEnd")
animate()
.setDuration(animationDurationCorrected)
.translationX(translationXTarget)
.translationY(translationYTarget)
.alpha(alphaEnd)
.alpha(alphaEndResolved)
.withStartAction {
visibilityStart?.let {
visibility = it
}
cachedEndAction?.let {it()}
cachedEndAction = endAction

cachedAlpha = alphaEnd
cachedVisibility = visibilityEnd ?: cachedVisibility
if (visibilityStart != null)
visibility = visibilityStart
else if (visibilityEnd == null)
visibility = targetVisibility
}
.withEndAction {
translationX = translationXTarget
translationY = translationYTarget
visibility = visibilityEnd ?: cachedVisibility ?: visibility
cachedAlpha = null
cachedVisibility = null
visibility = targetVisibility
cachedEndAction?.let {it()}
cachedEndAction = null
// Log.v("Metronome", "SoundChooserControlButton: uid=$uid, visibilityStart=$visibilityStart, visibilityEnd=$visibilityEnd")
}
}

fun moveToTarget2(animationDuration: Long) {
// Log.v("Metronome", "SoundChooserControlButton.moveTotarget2")
// Log.v("Metronome", "SoundChooserControlButton.moveTotarget2, uid=$uid")
changeState(animationDuration, null, null, null)
}

fun moveToTarget2AndDisappear(animationDuration: Long, endAction: (()->Unit)? = null) {
// Log.v("Metronome", "SoundChooserControlButton.moveTotarget2AndDisappear")
// Log.v("Metronome", "SoundChooserControlButton.moveTotarget2AndDisappear uid=$uid")
changeState(animationDuration, 0f, null, GONE, endAction)
}

fun emerge(animationDuration: Long) {
// Log.v("Metronome", "SoundChooserControlButton.emerge")
//val animationDurationCorrected = if (visibility == VISIBLE && alpha == 1f) 0L else animationDuration
// Log.v("Metronome", "SoundChooserControlButton.emerge uid=$uid")
changeState(animationDuration, 1f, VISIBLE, null)
}
}
8 changes: 8 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/46.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
v4.3.1:
- Slightly increase scenes in compact view of scenes
- Slightly increase player controls in scenes view
- Update French translations (thanks to brilnius)

v4.3.2:
- Fix issue that active editing note was sometime not shows
- Update dependencies

0 comments on commit dc41544

Please sign in to comment.