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

@ -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,6 +16,10 @@ 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;
@ -119,8 +123,14 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
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));
}