Skip to content

Commit

Permalink
W
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisguse committed Nov 19, 2024
1 parent 5ff91a9 commit f2fdd90
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import de.dennisguse.opentracks.ui.customRecordingLayout.CsvLayoutUtils;
import de.dennisguse.opentracks.ui.customRecordingLayout.RecordingLayout;
import de.dennisguse.opentracks.ui.customRecordingLayout.RecordingLayoutIO;
import de.dennisguse.opentracks.util.IntentDashboardUtils;

/**
* Utilities to access preferences stored in {@link SharedPreferences}.
Expand Down Expand Up @@ -860,14 +859,6 @@ 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);
}

public static int getTotalRowsDeleted() {
return getInt(R.string.total_rows_deleted_key, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
import android.widget.Toast;

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 {

Expand All @@ -41,8 +36,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

Preference dynamicColors = findPreference(getString(R.string.settings_ui_dynamic_colors_key));
dynamicColors.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU);

setShowOnMapFormatOptions();
}

@Override
Expand Down Expand Up @@ -79,14 +72,4 @@ public void onDisplayPreferenceDialog(Preference preference) {

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]));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.util.Pair;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.ShareContentProvider;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.tables.MarkerColumns;
import de.dennisguse.opentracks.data.tables.TrackPointsColumns;
import de.dennisguse.opentracks.data.tables.TracksColumns;
import de.dennisguse.opentracks.io.file.TrackFileFormat;
import de.dennisguse.opentracks.settings.PreferencesUtils;

/**
Expand All @@ -39,14 +32,6 @@ public class IntentDashboardUtils {

private static final String ACTION_DASHBOARD_PAYLOAD = ACTION_DASHBOARD + ".Payload";

public static final TrackFileFormat[] SHOW_ON_MAP_TRACK_FILE_FORMATS = new TrackFileFormat[] {
TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES,
TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA,
TrackFileFormat.GPX};

public static final String PREFERENCE_ID_DASHBOARD = ACTION_DASHBOARD;
public static final String PREFERENCE_ID_ASK = "ASK";

/**
* Assume "v1" if not present.
*/
Expand All @@ -73,59 +58,13 @@ private IntentDashboardUtils() {

/**
* Send intent to show tracks on a map (needs an another app) as resource URIs.
* Shows an AlertDialog with different format option if none is defined as preference.
*
* @param context the context
* @param isRecording are we currently recording?
* @param trackIds the track ids
*/
public static void showTrackOnMap(Context context, boolean isRecording, Track.Id... trackIds) {
Map<String, String> options = TrackFileFormat.toPreferenceIdLabelMap(context.getResources(), IntentDashboardUtils.SHOW_ON_MAP_TRACK_FILE_FORMATS);
options.put(IntentDashboardUtils.PREFERENCE_ID_DASHBOARD, context.getString(R.string.show_on_dashboard));
final String[] optionLabels = options.values().toArray(new String[0]);
final String[] optionValues = options.keySet().toArray(new String[0]);
final AtomicInteger checkedItem = new AtomicInteger(NONE_SELECTED);
String preferenceValue = PreferencesUtils.getShowOnMapFormat();
for (int i = 0; i < optionValues.length; i++) {
if (optionValues[i].equals(preferenceValue)) {
checkedItem.set(i);
}
}
if (checkedItem.get() == NONE_SELECTED) {
checkedItem.set(0); // set first option as default
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.select_show_on_map_behavior);
builder.setSingleChoiceItems(optionLabels, checkedItem.get(), (dialog, which) -> checkedItem.set(which));
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> onFormatSelected(context, isRecording, optionValues[checkedItem.get()], trackIds, false));
builder.setNeutralButton(R.string.always, ((dialog, which) -> onFormatSelected(context, isRecording, optionValues[checkedItem.get()], trackIds, true)));
builder.setNegativeButton(android.R.string.cancel, null);

AlertDialog dialog = builder.create();
dialog.show();
} else {
onFormatSelected(context, isRecording, preferenceValue, trackIds, true);
}
}

/**
* A format was selected, remember if <code>always</code> is true and start the necessary action
*
* @param context the context
* @param isRecording are we currently recording?
* @param selectedValue the chosen format
* @param trackIds the track ids
* @param always set the selectedValue as default preference
*/
private static void onFormatSelected(final Context context, final boolean isRecording, final String selectedValue, final Track.Id[] trackIds, final boolean always) {
if (always) {
PreferencesUtils.setShowOnMapFormat(selectedValue);
}
TrackFileFormat trackFileFormat = TrackFileFormat.valueOfPreferenceId(selectedValue);
if (trackFileFormat != null) {
showTrackOnMapWithFileFormat(context, trackFileFormat, Set.of(trackIds));
} else {
startDashboard(context, isRecording, null, null, trackIds);
}
startDashboard(context, isRecording, null, null, trackIds);
}

/**
Expand Down Expand Up @@ -183,28 +122,4 @@ public static void startDashboard(Context context, boolean isRecording, @Nullabl
Toast.makeText(context, R.string.show_on_dashboard_not_installed, Toast.LENGTH_SHORT).show();
}
}

/**
* Send intent to show tracks on a map (needs an another app) to support specific trackFileFormat.
*
* @param context the context
* @param trackFileFormat the track file format
* @param trackIds the track ids
*/
private static void showTrackOnMapWithFileFormat(Context context, TrackFileFormat trackFileFormat, Set<Track.Id> trackIds) {
if (trackIds.isEmpty()) {
return;
}

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackIds, "SharingTrack", trackFileFormat);
intent.setDataAndType(uriAndMime.first, uriAndMime.second);

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

context.startActivity(Intent.createChooser(intent, context.getString(R.string.open_track_as_trackfileformat, trackFileFormat.getExtension())));
}

}
2 changes: 0 additions & 2 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
<string name="settings_sensor_heart_rate_max_key" translatable="false">maxHeartRate</string>
<string name="settings_sensor_heart_rate_max_default" translatable="false">220</string>

<string name="show_on_map_format_key" translatable="false">showOnMapFormatKey</string>

<string name="total_rows_deleted_key" translatable="false">totalRowsDeletedKey</string>

<string name="settings_default_export_directory_key" translatable="false">settingsDefaultExportDirectory</string>
Expand Down
2 changes: 0 additions & 2 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,6 @@ limitations under the License.
<string name="error_crash_title">%1$s crashed</string>
<string name="share_crash_report">Share crash report</string>
<string name="report_bug">Report bug</string>
<string name="select_show_on_map_behavior">Select \"show on map\" behavior</string>
<string name="show_on_map_format_ask">Ask</string>
<string name="show_on_dashboard">OpenTracks Dashboard API</string>
<string name="show_on_dashboard_not_installed">No application supporting OpenTracks Dashboard API installed.</string>
<string name="always">Always</string>
Expand Down
6 changes: 0 additions & 6 deletions src/main/res/xml/settings_user_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
android:summary="@string/settings_ui_dynamic_colors_summary"
android:title="@string/settings_ui_dynamic_colors_title" />

<ListPreference
android:defaultValue="@string/show_on_map_format_ask"
android:key="@string/show_on_map_format_key"
android:title="@string/select_show_on_map_behavior"
app:useSimpleSummaryProvider="true" />

<PreferenceCategory app:title="@string/settings_recording_title">

<Preference
Expand Down

0 comments on commit f2fdd90

Please sign in to comment.