Skip to content

Commit

Permalink
add boolean return value to SparkEventListener that controls animation (
Browse files Browse the repository at this point in the history
  • Loading branch information
connyduck authored Mar 2, 2020
1 parent 30fd0a2 commit ab06bbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions sparkbutton/src/main/java/at/connyduck/sparkbutton/SparkButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,26 @@ public void setEventListener(SparkEventListener listener) {

@Override
public void onClick(View v) {
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;
boolean shouldPlayAnimation = listener == null || listener.onEvent(this, isChecked);

imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
if(shouldPlayAnimation) {
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;

if (animatorSet != null) {
animatorSet.cancel();
}
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);

if (animatorSet != null) {
animatorSet.cancel();
}
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
} else {
sparkAnimationView.setVisibility(INVISIBLE);
}
} else {
sparkAnimationView.setVisibility(INVISIBLE);
playAnimation();
}
} else {
playAnimation();
}
if (listener != null) {
listener.onEvent(this, isChecked);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
import androidx.annotation.NonNull;

public interface SparkEventListener {
void onEvent(@NonNull SparkButton button, boolean buttonState);
boolean onEvent(@NonNull SparkButton button, boolean buttonState);
}

0 comments on commit ab06bbc

Please sign in to comment.