mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-29 08:42:12 -07:00
#1 User defined workout titles and description
This commit is contained in:
parent
336d0890ea
commit
58784c3078
@ -22,14 +22,13 @@ package de.tadris.fitness.activity;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.github.clans.fab.FloatingActionButton;
|
|
||||||
import com.github.clans.fab.FloatingActionMenu;
|
import com.github.clans.fab.FloatingActionMenu;
|
||||||
|
|
||||||
import de.tadris.fitness.Instance;
|
import de.tadris.fitness.Instance;
|
||||||
@ -66,8 +65,10 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startRecording(String activity){
|
public void startRecording(String activity){
|
||||||
|
menu.close(true);
|
||||||
RecordWorkoutActivity.ACTIVITY= activity;
|
RecordWorkoutActivity.ACTIVITY= activity;
|
||||||
startActivity(new Intent(this, RecordWorkoutActivity.class));
|
final Intent intent= new Intent(this, RecordWorkoutActivity.class);
|
||||||
|
new Handler().postDelayed(() -> startActivity(intent), 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
package de.tadris.fitness.activity;
|
package de.tadris.fitness.activity;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@ -30,6 +31,7 @@ import android.os.PowerManager;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
@ -53,7 +55,6 @@ import de.tadris.fitness.location.WorkoutRecorder;
|
|||||||
import de.tadris.fitness.map.MapManager;
|
import de.tadris.fitness.map.MapManager;
|
||||||
import de.tadris.fitness.util.ThemeManager;
|
import de.tadris.fitness.util.ThemeManager;
|
||||||
import de.tadris.fitness.util.UnitUtils;
|
import de.tadris.fitness.util.UnitUtils;
|
||||||
import de.tadris.fitness.util.WorkoutTypeCalculator;
|
|
||||||
|
|
||||||
public class RecordWorkoutActivity extends FitoTrackActivity implements LocationListener.LocationChangeListener {
|
public class RecordWorkoutActivity extends FitoTrackActivity implements LocationListener.LocationChangeListener {
|
||||||
|
|
||||||
@ -152,14 +153,40 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopAndSave(){
|
private void stop(){
|
||||||
recorder.stop();
|
recorder.stop();
|
||||||
|
if(recorder.getSampleCount() > 3){
|
||||||
|
showEnterDescriptionDialog();
|
||||||
|
}else{
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveAndClose(){
|
||||||
if(recorder.getSampleCount() > 3){
|
if(recorder.getSampleCount() > 3){
|
||||||
recorder.save();
|
recorder.save();
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showEnterDescriptionDialog(){
|
||||||
|
final EditText editText= new EditText(this);
|
||||||
|
new AlertDialog.Builder(this).setTitle(R.string.enterComment).setPositiveButton(R.string.okay, (dialog, which) -> {
|
||||||
|
dialog.cancel();
|
||||||
|
recorder.setComment(editText.getText().toString());
|
||||||
|
saveAndClose();
|
||||||
|
}).setView(editText).setCancelable(false).create().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAreYouSureToStopDialog(){
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.stopRecordingQuestion)
|
||||||
|
.setMessage(R.string.stopRecordingQuestionMessage)
|
||||||
|
.setPositiveButton(R.string.okay, (dialog, which) -> stop())
|
||||||
|
.setNegativeButton(R.string.continue_, null)
|
||||||
|
.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
void checkPermissions(){
|
void checkPermissions(){
|
||||||
if (!hasPermission()) {
|
if (!hasPermission()) {
|
||||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 10);
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 10);
|
||||||
@ -240,12 +267,21 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
if(id == R.id.actionRecordingStop){
|
if(id == R.id.actionRecordingStop){
|
||||||
stopAndSave();
|
stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if(recorder.getSampleCount() > 3){
|
||||||
|
showAreYouSureToStopDialog();
|
||||||
|
}else{
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class InfoViewHolder{
|
public static class InfoViewHolder{
|
||||||
TextView titleView, valueView;
|
TextView titleView, valueView;
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.mikephil.charting.charts.LineChart;
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
@ -93,6 +94,11 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
|||||||
|
|
||||||
root= findViewById(R.id.showWorkoutRoot);
|
root= findViewById(R.id.showWorkoutRoot);
|
||||||
|
|
||||||
|
addText(getString(R.string.comment) + ": " + workout.comment).setOnClickListener(v -> {
|
||||||
|
TextView textView= (TextView)v;
|
||||||
|
openEditCommentDialog(textView);
|
||||||
|
});
|
||||||
|
|
||||||
addTitle(getString(R.string.workoutTime));
|
addTitle(getString(R.string.workoutTime));
|
||||||
addKeyValue(getString(R.string.workoutDate), getDate());
|
addKeyValue(getString(R.string.workoutDate), getDate());
|
||||||
addKeyValue(getString(R.string.workoutDuration), UnitUtils.getHourMinuteSecondTime(workout.duration),
|
addKeyValue(getString(R.string.workoutDuration), UnitUtils.getHourMinuteSecondTime(workout.duration),
|
||||||
@ -120,6 +126,21 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void openEditCommentDialog(final TextView change){
|
||||||
|
final EditText editText= new EditText(this);
|
||||||
|
editText.setText(workout.comment);
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.enterComment)
|
||||||
|
.setPositiveButton(R.string.okay, (dialog, which) -> changeComment(editText.getText().toString(), change))
|
||||||
|
.setView(editText).create().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void changeComment(String comment, TextView onChange){
|
||||||
|
workout.comment= comment;
|
||||||
|
Instance.getInstance(this).db.workoutDao().updateWorkout(workout);
|
||||||
|
onChange.setText(getString(R.string.comment) + ": " + workout.comment);
|
||||||
|
}
|
||||||
|
|
||||||
String getDate(){
|
String getDate(){
|
||||||
return SimpleDateFormat.getDateInstance().format(new Date(workout.start));
|
return SimpleDateFormat.getDateInstance().format(new Date(workout.start));
|
||||||
}
|
}
|
||||||
@ -137,6 +158,18 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
|||||||
root.addView(textView);
|
root.addView(textView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextView addText(String text){
|
||||||
|
TextView textView= new TextView(this);
|
||||||
|
textView.setText(text);
|
||||||
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||||
|
textView.setTextColor(getThemePrimaryColor());
|
||||||
|
textView.setPadding(0, 20, 0, 0);
|
||||||
|
|
||||||
|
root.addView(textView);
|
||||||
|
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
|
||||||
void addKeyValue(String key1, String value1){
|
void addKeyValue(String key1, String value1){
|
||||||
addKeyValue(key1, value1, "", "");
|
addKeyValue(key1, value1, "", "");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,8 @@ public class Workout{
|
|||||||
|
|
||||||
public long pauseDuration;
|
public long pauseDuration;
|
||||||
|
|
||||||
|
public String comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Length of workout in meters
|
* Length of workout in meters
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -245,6 +245,10 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment){
|
||||||
|
workout.comment= comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum RecordingState{
|
enum RecordingState{
|
||||||
IDLE, RUNNING, PAUSED, STOPPED
|
IDLE, RUNNING, PAUSED, STOPPED
|
||||||
|
|||||||
@ -48,6 +48,16 @@
|
|||||||
|
|
||||||
<string name="recordWorkout">Record Workout</string>
|
<string name="recordWorkout">Record Workout</string>
|
||||||
|
|
||||||
|
<string name="comment">Comment</string>
|
||||||
|
<string name="enterComment">Enter Comment</string>
|
||||||
|
<string name="okay">Okay</string>
|
||||||
|
|
||||||
|
<string name="stopRecordingQuestion">Stop Recording?</string>
|
||||||
|
<string name="stopRecordingQuestionMessage">Do you really want to stop the recording?</string>
|
||||||
|
|
||||||
|
<!-- leave the underscore because "continue" is a java command -->
|
||||||
|
<string name="continue_">Continue</string>
|
||||||
|
|
||||||
<string name="deleteWorkout">Delete Workout</string>
|
<string name="deleteWorkout">Delete Workout</string>
|
||||||
<string name="deleteWorkoutMessage">Do you really want to delete the workout?</string>
|
<string name="deleteWorkoutMessage">Do you really want to delete the workout?</string>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user