Merge pull request #7663 from jensMF/folder_per_day

Added option to save gpx files in daily folders fixes #6831 and #7514
This commit is contained in:
Denis Kolomiets 2019-10-21 17:44:44 +03:00 committed by GitHub
commit 518f0329a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 25 deletions

View file

@ -2460,8 +2460,13 @@ Abgedeckte Fläche: %1$s x %2$s</string>
<string name="max_min">max/min</string>
<string name="shared_string_reset">Zurücksetzen</string>
<string name="ascent_descent">Aufstieg/Abstieg</string>
<string name="track_storage_directory">Track Speicherort</string>
<string name="track_storage_directory_descrp">Tracks können im Rec Ordner oder in Monats- bzw. Tagesordnern gespeichert werden.</string>
<string name="store_tracks_in_rec_directory">Aufgezeichnete Tracks im Rec Ordner speichern</string>
<string name="store_tracks_in_monthly_directories">Aufgezeichnete Tracks in Monatsordnern speichern</string>
<string name="store_tracks_in_monthly_directories_descrp">Aufgezeichnete Tracks in nach Aufzeichnungsmonat benannten Unterordnern speichern (z. B. 2018-01).</string>
<string name="store_tracks_in_daily_directories">Aufgezeichnete Tracks in Tagesordnern speichern</string>
<string name="store_tracks_in_daily_directories_descrp">Aufgezeichnete Tracks in nach Aufzeichnungstag benannten Unterordnern speichern (z. B. 2018-01).</string>
<string name="map_widget_ruler_control">Zirkel</string>
<string name="of">%1$d von %2$d</string>
<string name="moving_time">Zeit in Bewegung</string>

View file

@ -11,6 +11,12 @@
Thx - Hardy
-->
<string name="track_storage_directory">Track Storage Directory</string>
<string name="track_storage_directory_descrp">Tracks can be stored in rec folder or in monthly or daily folders.</string>
<string name="store_tracks_in_rec_directory">Store recorded tracks in rec folder</string>
<string name="store_tracks_in_daily_directories">Store recorded tracks in daily folders</string>
<string name="store_tracks_in_daily_directories_descrp">Store recorded tracks in sub-folders per recording day (like 2018-01-01).</string>
<string name="shared_string_calculate">Calculate</string>
<string name="shared_string_osmand_usage">OsmAnd Usage</string>
<string name="shared_sting_tiles">Tiles</string>

View file

@ -1494,9 +1494,13 @@ public class OsmandSettings {
SAVE_TRACK_TO_GPX.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false);
}
public static final Integer REC_DIRECTORY = 0;
public static final Integer MONTHLY_DIRECTORY = 1;
public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeGlobal();
public final CommonPreference<Boolean> STORE_TRACKS_IN_MONTHLY_DIRECTORIES = new BooleanPreference("store_tracks_in_monthly_directories", false).makeGlobal();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();

View file

