mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-28 16:22:12 -07:00
Delete workouts via long press in workout list
This commit is contained in:
parent
82e383e953
commit
9c3e4021f8
@ -37,6 +37,7 @@ import com.github.clans.fab.FloatingActionMenu;
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.data.Workout;
|
||||
import de.tadris.fitness.util.DialogUtils;
|
||||
import de.tadris.fitness.view.WorkoutAdapter;
|
||||
|
||||
public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.WorkoutAdapterListener {
|
||||
@ -75,6 +76,9 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
|
||||
|
||||
checkFirstStart();
|
||||
|
||||
adapter= new WorkoutAdapter(workouts, this);
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
}
|
||||
|
||||
private void checkFirstStart(){
|
||||
@ -101,9 +105,8 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
workouts= Instance.getInstance(this).db.workoutDao().getWorkouts();
|
||||
adapter= new WorkoutAdapter(workouts, this);
|
||||
listView.setAdapter(adapter);
|
||||
loadData();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,6 +115,19 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
|
||||
startActivity(new Intent(this, ShowWorkoutActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(int pos, Workout workout) {
|
||||
DialogUtils.showDeleteWorkoutDialog(this, () -> {
|
||||
Instance.getInstance(ListWorkoutsActivity.this).db.workoutDao().deleteWorkout(workout);
|
||||
loadData();
|
||||
adapter.notifyItemRemoved(pos);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadData(){
|
||||
workouts= Instance.getInstance(this).db.workoutDao().getWorkouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
@ -131,6 +147,4 @@ public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.Wor
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -39,11 +39,12 @@ import java.util.Date;
|
||||
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.util.DialogUtils;
|
||||
import de.tadris.fitness.util.gpx.GpxExporter;
|
||||
import de.tadris.fitness.util.unit.UnitUtils;
|
||||
import de.tadris.fitness.view.ProgressDialogController;
|
||||
|
||||
public class ShowWorkoutActivity extends WorkoutActivity {
|
||||
public class ShowWorkoutActivity extends WorkoutActivity implements DialogUtils.WorkoutDeleter {
|
||||
|
||||
|
||||
@Override
|
||||
@ -182,17 +183,13 @@ public class ShowWorkoutActivity extends WorkoutActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void deleteWorkout(){
|
||||
public void deleteWorkout(){
|
||||
Instance.getInstance(this).db.workoutDao().deleteWorkout(workout);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void showDeleteDialog(){
|
||||
new AlertDialog.Builder(this).setTitle(R.string.deleteWorkout)
|
||||
.setMessage(R.string.deleteWorkoutMessage)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> deleteWorkout())
|
||||
.create().show();
|
||||
DialogUtils.showDeleteWorkoutDialog(this, this);
|
||||
}
|
||||
|
||||
private void exportToGpx(){
|
||||
|
||||
22
app/src/main/java/de/tadris/fitness/util/DialogUtils.java
Normal file
22
app/src/main/java/de/tadris/fitness/util/DialogUtils.java
Normal file
@ -0,0 +1,22 @@
|
||||
package de.tadris.fitness.util;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
|
||||
import de.tadris.fitness.R;
|
||||
|
||||
public class DialogUtils {
|
||||
|
||||
public static void showDeleteWorkoutDialog(Context context, WorkoutDeleter deleter){
|
||||
new AlertDialog.Builder(context).setTitle(R.string.deleteWorkout)
|
||||
.setMessage(R.string.deleteWorkoutMessage)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> deleter.deleteWorkout())
|
||||
.create().show();
|
||||
}
|
||||
|
||||
public interface WorkoutDeleter{
|
||||
void deleteWorkout();
|
||||
}
|
||||
|
||||
}
|
||||
@ -87,6 +87,10 @@ public class WorkoutAdapter extends RecyclerView.Adapter<WorkoutAdapter.WorkoutV
|
||||
holder.lengthText.setText(UnitUtils.getDistance(workout.length));
|
||||
holder.timeText.setText(UnitUtils.getHourMinuteTime(workout.duration));
|
||||
holder.root.setOnClickListener(v -> listener.onItemClick(workout));
|
||||
holder.root.setOnLongClickListener(v -> {
|
||||
listener.onItemLongClick(position, workout);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
@ -97,6 +101,7 @@ public class WorkoutAdapter extends RecyclerView.Adapter<WorkoutAdapter.WorkoutV
|
||||
|
||||
public interface WorkoutAdapterListener{
|
||||
void onItemClick(Workout workout);
|
||||
void onItemLongClick(int pos, Workout workout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user