diff --git a/app/build.gradle b/app/build.gradle index 697382f0..2e343697 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,14 +46,14 @@ android { productFlavors { pro { applicationId 'com.bodyweight.fitness.pro' - versionCode 113 - versionName "1.1.3" + versionCode 114 + versionName "1.1.4" } free { applicationId 'com.bodyweight.fitness.free' - versionCode 113 - versionName "1.1.3" + versionCode 114 + versionName "1.1.4" } } buildTypes { diff --git a/app/src/main/java/com/bodyweight/fitness/view/dialog/LogWorkoutDialog.java b/app/src/main/java/com/bodyweight/fitness/view/dialog/LogWorkoutDialog.java index 89fbe8b9..61fba5dc 100644 --- a/app/src/main/java/com/bodyweight/fitness/view/dialog/LogWorkoutDialog.java +++ b/app/src/main/java/com/bodyweight/fitness/view/dialog/LogWorkoutDialog.java @@ -2,6 +2,7 @@ import android.app.Dialog; import android.content.Context; +import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.Menu; @@ -32,6 +33,9 @@ import com.bodyweight.fitness.model.repository.RepositoryRoutine; import com.bodyweight.fitness.stream.RoutineStream; import com.bodyweight.fitness.utils.PreferenceUtils; +import com.bodyweight.fitness.view.listener.RepeatListener; + +import butterknife.OnTouch; import io.realm.Realm; public class LogWorkoutDialog { @@ -40,6 +44,8 @@ public interface OnDismissLogWorkoutDialogListener { } private static final int MAXIMUM_NUMBER_OF_SETS = 12; + private static final int REPEAT_INITIAL_INTERVAL = 400; + private static final int REPEAT_NORMAL_INTERVAL = 100; private Dialog mDialog; private OnDismissLogWorkoutDialogListener mOnDismissLogWorkoutDialogListener; @@ -71,6 +77,18 @@ public interface OnDismissLogWorkoutDialogListener { @InjectView(R.id.repsDescription) TextView mActionViewRepsDescription; + @InjectView(R.id.weightIncrease) + AppCompatImageButton mWeightIncrease; + + @InjectView(R.id.weightDecrease) + AppCompatImageButton mWeightDecrease; + + @InjectView(R.id.repsIncrease) + AppCompatImageButton mRepsIncrease; + + @InjectView(R.id.repsDecrease) + AppCompatImageButton mRepsDecrease; + private LinearLayout mRowLayout; private ArrayList mViewSets = new ArrayList<>(); @@ -118,6 +136,22 @@ private void buildDialog(Context context) { ButterKnife.inject(this, mDialog); + mWeightIncrease.setOnTouchListener( + new RepeatListener(REPEAT_INITIAL_INTERVAL, REPEAT_NORMAL_INTERVAL, (view) -> onClickIncreaseWeight()) + ); + + mWeightDecrease.setOnTouchListener( + new RepeatListener(REPEAT_INITIAL_INTERVAL, REPEAT_NORMAL_INTERVAL, (view) -> onClickDecreaseWeight()) + ); + + mRepsIncrease.setOnTouchListener( + new RepeatListener(REPEAT_INITIAL_INTERVAL, REPEAT_NORMAL_INTERVAL, (view) -> onClickIncreaseReps()) + ); + + mRepsDecrease.setOnTouchListener( + new RepeatListener(REPEAT_INITIAL_INTERVAL, REPEAT_NORMAL_INTERVAL, (view) -> onClickDecreaseReps()) + ); + mWeightMeasurementUnit = PreferenceUtils .getInstance() .getWeightMeasurementUnit(); @@ -450,13 +484,24 @@ public void inflateToolbarMenu() { switch (item.getItemId()) { case R.id.action_add_set: { if (shouldAddSet()) { + int seconds = 0; + double weight = 0; + int reps = 0; + + if (!mRepositoryExercise.getSets().isEmpty()) { + RepositorySet repositorySet = mRepositoryExercise.getSets().last(); + seconds = repositorySet.getSeconds(); + weight = repositorySet.getWeight(); + reps = repositorySet.getReps(); + } + RepositorySet repositorySet = mRealm.createObject(RepositorySet.class); repositorySet.setId("Set-" + UUID.randomUUID().toString()); repositorySet.setIsTimed(false); - repositorySet.setSeconds(0); - repositorySet.setWeight(0); - repositorySet.setReps(0); + repositorySet.setSeconds(seconds); + repositorySet.setWeight(weight); + repositorySet.setReps(reps); repositorySet.setExercise(mRepositoryExercise); @@ -469,13 +514,24 @@ public void inflateToolbarMenu() { case R.id.action_add_timed_set: { if (shouldAddSet()) { + int seconds = 0; + double weight = 0; + int reps = 0; + + if (!mRepositoryExercise.getSets().isEmpty()) { + RepositorySet repositorySet = mRepositoryExercise.getSets().last(); + seconds = repositorySet.getSeconds(); + weight = repositorySet.getWeight(); + reps = repositorySet.getReps(); + } + RepositorySet repositorySet = mRealm.createObject(RepositorySet.class); repositorySet.setId("Set-" + UUID.randomUUID().toString()); repositorySet.setIsTimed(true); - repositorySet.setSeconds(0); - repositorySet.setWeight(0); - repositorySet.setReps(0); + repositorySet.setSeconds(seconds); + repositorySet.setWeight(weight); + repositorySet.setReps(reps); repositorySet.setExercise(mRepositoryExercise); @@ -506,9 +562,7 @@ public void invalidateToolbarMenu() { mToolbar.getMenu().clear(); } - @OnClick(R.id.weightIncrease) - @SuppressWarnings("unused") - public void onClickIncreaseWeight(View view) { + public void onClickIncreaseWeight() { if(mSet.isTimed()) { if(mSet.getSeconds() % 60 == 59) { mSet.setSeconds(mSet.getSeconds() - 59); @@ -521,7 +575,7 @@ public void onClickIncreaseWeight(View view) { setLastUpdatedTime(); } else { - if(mSet.getWeight() >= 500) { + if(mSet.getWeight() >= 250) { return; } @@ -537,9 +591,7 @@ public void onClickIncreaseWeight(View view) { } } - @OnClick(R.id.weightDecrease) - @SuppressWarnings("unused") - public void onClickDecreaseWeight(View view) { + public void onClickDecreaseWeight() { if(mSet.isTimed()) { if(mSet.getSeconds() % 60 == 0) { mSet.setSeconds(mSet.getSeconds() + 59); @@ -568,9 +620,7 @@ public void onClickDecreaseWeight(View view) { } } - @OnClick(R.id.repsIncrease) - @SuppressWarnings("unused") - public void onClickIncreaseReps(View view) { + public void onClickIncreaseReps() { if(mSet.isTimed()) { if (mSet.getSeconds() / 60 >= 5) { return; @@ -595,9 +645,7 @@ public void onClickIncreaseReps(View view) { } } - @OnClick(R.id.repsDecrease) - @SuppressWarnings("unused") - public void onClickDecreaseReps(View view) { + public void onClickDecreaseReps() { if(mSet.isTimed()) { if(mSet.getSeconds() >= 60) { mSet.setSeconds(mSet.getSeconds() - 60); diff --git a/app/src/main/java/com/bodyweight/fitness/view/listener/RepeatListener.java b/app/src/main/java/com/bodyweight/fitness/view/listener/RepeatListener.java new file mode 100644 index 00000000..c7a411ed --- /dev/null +++ b/app/src/main/java/com/bodyweight/fitness/view/listener/RepeatListener.java @@ -0,0 +1,54 @@ +package com.bodyweight.fitness.view.listener; + +import android.os.Handler; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnTouchListener; + +public class RepeatListener implements OnTouchListener { + private Handler handler = new Handler(); + + private int initialInterval; + private final int normalInterval; + + private final OnClickListener clickListener; + + private Runnable handlerRunnable = new Runnable() { + @Override + public void run() { + handler.postDelayed(this, normalInterval); + clickListener.onClick(downView); + } + }; + + private View downView; + + public RepeatListener(int initialInterval, int normalInterval, OnClickListener clickListener) { + this.initialInterval = initialInterval; + this.normalInterval = normalInterval; + this.clickListener = clickListener; + } + + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + handler.removeCallbacks(handlerRunnable); + handler.postDelayed(handlerRunnable, initialInterval); + downView = view; + downView.setPressed(true); + clickListener.onClick(view); + + return true; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + handler.removeCallbacks(handlerRunnable); + downView.setPressed(false); + downView = null; + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 50e5430d..a3da2d36 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:2.0.0-alpha3' + classpath 'com.android.tools.build:gradle:2.0.0-alpha5' classpath 'me.tatarka:gradle-retrolambda:3.1.0' classpath 'io.fabric.tools:gradle:1.+' }