#1 User defined workout titles and description

This commit is contained in:
jannis 2019-08-19 17:03:06 +02:00
parent 336d0890ea
commit 58784c3078
6 changed files with 92 additions and 6 deletions

View File

@ -22,14 +22,13 @@ package de.tadris.fitness.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;
import de.tadris.fitness.Instance;
@ -66,8 +65,10 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
}
public void startRecording(String activity){
menu.close(true);
RecordWorkoutActivity.ACTIVITY= activity;
startActivity(new Intent(this, RecordWorkoutActivity.class));
final Intent intent= new Intent(this, RecordWorkoutActivity.class);
new Handler().postDelayed(() -> startActivity(intent), 300);
}
@Override

View File

@ -20,6 +20,7 @@
package de.tadris.fitness.activity;
import android.Manifest;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
@ -30,6 +31,7 @@ import android.os.PowerManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
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.util.ThemeManager;
import de.tadris.fitness.util.UnitUtils;
import de.tadris.fitness.util.WorkoutTypeCalculator;
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()));
}
private void stopAndSave(){
private void stop(){
recorder.stop();
if(recorder.getSampleCount() > 3){
showEnterDescriptionDialog();
}else{
finish();
}
}
private void saveAndClose(){
if(recorder.getSampleCount() > 3){
recorder.save();
}
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(){
if (!hasPermission()) {
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) {
int id = item.getItemId();
if(id == R.id.actionRecordingStop){
stopAndSave();
stop();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if(recorder.getSampleCount() > 3){
showAreYouSureToStopDialog();
}else{
super.onBackPressed();
}
}
public static class InfoViewHolder{
TextView titleView, valueView;

View File

@ -30,6 +30,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
@ -93,6 +94,11 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
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));
addKeyValue(getString(R.string.workoutDate), getDate());
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(){
return SimpleDateFormat.getDateInstance().format(new Date(workout.start));
}
@ -137,6 +158,18 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
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){
addKeyValue(key1, value1, "", "");
}

View File

@ -39,6 +39,8 @@ public class Workout{
public long pauseDuration;
public String comment;
/**
* Length of workout in meters
*/

View File

@ -245,6 +245,10 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
}
}
public void setComment(String comment){
workout.comment= comment;
}
enum RecordingState{
IDLE, RUNNING, PAUSED, STOPPED

View File

@ -48,6 +48,16 @@
<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="deleteWorkoutMessage">Do you really want to delete the workout?</string>