added ability to delete a recording

This commit is contained in:
y20k 2017-08-21 11:48:17 +02:00
parent ae2d261bfe
commit 3487792ada
2 changed files with 33 additions and 6 deletions

View file

@ -80,6 +80,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
private DropdownAdapter mDropdownAdapter; private DropdownAdapter mDropdownAdapter;
private LinearLayout mTrackManagementLayout; private LinearLayout mTrackManagementLayout;
private Spinner mDropdown; private Spinner mDropdown;
private View mStatisticsSheet;
private TextView mDistanceView; private TextView mDistanceView;
private TextView mStepsView; private TextView mStepsView;
private TextView mWaypointsView; private TextView mWaypointsView;
@ -188,7 +189,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
// get views for statistics sheet // get views for statistics sheet
View statisticsView = mRootView.findViewById(R.id.statistics_view); View statisticsView = mRootView.findViewById(R.id.statistics_view);
View statisticsSheet = mRootView.findViewById(R.id.statistics_sheet); mStatisticsSheet = mRootView.findViewById(R.id.statistics_sheet);
mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance); mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance);
mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps); mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints); mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints);
@ -211,7 +212,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
} }
// set up and show statistics sheet // set up and show statistics sheet
mStatisticsSheetBehavior = BottomSheetBehavior.from(statisticsSheet); mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mStatisticsSheetBehavior.setBottomSheetCallback(getStatisticsSheetCallback()); mStatisticsSheetBehavior.setBottomSheetCallback(getStatisticsSheetCallback());
statisticsView.setOnClickListener(new View.OnClickListener() { statisticsView.setOnClickListener(new View.OnClickListener() {
@ -304,7 +305,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
switch(requestCode) { switch(requestCode) {
case RESULT_DELETE_DIALOG: case RESULT_DELETE_DIALOG:
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
LogHelper.v(LOG_TAG, "Delete dialog result: DELETE"); deleteCurrentTrack();
} else if (resultCode == Activity.RESULT_CANCELED){ } else if (resultCode == Activity.RESULT_CANCELED){
LogHelper.v(LOG_TAG, "Delete dialog result: CANCEL"); LogHelper.v(LOG_TAG, "Delete dialog result: CANCEL");
} }
@ -371,18 +372,44 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
// show onboarding layout // show onboarding layout
mMapView.setVisibility(View.GONE); mMapView.setVisibility(View.GONE);
mOnboardingView.setVisibility(View.VISIBLE); mOnboardingView.setVisibility(View.VISIBLE);
mTrackManagementLayout.setVisibility(View.INVISIBLE); mTrackManagementLayout.setVisibility(View.GONE);
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mStatisticsSheet.setVisibility(View.GONE);
} else { } else {
// show normal layout // show normal layout
mOnboardingView.setVisibility(View.GONE); mOnboardingView.setVisibility(View.GONE);
mMapView.setVisibility(View.VISIBLE); mMapView.setVisibility(View.VISIBLE);
mTrackManagementLayout.setVisibility(View.VISIBLE); mTrackManagementLayout.setVisibility(View.VISIBLE);
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mStatisticsSheet.setVisibility(View.VISIBLE);
} }
} }
/* Deletes currently visible track */
private void deleteCurrentTrack() {
// delete track file and refresh dropdown adapter
if (mDropdownAdapter.getItem(mCurrentTrack).getTrackFile().delete()) {
mDropdownAdapter.refresh();
mDropdownAdapter.notifyDataSetChanged();
mDropdown.setAdapter(mDropdownAdapter);
} else {
LogHelper.e(LOG_TAG, "Unable to delete recording.");
}
if (mDropdownAdapter.isEmpty()) {
// show onboarding
switchOnboardingLayout();
} else {
// show next track
mDropdown.setSelection(0, true);
mCurrentTrack = 0;
}
}
/* Creates BottomSheetCallback for the statistics sheet - needed in onCreateView */ /* Creates BottomSheetCallback for the statistics sheet - needed in onCreateView */
private BottomSheetBehavior.BottomSheetCallback getStatisticsSheetCallback() { private BottomSheetBehavior.BottomSheetCallback getStatisticsSheetCallback() {
return new BottomSheetBehavior.BottomSheetCallback() { return new BottomSheetBehavior.BottomSheetCallback() {

View file

@ -52,7 +52,7 @@
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:contentDescription="@string/descr_export_button" /> android:contentDescription="@string/descr_export_button" />
<ImageButton <ImageButton
android:visibility="gone" android:visibility="visible"
android:id="@+id/delete_button" android:id="@+id/delete_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"