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

View file

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

View file

@ -62,11 +62,6 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
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;
@ -261,8 +256,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void onClick(View v) {
if (fragmentManager != null) {
final GPXFile gpxFile = getGPXFile();
StopTrackRecordingBottomFragment.showInstance(gpxFile, createSaveListener(), fragmentManager, TripRecordingActiveBottomSheet.this);
StopTrackRecordingBottomFragment.showInstance(getMapActivity(), fragmentManager, TripRecordingActiveBottomSheet.this);
}
}
});
@ -311,20 +305,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
private String getTimeTrackSaved() {
long timeTrackSaved = helper.getLastTimeUpdated();
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z", Locale.getDefault());
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();
if (helper.time != 0) {
long timeTrackSaved = helper.time;
long now = System.currentTimeMillis();
formattedTimeTrackSaved = DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS);
} catch (ParseException e) {
log.error(e);
CharSequence time = DateUtils.getRelativeTimeSpanString(timeTrackSaved, now, DateUtils.MINUTE_IN_MILLIS);
return String.valueOf(time);
} else {
return null;
}
return String.valueOf(formattedTimeTrackSaved);
}
@Override
@ -406,7 +394,8 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
View view = snackbar.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
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);
UiUtilities.setupSnackbar(snackbar, nightMode);
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,
nightMode ? R.drawable.btn_background_active_dark : R.drawable.btn_background_active_light);
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,
nightMode ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_inactive_light);
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,
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);
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,
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);

View file

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