fix another way to show the bottom sheet with renaming and opening current track after clicking "Save and stop recording";

fix showing correct track save time;
fix now after clicking the "Stop.." buttons, the track recording fragment does not open
This commit is contained in:
Skalii 2021-02-10 17:21:01 +02:00
parent c36d007b5c
commit 6adbcd5ff6
4 changed files with 34 additions and 45 deletions

View file

@ -78,6 +78,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private SelectedGpxFile currentTrack; private SelectedGpxFile currentTrack;
private int points; private int points;
private int trkPoints = 0; private int trkPoints = 0;
public long time;
public SavingTrackHelper(OsmandApplication ctx) { public SavingTrackHelper(OsmandApplication ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION); super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
@ -255,6 +256,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified()); GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
GpxDataItem item = new GpxDataItem(fout, analysis); GpxDataItem item = new GpxDataItem(fout, analysis);
ctx.getGpxDbHelper().add(item); ctx.getGpxDbHelper().add(item);
time = fout.lastModified();
} }
} }
} }

View file

@ -1,24 +1,21 @@
package net.osmand.plus.monitoring; package net.osmand.plus.monitoring;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.myplaces.SaveCurrentTrackTask;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.TextViewEx;
import androidx.annotation.DimenRes; import androidx.annotation.DimenRes;
@ -34,17 +31,13 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
public static final String TAG = StopTrackRecordingBottomFragment.class.getSimpleName(); public static final String TAG = StopTrackRecordingBottomFragment.class.getSimpleName();
private OsmandApplication app; private OsmandApplication app;
private MapActivity mapActivity;
private OsmandSettings settings; private OsmandSettings settings;
private OsmandMonitoringPlugin plugin; private OsmandMonitoringPlugin plugin;
private GPXFile gpxFile; private ButtonType tag = ButtonType.CANCEL;
private SaveGpxListener saveGpxListener;
public void setGpxFile(GPXFile gpxFile) { public void setMapActivity(MapActivity mapActivity) {
this.gpxFile = gpxFile; this.mapActivity = mapActivity;
}
public void setSaveGpxListener(SaveGpxListener saveGpxListener) {
this.saveGpxListener = saveGpxListener;
} }
@Override @Override
@ -122,7 +115,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
return; return;
} }
ButtonType tag = (ButtonType) o; tag = (ButtonType) o;
if (tag == ButtonType.STOP_AND_DISCARD) { if (tag == ButtonType.STOP_AND_DISCARD) {
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.stopRecording(); plugin.stopRecording();
@ -131,8 +124,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
app.getSavingTrackHelper().clearRecordedData(true); app.getSavingTrackHelper().clearRecordedData(true);
} else if (tag == ButtonType.SAVE_AND_STOP) { } else if (tag == ButtonType.SAVE_AND_STOP) {
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
new SaveCurrentTrackTask(app, gpxFile, saveGpxListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); plugin.saveCurrentTrack(null, mapActivity);
plugin.stopRecording();
app.getNotificationHelper().refreshNotifications(); app.getNotificationHelper().refreshNotifications();
} }
} }
@ -151,11 +143,13 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (tag == ButtonType.CANCEL) {
Fragment target = getTargetFragment(); Fragment target = getTargetFragment();
if (target instanceof TripRecordingActiveBottomSheet) { if (target instanceof TripRecordingActiveBottomSheet) {
((TripRecordingActiveBottomSheet) target).show(); ((TripRecordingActiveBottomSheet) target).show();
} }
} }
}
enum ButtonType { enum ButtonType {
STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop, R.dimen.dialog_content_margin, DialogButtonType.SECONDARY_HARMFUL), STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop, R.dimen.dialog_content_margin, DialogButtonType.SECONDARY_HARMFUL),
@ -183,11 +177,10 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
return true; return true;
} }
public static void showInstance(GPXFile gpxFile, SaveGpxListener saveGpxListener, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) { public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) { if (!fragmentManager.isStateSaved()) {
StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment(); StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
fragment.setGpxFile(gpxFile); fragment.setMapActivity(mapActivity);
fragment.setSaveGpxListener(saveGpxListener);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
} }

View file

