Skip to content

Commit

Permalink
If OpenStreetMap auto sending is enabled, prompt the user for descrip…
Browse files Browse the repository at this point in the history
…tion and tags before starting logging.
  • Loading branch information
mendhak committed Dec 20, 2021
1 parent 8b19111 commit 1acb9fb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
27 changes: 21 additions & 6 deletions gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -112,26 +113,41 @@ public void requestToggleLogging() {
return;
}

ArrayList<FormElement> 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<String> 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<String> 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);
Expand Down

0 comments on commit 1acb9fb

Please sign in to comment.