Skip to content

Commit

Permalink
Merge pull request #22 from mazurio/114-release
Browse files Browse the repository at this point in the history
Release 1.1.4
  • Loading branch information
mazurio committed Jan 16, 2016
2 parents ca58d2c + 5cf8e7b commit 4251998
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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<View> mViewSets = new ArrayList<>();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -521,7 +575,7 @@ public void onClickIncreaseWeight(View view) {

setLastUpdatedTime();
} else {
if(mSet.getWeight() >= 500) {
if(mSet.getWeight() >= 250) {
return;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.+'
}
Expand Down

0 comments on commit 4251998

Please sign in to comment.