@ -62,11 +62,6 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT; import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
@ -261,8 +256,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (fragmentManager != null) { if (fragmentManager != null) {
final GPXFile gpxFile = getGPXFile(); StopTrackRecordingBottomFragment.showInstance(getMapActivity(), fragmentManager, TripRecordingActiveBottomSheet.this);
StopTrackRecordingBottomFragment.showInstance(gpxFile, createSaveListener(), fragmentManager, TripRecordingActiveBottomSheet.this);
} }
} }
}); });
@ -311,20 +305,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
} }
private String getTimeTrackSaved() { private String getTimeTrackSaved() {
long timeTrackSaved = helper.getLastTimeUpdated(); if (helper.time != 0) {
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z", Locale.getDefault()); long timeTrackSaved = helper.time;
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date resultDate = new Date(timeTrackSaved);
String sdfFormatted = sdf.format(resultDate);
CharSequence formattedTimeTrackSaved = null;
try {
long time = sdf.parse(sdfFormatted).getTime();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
formattedTimeTrackSaved = DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS); CharSequence time = DateUtils.getRelativeTimeSpanString(timeTrackSaved, now, DateUtils.MINUTE_IN_MILLIS);
} catch (ParseException e) { return String.valueOf(time);
log.error(e); } else {
return null;
} }
return String.valueOf(formattedTimeTrackSaved);
} }
@Override @Override
@ -406,7 +394,8 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
View view = snackbar.getView(); View view = snackbar.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.gravity = Gravity.TOP; params.gravity = Gravity.TOP;
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context), 0, 0); final int dp16 = AndroidUtils.dpToPx(mapActivity, 16f);
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context) + dp16, 0, 0);
view.setLayoutParams(params); view.setLayoutParams(params);
UiUtilities.setupSnackbar(snackbar, nightMode); UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show(); snackbar.show();
@ -438,26 +427,30 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
} }
} }
private static void setItemBackgroundActive(LinearLayout view, Context context, boolean nightMode) { private static void setItemBackgroundActive(LinearLayout view, Context context,
boolean nightMode) {
Drawable background = AppCompatResources.getDrawable(context, Drawable background = AppCompatResources.getDrawable(context,
nightMode ? R.drawable.btn_background_active_dark : R.drawable.btn_background_active_light); nightMode ? R.drawable.btn_background_active_dark : R.drawable.btn_background_active_light);
view.setBackgroundDrawable(background); view.setBackgroundDrawable(background);
} }
private static void setItemBackgroundInactive(LinearLayout view, Context context, boolean nightMode) { private static void setItemBackgroundInactive(LinearLayout view, Context context,
boolean nightMode) {
Drawable background = AppCompatResources.getDrawable(context, Drawable background = AppCompatResources.getDrawable(context,
nightMode ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_inactive_light); nightMode ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_inactive_light);
view.setBackgroundDrawable(background); view.setBackgroundDrawable(background);
} }
private static void setShowOnMapBackgroundActive(LinearLayout view, Context context, boolean checked, boolean nightMode) { private static void setShowOnMapBackgroundActive(LinearLayout view, Context context,
boolean checked, boolean nightMode) {
Drawable background = AppCompatResources.getDrawable(context, Drawable background = AppCompatResources.getDrawable(context,
nightMode ? checked ? R.drawable.btn_background_active_dark : R.drawable.btn_background_stroked_active_dark nightMode ? checked ? R.drawable.btn_background_active_dark : R.drawable.btn_background_stroked_active_dark
: checked ? R.drawable.btn_background_active_light : R.drawable.btn_background_stroked_active_light); : checked ? R.drawable.btn_background_active_light : R.drawable.btn_background_stroked_active_light);
view.setBackgroundDrawable(background); view.setBackgroundDrawable(background);
} }
private static void setShowOnMapBackgroundInactive(LinearLayout view, Context context, boolean checked, boolean nightMode) { private static void setShowOnMapBackgroundInactive(LinearLayout view, Context context,
boolean checked, boolean nightMode) {
Drawable background = AppCompatResources.getDrawable(context, Drawable background = AppCompatResources.getDrawable(context,
nightMode ? checked ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_stroked_inactive_dark nightMode ? checked ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_stroked_inactive_dark
: checked ? R.drawable.btn_background_inactive_light : R.drawable.btn_background_stroked_inactive_light); : checked ? R.drawable.btn_background_inactive_light : R.drawable.btn_background_stroked_inactive_light);

View file

@ -52,6 +52,7 @@ public class SaveCurrentTrackTask extends AsyncTask<Void, Void, Boolean> {
for (final String f : files.keySet()) { for (final String f : files.keySet()) {
File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT); File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
GPXUtilities.writeGpxFile(fout, gpx); GPXUtilities.writeGpxFile(fout, gpx);
app.getSavingTrackHelper().time = fout.lastModified();
} }
return shouldClearPath; return shouldClearPath;
} }