Skip to content

Commit

Permalink
Finalized brodeurlv#61
Browse files Browse the repository at this point in the history
  • Loading branch information
brodeurlv committed Jun 15, 2019
1 parent b2c432e commit ecba9e7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 78 deletions.
150 changes: 75 additions & 75 deletions app/src/main/java/com/easyfitness/DAO/CVSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public boolean exportDatabase(Profile pProfile) {
try {
exportFontes(exportDir, pProfile);
exportCardio(exportDir, pProfile);
exportStatic(exportDir, pProfile);
exportIsometric(exportDir, pProfile);
exportProfileWeight(exportDir, pProfile);
exportBodyMeasures(exportDir, pProfile);
exportExercise(exportDir, pProfile);
Expand Down Expand Up @@ -144,6 +144,73 @@ public boolean exportFontes(File exportDir, Profile pProfile) {
return true;
}

public boolean exportIsometric(File exportDir, Profile pProfile) {
try {
// FONTE
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_H_m_s");
Date date = new Date();

CsvWriter csvOutput = new CsvWriter(exportDir.getPath() + "/" + "EF_" + pProfile.getName() + "_Isometric_" + dateFormat.format(date) + ".csv", ',', Charset.forName("UTF-8"));

/**This is our database connector class that reads the data from the database.
* The code of this class is omitted for brevity.
*/
DAOStatic daoStatic = new DAOStatic(mContext);
daoStatic.open();

/**Let's read the first table of the database.
* getFirstTable() is a method in our DBCOurDatabaseConnector class which retrieves a Cursor
* containing all records of the table (all fields).
* The code of this class is omitted for brevity.
*/
List<StaticExercise> records = null;
records = daoStatic.getAllStaticRecordsByProfileArray(pProfile);

//Write the name of the table and the name of the columns (comma separated values) in the .csv file.
csvOutput.write(TABLE_HEAD);
csvOutput.write(ID_HEAD);
csvOutput.write(DAOStatic.DATE);
csvOutput.write(DAOStatic.EXERCISE);
csvOutput.write(DAOStatic.WEIGHT);
csvOutput.write(DAOStatic.SECONDS);
csvOutput.write(DAOStatic.SERIE);
csvOutput.write(DAOStatic.PROFIL_KEY);
csvOutput.write(DAOStatic.UNIT);
csvOutput.write(DAOStatic.NOTES);
csvOutput.endRecord();

for (int i = 0; i < records.size(); i++) {
csvOutput.write(DAOStatic.TABLE_NAME);
csvOutput.write(Long.toString(records.get(i).getId()));

Date dateRecord = records.get(i).getDate();

SimpleDateFormat dateFormatcsv = new SimpleDateFormat(DAOUtils.DATE_FORMAT);

csvOutput.write(dateFormatcsv.format(dateRecord));
csvOutput.write(records.get(i).getExercise());
csvOutput.write(Float.toString(records.get(i).getPoids()));
csvOutput.write(Integer.toString(records.get(i).getSecond()));
csvOutput.write(Integer.toString(records.get(i).getSerie()));
if (records.get(i).getProfil() != null)
csvOutput.write(Long.toString(records.get(i).getProfil().getId()));
else csvOutput.write("-1");
csvOutput.write(Integer.toString(records.get(i).getUnit()));
if (records.get(i).getNote() == null) csvOutput.write("");
else csvOutput.write(records.get(i).getNote());
csvOutput.endRecord();
}
csvOutput.close();
daoStatic.closeAll();
} catch (Exception e) {
//if there are any exceptions, return false
e.printStackTrace();
return false;
}
//If there are no errors, return true.
return true;
}

public boolean exportProfileWeight(File exportDir, Profile pProfile) {
try {
// FONTE
Expand Down Expand Up @@ -296,73 +363,6 @@ public boolean exportCardio(File exportDir, Profile pProfile) {
return true;
}

public boolean exportStatic(File exportDir, Profile pProfile) {
try {
// CARDIO
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_H_m_s");
Date date = new Date();

CsvWriter csvOutput = new CsvWriter(exportDir.getPath() + "/" + "EF_" + pProfile.getName() + "_Cardio_" + dateFormat.format(date) + ".csv", ',', Charset.forName("UTF-8"));

/**This is our database connector class that reads the data from the database.
* The code of this class is omitted for brevity.
*/
DAOStatic dbcStatic = new DAOStatic(mContext);
dbcStatic.open();

/**Let's read the first table of the database.
* getFirstTable() is a method in our DBCOurDatabaseConnector class which retrieves a Cursor
* containing all records of the table (all fields).
* The code of this class is omitted for brevity.
*/
List<StaticExercise> records = null;
records = dbcStatic.getAllStaticRecordsByProfileArray(pProfile);

//Write the name of the table and the name of the columns (comma separated values) in the .csv file.
csvOutput.write(TABLE_HEAD);
csvOutput.write(ID_HEAD);
csvOutput.write(DAOStatic.DATE);
csvOutput.write(DAOStatic.TIME);
csvOutput.write(DAOStatic.EXERCISE);
csvOutput.write(DAOStatic.SERIE);
csvOutput.write(DAOStatic.SECONDS);
csvOutput.write(DAOStatic.WEIGHT);
csvOutput.write(DAOStatic.UNIT);
csvOutput.write(DAOStatic.PROFIL_KEY);
csvOutput.endRecord();

for (int i = 0; i < records .size(); i++) {
csvOutput.write(DAOCardio.TABLE_NAME);
csvOutput.write(Long.toString(records .get(i).getId()));

Date dateRecord = records .get(i).getDate();

SimpleDateFormat dateFormatcsv = new SimpleDateFormat(DAOUtils.DATE_FORMAT);

csvOutput.write(dateFormatcsv.format(dateRecord));
csvOutput.write(records .get(i).getTime());
csvOutput.write(records .get(i).getExercise());
csvOutput.write(Integer.toString(records .get(i).getSerie()));
csvOutput.write(Integer.toString(records .get(i).getSecond()));
csvOutput.write(Float.toString(records .get(i).getPoids()));
csvOutput.write(Integer.toString(records.get(i).getUnit()));
if (records .get(i).getProfil() != null)
csvOutput.write(Long.toString(records .get(i).getProfil().getId()));
else csvOutput.write("-1");
//write the record in the .csv file
csvOutput.endRecord();
}
csvOutput.close();
dbcStatic.close();
} catch (Exception e) {
//if there are any exceptions, return false
e.printStackTrace();
return false;
}
//If there are no errors, return true.
return true;
}

public boolean exportExercise(File exportDir, Profile pProfile) {
try {
// FONTE
Expand Down Expand Up @@ -464,15 +464,15 @@ public boolean importDatabase(String file, Profile pProfile) {
dbcCardio.addCardioRecord(date, time, exercise, distance, duration, pProfile);
dbcCardio.close();
} else if (dbcMachine.getMachine(machine).getType() == DAOMachine.TYPE_STATIC) {
float poids = Float.valueOf(csvRecords.get(DAOFonte.WEIGHT));
int second = Integer.valueOf(csvRecords.get(DAOFonte.SECONDS));
int serie = Integer.valueOf(csvRecords.get(DAOFonte.SERIE));
float poids = Float.valueOf(csvRecords.get(DAOStatic.WEIGHT));
int second = Integer.valueOf(csvRecords.get(DAOStatic.SECONDS));
int serie = Integer.valueOf(csvRecords.get(DAOStatic.SERIE));
int unit = 0;
if (!csvRecords.get(DAOFonte.UNIT).isEmpty()) {
unit = Integer.valueOf(csvRecords.get(DAOFonte.UNIT));
if (!csvRecords.get(DAOStatic.UNIT).isEmpty()) {
unit = Integer.valueOf(csvRecords.get(DAOStatic.UNIT));
}
String notes = csvRecords.get(DAOFonte.NOTES);
String time = csvRecords.get(DAOFonte.TIME);
String notes = csvRecords.get(DAOStatic.NOTES);
String time = csvRecords.get(DAOStatic.TIME);
dbcStatic.addStaticRecord(date, machine, serie, second, poids, pProfile, unit, notes, time);
dbcStatic.close();
}
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/com/easyfitness/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyfitness;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -15,6 +16,7 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
Expand Down Expand Up @@ -49,6 +51,7 @@
import com.easyfitness.intro.MainIntroActivity;
import com.easyfitness.machines.MachineFragment;
import com.easyfitness.utils.CustomExceptionHandler;
import com.easyfitness.utils.EditableInputView.EditableInputView;
import com.easyfitness.utils.FileChooserDialog;
import com.easyfitness.utils.ImageUtil;
import com.easyfitness.utils.MusicController;
Expand All @@ -61,6 +64,8 @@
import java.util.ArrayList;
import java.util.List;

import cn.pedant.SweetAlert.SweetAlertDialog;

//import com.crashlytics.android.Crashlytics;

//import io.fabric.sdk.android.Fabric;
Expand Down Expand Up @@ -458,8 +463,25 @@ public boolean onOptionsItemSelected(MenuItem item) {
m_importCVSchosenDir = chosenDir;
//Toast.makeText(getActivity().getBaseContext(), "Chosen directory: " +
// chosenDir, Toast.LENGTH_LONG).show();
CVSManager cvsMan = new CVSManager(getActivity().getBaseContext());
cvsMan.importDatabase(m_importCVSchosenDir, getCurrentProfil());
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText(this.getResources().getString(R.string.global_confirm_question))
.setConfirmText(this.getResources().getString(R.string.global_yes))
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.dismissWithAnimation();
CVSManager cvsMan = new CVSManager(getActivity().getBaseContext());
if(cvsMan.importDatabase(m_importCVSchosenDir, getCurrentProfil())) {
KToast.successToast(getActivity(), m_importCVSchosenDir + getActivity().getResources().getString(R.string.imported_successfully), Gravity.BOTTOM, KToast.LENGTH_SHORT );
} else {
KToast.errorToast(getActivity(), m_importCVSchosenDir + getActivity().getResources().getString(R.string.import_failed), Gravity.BOTTOM, KToast.LENGTH_SHORT );
}
setCurrentProfil(getCurrentProfil()); // Refresh profile
}

})
.show();

});

fileChooserDialog.setFileFilter("csv");
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,10 @@
<string name="staticExercise">"Isometrische "</string>
<string name="what_type_of_exercise">Welche Art von Training ?</string>
<string name="exercise_type">Art von Training:</string>
<string name="global_confirm_question">Sind sie sicher?</string>
<string name="imported_successfully">import gelungen</string>
<string name="import_failed">import ist fehlgeschlagen</string>
<string name="maxWeightPerDuration">Max Gewicht pro Dauer</string>
<string name="nbSeriesPerDate">Nb Serien nach Datum</string>
</resources>

5 changes: 5 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@
<string name="exercise_type">Type d\'exercice:</string>
<string name="staticExercise">Isometrique</string>
<string name="what_type_of_exercise">Quel type d\'exercice ?</string>
<string name="global_confirm_question">Etes-vous sûr ?</string>
<string name="import_failed">import a échoué</string>
<string name="imported_successfully">import réussit</string>
<string name="maxWeightPerDuration">Poids max par durée</string>
<string name="nbSeriesPerDate">Nb séries par date</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="global_confirm">Confirm</string>
<string name="global_confirm_question">Are you sure?</string>
<string name="global_warning">Warning</string>
<string name="global_error">Error</string>
<string name="global_cancel">Cancel</string>
Expand Down Expand Up @@ -86,6 +87,7 @@
<string name="export_success">Database exported</string>
<string name="export_failed">Database export failed</string>
<string name="import_database">Import Records</string>

<string name="deleteDB_warning">
This action will reset the entire application.
All data will be lost.
Expand Down Expand Up @@ -311,5 +313,7 @@
<string name="exercise_type">Exercise Type:</string>
<string name="staticExercise">Isometric</string>
<string name="SecondsLabel_short">Secs</string>
<string name="imported_successfully"> imported successfully</string>
<string name="import_failed"> import failed</string>

</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', 'sweet-alert-dialog'
include ':app'

0 comments on commit ecba9e7

Please sign in to comment.