From 1acb9fba0512908d46123c7c8155eb2fbab1ffd8 Mon Sep 17 00:00:00 2001 From: mendhak Date: Mon, 20 Dec 2021 12:34:42 +0000 Subject: [PATCH] If OpenStreetMap auto sending is enabled, prompt the user for description and tags before starting logging. --- .../mendhak/gpslogger/GpsMainActivity.java | 27 ++++++++--- .../display/GenericViewFragment.java | 48 ++++++++++++------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java b/gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java index f8d6ee109..f11e565d7 100644 --- a/gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java +++ b/gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java @@ -335,16 +335,31 @@ public boolean onResult(@NonNull String dialogTag, int which, @NonNull Bundle ex return true; } - if(dialogTag.equalsIgnoreCase("customfilename") && which == BUTTON_POSITIVE){ - String enteredText = extras.getString("customfilename"); - String originalFileName = preferenceHelper.getCustomFileName(); + if(dialogTag.equalsIgnoreCase("shouldpromptbeforelogging") && which == BUTTON_POSITIVE){ - if(!originalFileName.equalsIgnoreCase(enteredText)){ - preferenceHelper.setCustomFileName(enteredText); + if(extras.containsKey(PreferenceNames.CUSTOM_FILE_NAME)){ + String chosenFileName = extras.getString(PreferenceNames.CUSTOM_FILE_NAME); + if(!preferenceHelper.getCustomFileName().equalsIgnoreCase(chosenFileName)){ + preferenceHelper.setCustomFileName(chosenFileName); + Files.addItemToCacheFile(chosenFileName, PreferenceNames.CUSTOM_FILE_NAME, GpsMainActivity.this); + } + } + + if(extras.containsKey(PreferenceNames.OPENSTREETMAP_TAGS)){ + String chosenOsmTags = extras.getString(PreferenceNames.OPENSTREETMAP_TAGS); + if(!preferenceHelper.getOSMTags().equalsIgnoreCase(chosenOsmTags)){ + preferenceHelper.setOSMTags(chosenOsmTags); + } + } + + if(extras.containsKey(PreferenceNames.OPENSTREETMAP_DESCRIPTION)){ + String chosenOsmDescription = extras.getString(PreferenceNames.OPENSTREETMAP_DESCRIPTION); + if(!preferenceHelper.getOSMDescription().equalsIgnoreCase(chosenOsmDescription)){ + preferenceHelper.setOSMDescription(chosenOsmDescription); + } } getCurrentFragment().toggleLogging(); - Files.addItemToCacheFile(enteredText, "customfilename", GpsMainActivity.this); return true; } diff --git a/gpslogger/src/main/java/com/mendhak/gpslogger/ui/fragments/display/GenericViewFragment.java b/gpslogger/src/main/java/com/mendhak/gpslogger/ui/fragments/display/GenericViewFragment.java index ff6f8c223..051fc2932 100644 --- a/gpslogger/src/main/java/com/mendhak/gpslogger/ui/fragments/display/GenericViewFragment.java +++ b/gpslogger/src/main/java/com/mendhak/gpslogger/ui/fragments/display/GenericViewFragment.java @@ -23,11 +23,11 @@ import android.os.Bundle; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import com.mendhak.gpslogger.GpsLoggingService; import com.mendhak.gpslogger.R; import com.mendhak.gpslogger.common.EventBusHook; import com.mendhak.gpslogger.common.PreferenceHelper; +import com.mendhak.gpslogger.common.PreferenceNames; import com.mendhak.gpslogger.common.Session; import com.mendhak.gpslogger.common.Systems; import com.mendhak.gpslogger.common.events.CommandEvents; @@ -37,6 +37,7 @@ import com.mendhak.gpslogger.ui.Dialogs; import de.greenrobot.event.EventBus; import eltos.simpledialogfragment.SimpleDialog; +import eltos.simpledialogfragment.form.FormElement; import eltos.simpledialogfragment.form.Hint; import eltos.simpledialogfragment.form.Input; import eltos.simpledialogfragment.form.SimpleFormDialog; @@ -112,26 +113,41 @@ public void requestToggleLogging() { return; } + ArrayList formElements = new ArrayList<>(); + + //If the user needs to be prompted about custom file name, build some form elements for it. if (preferenceHelper.shouldCreateCustomFile() && preferenceHelper.shouldAskCustomFileNameEachTime()) { + formElements.add(Hint.plain(R.string.new_file_custom_title)); + formElements.add(Hint.plain(R.string.new_file_custom_message)); + + final List cachedList = Files.getListFromCacheFile(PreferenceNames.CUSTOM_FILE_NAME, getActivity()); + formElements.add(Input.plain(PreferenceNames.CUSTOM_FILE_NAME) + .suggest(new ArrayList<>(cachedList)) + .text(preferenceHelper.getCustomFileName())); + + } - //Result handled in GPSMainactivity onResult. - //Dialogs.autoSuggestDialog( (FragmentActivity) getActivity(),"customfilename", getString(R.string.new_file_custom_title), "", preferenceHelper.getCustomFileName()); + //If the user needs to be prompted about OpenStreetMap settings, build some form elements for it. + if(preferenceHelper.isAutoSendEnabled() && preferenceHelper.isOsmAutoSendEnabled()){ + formElements.add(Hint.plain(R.string.osm_setup_title)); + formElements.add(Input.plain(PreferenceNames.OPENSTREETMAP_DESCRIPTION) + .hint(getString(R.string.osm_description)) + .text(preferenceHelper.getOSMDescription())); + formElements.add(Input.plain(PreferenceNames.OPENSTREETMAP_TAGS) + .hint(R.string.osm_tags) + .text(preferenceHelper.getOSMTags())); + } - final List cachedList = Files.getListFromCacheFile("customfilename", getActivity()); + //If the user needs to be prompted about any of the above, it's time to show a dialog + //The result is handled in GPSMainactivity onResult. + if(formElements.size() > 0){ SimpleFormDialog.build() - .fields( - Hint.plain(R.string.new_file_custom_title), - Hint.plain(R.string.new_file_custom_message), - Input.plain("customfilename") - .suggest(new ArrayList<>(cachedList)) - .text(preferenceHelper.getCustomFileName()) - - ) - //.title(getString(R.string.new_file_custom_title)) - .show(getActivity(), "customfilename"); - - } else { + .fields(formElements.toArray(new FormElement[0])) + .show(getActivity(), "shouldpromptbeforelogging"); + } + //Else it's just normal logging. + else { if(!session.isStarted()){ Intent serviceIntent = new Intent(getActivity().getApplicationContext(), GpsLoggingService.class); ContextCompat.startForegroundService(getActivity().getApplicationContext(), serviceIntent);