@ -186,7 +186,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
return false;
}
/**
* @return warnings, filenames
*/
@ -204,23 +204,25 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
File fout = new File(dir, f + ".gpx"); //$NON-NLS-1$
if (!data.get(f).isEmpty()) {
WptPt pt = data.get(f).findPointToShow();
File targetDir = dir;
if (ctx.getSettings().STORE_TRACKS_IN_MONTHLY_DIRECTORIES.get()) {
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
Integer track_storage_directory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get();
if (track_storage_directory != OsmandSettings.REC_DIRECTORY) {
SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM");
if (track_storage_directory == OsmandSettings.DAILY_DIRECTORY) {
dateDirFormat = new SimpleDateFormat("yyyy-MM-dd");
}
String dateDirName = dateDirFormat.format(new Date(pt.time));
File dateDir = new File(dir, dateDirName);
dateDir.mkdirs();
if (dateDir.exists()) {
targetDir = dateDir;
fileName = dateDirName + File.separator + fileName;
}
}
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
filenames.add(fileName);
fout = new File(targetDir, fileName + ".gpx"); //$NON-NLS-1$
fout = new File(dir, fileName + ".gpx"); //$NON-NLS-1$
int ind = 1;
while (fout.exists()) {
fout = new File(targetDir, fileName + "_" + (++ind) + ".gpx"); //$NON-NLS-1$ //$NON-NLS-2$
fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -42,7 +42,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
dismiss();
}
final File f = new File (app.getAppCustomization().getTracksDir() +"/"+ savedGpxName + ".gpx");
final File f = new File (app.getAppCustomization().getTracksDir(), savedGpxName + ".gpx");
final boolean nightMode = !app.getSettings().isLightContent();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
View mainView = View

View file

@ -16,17 +16,21 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.view.Window;
import static net.osmand.plus.OsmandSettings.DAILY_DIRECTORY;
import static net.osmand.plus.OsmandSettings.MONTHLY_DIRECTORY;
import static net.osmand.plus.OsmandSettings.REC_DIRECTORY;
public class SettingsMonitoringActivity extends SettingsBaseActivity {
private CheckBoxPreference routeServiceEnabled;
private BroadcastReceiver broadcastReceiver;
public static final int[] BG_SECONDS = new int[]{0, 30, 60, 90};
public static final int[] BG_MINUTES = new int[]{2, 3, 5, 10, 15, 30, 60, 90};
private static final int[] SECONDS = OsmandMonitoringPlugin.SECONDS;
private static final int[] MINUTES = OsmandMonitoringPlugin.MINUTES;
private static final int[] MAX_INTERVAL_TO_SEND_MINUTES = OsmandMonitoringPlugin.MAX_INTERVAL_TO_SEND_MINUTES;
public SettingsMonitoringActivity() {
super(true);
}
@ -39,7 +43,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
setProgressVisibility(false);
getToolbar().setTitle(R.string.monitoring_settings);
PreferenceScreen grp = getPreferenceScreen();
createLoggingSection(grp);
createLiveSection(grp);
createNotificationSection(grp);
@ -87,15 +91,15 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
R.string.save_track_to_gpx_descrp));
cat.addPreference(createTimeListPreference(settings.SAVE_TRACK_INTERVAL, SECONDS,
MINUTES, 1000, R.string.save_track_interval, R.string.save_track_interval_descr));
String[] names;
String[] names;
Float[] floatValues;
floatValues = new Float[] {0.f, 2.0f, 5.0f, 10.0f, 20.0f, 30.0f, 50.0f};
names = new String[floatValues.length];
names[0] = getString(R.string.shared_string_not_selected);
for(int i = 1; i < floatValues.length; i++) {
names[i] = floatValues[i].intValue() + " " + getString(R.string.m);
names[i] = floatValues[i].intValue() + " " + getString(R.string.m);
}
cat.addPreference(createListPreference(settings.SAVE_TRACK_MIN_DISTANCE, names, floatValues,
cat.addPreference(createListPreference(settings.SAVE_TRACK_MIN_DISTANCE, names, floatValues,
R.string.save_track_min_distance, R.string.save_track_min_distance_descr));
floatValues = new Float[] {0.f, 1.0f, 2.0f, 5.0f, 10.0f, 15.0f, 20.0f, 50.0f, 100.0f};
names = new String[floatValues.length];
@ -103,7 +107,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
for(int i = 1; i < floatValues.length; i++) {
names[i] = floatValues[i].intValue() + " " + getString(R.string.m) + " (" + Math.round(floatValues[i]/0.3048f) + " " + getString(R.string.foot) + ")";
}
cat.addPreference(createListPreference(settings.SAVE_TRACK_PRECISION, names, floatValues,
cat.addPreference(createListPreference(settings.SAVE_TRACK_PRECISION, names, floatValues,
R.string.save_track_precision, R.string.save_track_precision_descr));
floatValues = new Float[] {0.f, 0.000001f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f};
names = new String[floatValues.length];
@ -113,14 +117,20 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
names[i] = floatValues[i].intValue() + " " + getString(R.string.km_h);
floatValues[i] = floatValues[i] / 3.6f;
}
cat.addPreference(createListPreference(settings.SAVE_TRACK_MIN_SPEED, names, floatValues,
cat.addPreference(createListPreference(settings.SAVE_TRACK_MIN_SPEED, names, floatValues,
R.string.save_track_min_speed, R.string.save_track_min_speed_descr));
cat.addPreference(createCheckBoxPreference(settings.AUTO_SPLIT_RECORDING, R.string.auto_split_recording_title,
R.string.auto_split_recording_descr));
cat.addPreference(createCheckBoxPreference(settings.DISABLE_RECORDING_ONCE_APP_KILLED, R.string.disable_recording_once_app_killed,
R.string.disable_recording_once_app_killed_descrp));
cat.addPreference(createCheckBoxPreference(settings.STORE_TRACKS_IN_MONTHLY_DIRECTORIES, R.string.store_tracks_in_monthly_directories,
R.string.store_tracks_in_monthly_directories_descrp));
Integer[] intValues = new Integer[]{REC_DIRECTORY, MONTHLY_DIRECTORY, DAILY_DIRECTORY};
names = new String[intValues.length];
names[0] = getString(R.string.store_tracks_in_rec_directory);
names[1] = getString(R.string.store_tracks_in_monthly_directories);
names[2] = getString(R.string.store_tracks_in_daily_directories);
cat.addPreference(createListPreference(settings.TRACK_STORAGE_DIRECTORY, names, intValues,
R.string.track_storage_directory, R.string.track_storage_directory_descrp));
}
@ -129,7 +139,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
cat = new PreferenceCategory(this);
cat.setTitle(R.string.live_monitoring_m);
grp.addPreference(cat);
cat.addPreference(createEditTextPreference(settings.LIVE_MONITORING_URL, R.string.live_monitoring_url,
R.string.live_monitoring_url_descr));
final CheckBoxPreference liveMonitoring = createCheckBoxPreference(settings.LIVE_MONITORING, R.string.live_monitoring_m,
@ -154,12 +164,12 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
public void updateAllSettings() {
super.updateAllSettings();
if(routeServiceEnabled != null) {
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
}
}
private void saveCurrentTracks(final SavingTrackHelper helper) {
setProgressVisibility(true);
getMyApplication().getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, Void>() {
@ -178,7 +188,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
}, (Void) null);
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -187,7 +197,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
broadcastReceiver = null;
}
}