Skip to content

Commit

Permalink
Changed dialogbox by checkbox for program update #141
Browse files Browse the repository at this point in the history
  • Loading branch information
brodeurlv committed Jul 24, 2021
1 parent 326b953 commit 4176744
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 50 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/com/easyfitness/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ public class MainActivity extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
//Log.e("Starting MainActivity", "Starting MainActivity");

SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String dayNightAuto = SP.getString("dayNightAuto", "2");
int dayNightAutoValue;
Expand Down
68 changes: 23 additions & 45 deletions app/src/main/java/com/easyfitness/RecordEditorDialogbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.easyfitness.DAO.record.DAORecord;
Expand All @@ -25,6 +26,7 @@ public class RecordEditorDialogbox extends Dialog implements View.OnClickListene
private final Record mRecord;
public Dialog d;
private WorkoutValuesInputView mWorkoutValuesInput;
private CheckBox mUpdateProgramCheckbox;
private boolean mCancelled = false;

public RecordEditorDialogbox(Activity a, Record record) {
Expand All @@ -50,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
Button updateButton = findViewById(R.id.btn_update);
Button failedButton = findViewById(R.id.btn_failed);
Button cancelButton = findViewById(R.id.btn_cancel);
mUpdateProgramCheckbox = findViewById(R.id.updateProgramCheckbox);
LinearLayout buttonsLayout = findViewById(R.id.buttons_layout);
mWorkoutValuesInput = findViewById(R.id.EditorWorkoutValuesInput);

Expand All @@ -61,9 +64,12 @@ protected void onCreate(Bundle savedInstanceState) {
failedButton.setVisibility(View.VISIBLE);
failedButton.setText(getContext().getString(R.string.fail));
buttonsLayout.setWeightSum(60);
mUpdateProgramCheckbox.setVisibility(View.VISIBLE);
mUpdateProgramCheckbox.setChecked(false);
} else {
updateButton.setText(getContext().getString(R.string.update));
failedButton.setVisibility(View.GONE);
mUpdateProgramCheckbox.setVisibility(View.GONE);
buttonsLayout.setWeightSum(40);
}

Expand All @@ -89,12 +95,10 @@ public void onClick(View v) {
distance = UnitConverter.MilesToKm(distance); // Always convert to KG
}

if (programTemplate!=null) {
if ((mWorkoutValuesInput.getDurationValue() > programTemplate.getDuration() ||
distance > programTemplate.getDistance()) &&
mWorkoutValuesInput.getDistanceUnit() == programTemplate.getDistanceUnit()) {
betterThanExisting = true;
}
if (programTemplate != null && mUpdateProgramCheckbox.isChecked()) {
programTemplate.setDuration(mWorkoutValuesInput.getDurationValue());
programTemplate.setDistance(distance);
programTemplate.setDistanceUnit(mWorkoutValuesInput.getDistanceUnit());
}

mRecord.setDuration(mWorkoutValuesInput.getDurationValue());
Expand All @@ -106,13 +110,11 @@ public void onClick(View v) {
float tmpPoids = mWorkoutValuesInput.getWeightValue();
tmpPoids = UnitConverter.weightConverter(tmpPoids, mWorkoutValuesInput.getWeightUnit(), WeightUnit.KG); // Always convert to KG

if (programTemplate!=null) {
if ((mWorkoutValuesInput.getSets() > programTemplate.getSets() ||
tmpPoids > programTemplate.getWeight() ||
mWorkoutValuesInput.getSeconds() > programTemplate.getSeconds()) &&
mWorkoutValuesInput.getWeightUnit() == programTemplate.getWeightUnit()) {
betterThanExisting = true;
}
if (programTemplate != null && mUpdateProgramCheckbox.isChecked()) {
programTemplate.setSets(mWorkoutValuesInput.getSets());
programTemplate.setSeconds(mWorkoutValuesInput.getSeconds());
programTemplate.setWeight(tmpPoids);
programTemplate.setWeightUnit(mWorkoutValuesInput.getWeightUnit());
}

mRecord.setSets(mWorkoutValuesInput.getSets());
Expand All @@ -124,13 +126,11 @@ public void onClick(View v) {
float tmpWeight = mWorkoutValuesInput.getWeightValue();
tmpPoids = UnitConverter.weightConverter(tmpWeight, mWorkoutValuesInput.getWeightUnit(), WeightUnit.KG); // Always convert to KG

if (programTemplate!=null) {
if ((mWorkoutValuesInput.getSets() > programTemplate.getSets() ||
tmpPoids > programTemplate.getWeight() ||
mWorkoutValuesInput.getReps() > programTemplate.getReps()) &&
mWorkoutValuesInput.getWeightUnit() == programTemplate.getWeightUnit()) {
betterThanExisting = true;
}
if (programTemplate != null && mUpdateProgramCheckbox.isChecked()) {
programTemplate.setSets(mWorkoutValuesInput.getSets());
programTemplate.setReps(mWorkoutValuesInput.getReps());
programTemplate.setWeight(tmpPoids);
programTemplate.setWeightUnit(mWorkoutValuesInput.getWeightUnit());
}

mRecord.setSets(mWorkoutValuesInput.getSets());
Expand All @@ -152,34 +152,12 @@ public void onClick(View v) {
mRecord.setProgramRecordStatus(ProgramRecordStatus.FAILED);
}

// If record is better than

daoRecord.updateRecord(mRecord);
if (programTemplate != null && mUpdateProgramCheckbox.isChecked()) {
daoRecord.updateRecord(programTemplate);
}
mCancelled = false;
dismiss();

if (betterThanExisting) {
final SweetAlertDialog dialog = new SweetAlertDialog(getContext(), SweetAlertDialog.WARNING_TYPE)
.setTitleText("Do you want to update program for next time?")
.setConfirmText(getContext().getString(R.string.global_yes))
.setCancelText(getContext().getString(R.string.global_no))
.setHideKeyBoardOnDismiss(true)
.setConfirmClickListener(sDialog -> {

if (programTemplate != null) {
programTemplate.setReps(mRecord.getReps());
programTemplate.setSeconds(mRecord.getSeconds());
programTemplate.setSets(mRecord.getSets());
programTemplate.setDistance(mRecord.getDistance());
programTemplate.setWeight(mRecord.getWeight());
programTemplate.setDuration(mRecord.getDuration());
daoRecord.updateRecord(programTemplate);
}

sDialog.dismiss();
});
dialog.show();
}
}
}

Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/layout/dialog_record_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@
android:layout_height="match_parent"
tool:selectedType="cardio"
tool:showRestTime="false"
tool:showTypeSelector="false" />
tool:showTypeSelector="false" >

</com.easyfitness.views.WorkoutValuesInputView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<CheckBox
android:id="@+id/updateProgramCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/also_update_program" />
</LinearLayout>

<LinearLayout
android:id="@+id/buttons_layout"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<string name="removedid">ID supprimé</string>
<string name="failedtocreatefolder">Echec de création du repertoire</string>


<string name="action_settings">Paramètres</string>
<string name="DateLabel">Date</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,5 @@
<string name="disclaimer_scoped_storage">Due to changes from Google, application files needs to be migrated. This can take some time if you have a lot of pictures. Please be patient.</string>
<string name="success">Success</string>
<string name="fail">Fail</string>
<string name="also_update_program">Also update program</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 4176744

Please sign in to comment.