Add "show on map" format selection dialog

This commit is contained in:
Peter Storch
2022-05-26 13:58:01 +02:00
parent 6c0033c107
commit 1108684d06
14 changed files with 165 additions and 123 deletions
@@ -9,7 +9,7 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import java.util.Locale;
import java.util.Map;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.io.file.TrackFileFormat;
@@ -46,27 +46,15 @@ public class ImportExportSettingsFragment extends PreferenceFragmentCompat {
}
private void setExportTrackFileFormatOptions() {
final TrackFileFormat[] trackFileFormats = {
Map<String, String> options = TrackFileFormat.toPreferenceIdLabelMap(getResources(),
TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES,
TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA,
TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA,
TrackFileFormat.GPX,
TrackFileFormat.CSV
};
String[] entries = new String[trackFileFormats.length];
String[] entryValues = new String[trackFileFormats.length];
for (int i = 0; i < entries.length; i++) {
TrackFileFormat trackFileFormat = trackFileFormats[i];
String trackFileFormatUpperCase = trackFileFormat.getExtension().toUpperCase(Locale.US); //ASCII upper case
int photoMessageId = trackFileFormat.includesPhotos() ? R.string.export_with_photos : R.string.export_without_photos;
entries[i] = String.format("%s (%s)", trackFileFormatUpperCase, getString(photoMessageId));
entryValues[i] = trackFileFormat.getPreferenceId();
}
TrackFileFormat.CSV);
ListPreference listPreference = findPreference(getString(R.string.export_trackfileformat_key));
listPreference.setEntries(entries);
listPreference.setEntryValues(entryValues);
listPreference.setEntries(options.values().toArray(new String[0]));
listPreference.setEntryValues(options.keySet().toArray(new String[0]));
}
private void setExportDirectorySummary() {
@@ -47,6 +47,7 @@ import de.dennisguse.opentracks.io.file.TrackFileFormat;
import de.dennisguse.opentracks.io.file.TrackFilenameGenerator;
import de.dennisguse.opentracks.ui.customRecordingLayout.CsvLayoutUtils;
import de.dennisguse.opentracks.ui.customRecordingLayout.Layout;
import de.dennisguse.opentracks.util.IntentDashboardUtils;
import de.dennisguse.opentracks.util.TrackIconUtils;
/**
@@ -761,4 +762,13 @@ public class PreferencesUtils {
public static void clear() {
sharedPreferences.edit().clear().commit();
}
public static void setShowOnMapFormat(final String showOnMapFormat) {
setString(R.string.show_on_map_format_key, showOnMapFormat);
}
public static String getShowOnMapFormat() {
return getString(R.string.show_on_map_format_key, IntentDashboardUtils.PREFERENCE_ID_ASK);
}
}
@@ -5,10 +5,15 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import java.util.Map;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.io.file.TrackFileFormat;
import de.dennisguse.opentracks.util.IntentDashboardUtils;
public class UserInterfaceSettingsFragment extends PreferenceFragmentCompat {
@@ -28,6 +33,8 @@ public class UserInterfaceSettingsFragment extends PreferenceFragmentCompat {
startActivity(intent);
return true;
});
setShowOnMapFormatOptions();
}
@Override
@@ -64,4 +71,14 @@ public class UserInterfaceSettingsFragment extends PreferenceFragmentCompat {
super.onDisplayPreferenceDialog(preference);
}
private void setShowOnMapFormatOptions() {
Map<String, String> options = TrackFileFormat.toPreferenceIdLabelMap(getResources(), IntentDashboardUtils.SHOW_ON_MAP_TRACK_FILE_FORMATS);
options.put(IntentDashboardUtils.PREFERENCE_ID_DASHBOARD, getString(R.string.show_on_dashboard));
options.put(IntentDashboardUtils.PREFERENCE_ID_ASK, getString(R.string.show_on_map_format_ask));
ListPreference listPreference = findPreference(getString(R.string.show_on_map_format_key));
listPreference.setEntries(options.values().toArray(new String[0]));
listPreference.setEntryValues(options.keySet().toArray(new String[0]));
}
}