Skip to content

Commit

Permalink
🐛 Fixed bug that called animationComplete() twice
Browse files Browse the repository at this point in the history
  • Loading branch information
germano.oliveira committed Jan 6, 2018
1 parent 0ba035c commit fffbcd6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ArcProgressAnimation extends Animation {
private float startingAngle;
private float endingAngle;
private TimerListener timerListener;
private boolean isFinished;

/**
* Instantiates a new Arc progress animation.
Expand All @@ -31,16 +32,17 @@ public ArcProgressAnimation(LinearTimerView linearTimerView, int endingAngle,

@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation) {

float finalAngle = startingAngle + ((endingAngle - startingAngle) * interpolatedTime);

linearTimerView.setPreFillAngle(finalAngle);
linearTimerView.requestLayout();

// If interpolatedTime = 0.0 -> Animation has started.
// If interpolatedTime = 1.0 -> Animation has completed.
if(interpolatedTime == 1.0)
timerListener.animationComplete();
if(interpolatedTime == 1.0){
if(isFinished) timerListener.animationComplete();
isFinished = true;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private LinearTimer(Builder builder) {
linearTimerView.setPreFillAngle(preFillAngle);

// Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.INITIALIZED.getStaus();
intStatusCode = LinearTimerStates.INITIALIZED.getStatus();

// If the user wants to show the progress in counter clock wise manner,
// we flip the view on its Y-Axis and let it function as is.
Expand Down Expand Up @@ -102,9 +102,9 @@ private void determinePreFillAngle() {
public void startTimer() {

if (basicParametersCheck()) {
if (intStatusCode == LinearTimerStates.INITIALIZED.getStaus()) {
if (intStatusCode == LinearTimerStates.INITIALIZED.getStatus()) {
// Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.ACTIVE.getStaus();
intStatusCode = LinearTimerStates.ACTIVE.getStatus();
arcProgressAnimation = new ArcProgressAnimation(linearTimerView, endingAngle, this);
arcProgressAnimation.setDuration(animationDuration);
linearTimerView.startAnimation(arcProgressAnimation);
Expand All @@ -124,10 +124,10 @@ public void startTimer() {
public void pauseTimer() throws IllegalStateException {
if (basicParametersCheck()) {
// Timer may be paused only in active state.
if (intStatusCode == LinearTimerStates.ACTIVE.getStaus()) {
if (intStatusCode == LinearTimerStates.ACTIVE.getStatus()) {

// Store the current status code in intStatusCode integer.
intStatusCode = LinearTimerStates.PAUSED.getStaus();
intStatusCode = LinearTimerStates.PAUSED.getStatus();

// Clear animations off of linearTimerView, set prefillAngle to current
// state and refresh view.
Expand All @@ -152,7 +152,7 @@ else if (countType == COUNT_UP_TIMER)
*/
public void resumeTimer() throws IllegalStateException {
if (basicParametersCheck()) {
if (intStatusCode == LinearTimerStates.PAUSED.getStaus()) {
if (intStatusCode == LinearTimerStates.PAUSED.getStatus()) {

// Reinitialize the animations as it may not be simply continued.
// The animation is reinitialized with the linearTimerView,
Expand All @@ -178,7 +178,7 @@ else if (countType == COUNT_UP_TIMER)
linearTimerView.startAnimation(arcProgressAnimation);

// Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.ACTIVE.getStaus();
intStatusCode = LinearTimerStates.ACTIVE.getStatus();
} else
throw new IllegalStateException("LinearTimer is not in paused state right now.");
}
Expand All @@ -191,7 +191,7 @@ public void restartTimer() {
if (basicParametersCheck()) {
if (arcProgressAnimation != null) {
// Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.ACTIVE.getStaus();
intStatusCode = LinearTimerStates.ACTIVE.getStatus();

// Reset the pre filling angle as passed by user during initialization
linearTimerView.setPreFillAngle(preFillAngle);
Expand All @@ -213,10 +213,10 @@ public void restartTimer() {
*/
public void resetTimer() {
if (basicParametersCheck()) {
if (intStatusCode == LinearTimerStates.PAUSED.getStaus()
|| intStatusCode == LinearTimerStates.FINISHED.getStaus()) {
if (intStatusCode == LinearTimerStates.PAUSED.getStatus()
|| intStatusCode == LinearTimerStates.FINISHED.getStatus()) {
//Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.INITIALIZED.getStaus();
intStatusCode = LinearTimerStates.INITIALIZED.getStatus();

//Cancel the circle animation
arcProgressAnimation.cancel();
Expand Down Expand Up @@ -270,7 +270,7 @@ public void animationComplete() {
try {
if (listenerCheck()) {
// Store the current status code in intStatusCode integer
intStatusCode = LinearTimerStates.FINISHED.getStaus();
intStatusCode = LinearTimerStates.FINISHED.getStatus();
timerListener.animationComplete();
}
} catch (LinearTimerListenerMissingException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onTick(long millisUntilFinished) {

@Override
public void onFinish() {
if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStaus())
if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStatus())
timerListener.timerTick(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onTick(long elapsedTime) {

@Override
public void onFinish() {
if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStaus())
if (LinearTimer.intStatusCode != LinearTimerStates.PAUSED.getStatus())
if (timerListener != null)
timerListener.timerTick(timerDuration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum LinearTimerStates {
* A method to return the affixed integer representation of the Status codes.
* @return An integer that represents the LinearTimer current status
*/
public int getStaus() {
public int getStatus() {
return intStatusCode;
}
}

0 comments on commit fffbcd6

Please sign in to comment.