Configure profile as service when changing profile settings

When trying to change settings for a profile that was not yet
configured as a service in the android app, the app exits instead of
configuring the profile. This behavior is not very intuitive for users.

This change instead adds a dialog to configure the profile as a new
service in case `Profile Settings` is selected and the selected profile
is not yet configured as a service.
This commit is contained in:
Jan Schopohl 2024-08-31 13:44:42 +02:00
parent e63cc9888f
commit e18e2a16f4
13 changed files with 31 additions and 34 deletions

View File

@ -78,6 +78,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
private String title; private String title;
private int wpCount; private int wpCount;
private boolean startSilent; private boolean startSilent;
private String configuredParams = null;
ActivityResultLauncher<Intent> someActivityResultLauncher; ActivityResultLauncher<Intent> someActivityResultLauncher;
@ -108,7 +109,12 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
if (data != null && data.hasExtra("PROFILE_HASH")) { if (data != null && data.hasExtra("PROFILE_HASH")) {
profile_hash = data.getExtras().getString("PROFILE_HASH", ""); profile_hash = data.getExtras().getString("PROFILE_HASH", "");
} }
mBRouterView.configureServiceParams(profile, sparams);
if (mBRouterView.getConfigureServiceParams(profile) == null) {
mBRouterView.startConfigureService(sparams);
} else {
mBRouterView.configureServiceParams(profile, sparams);
}
} }
} }
@ -203,6 +209,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
return builder.create(); return builder.create();
*/ */
case DIALOG_ROUTINGMODES_ID: case DIALOG_ROUTINGMODES_ID:
String configuredParams = this.configuredParams;
builder.setTitle(message); builder.setTitle(message);
builder.setMultiChoiceItems(routingModes, routingModesChecked, builder.setMultiChoiceItems(routingModes, routingModesChecked,
new DialogInterface.OnMultiChoiceClickListener() { new DialogInterface.OnMultiChoiceClickListener() {
@ -213,7 +220,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
}); });
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
mBRouterView.configureService(routingModes, routingModesChecked); mBRouterView.configureService(routingModes, routingModesChecked, configuredParams);
} }
}); });
return builder.create(); return builder.create();
@ -345,7 +352,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
public void onClick(DialogInterface dialog, int item) { public void onClick(DialogInterface dialog, int item) {
if (slist.size() > 1 && item == 0) { if (slist.size() > 1 && item == 0) {
if (wpCount == 0) { if (wpCount == 0) {
mBRouterView.startConfigureService(); mBRouterView.startConfigureService(null);
} else if (wpCount == -3) { } else if (wpCount == -3) {
showRepeatTimeoutHelp(); showRepeatTimeoutHelp();
} else if (wpCount >= 2) { } else if (wpCount >= 2) {
@ -456,21 +463,20 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
} }
String sparams = mBRouterView.getConfigureServiceParams(selectedProfile); String sparams = mBRouterView.getConfigureServiceParams(selectedProfile);
if (sparams != null) { if (sparams == null) {
if (listParams.size() > 0) { // profile is not used yet
Intent i = new Intent(BRouterActivity.this, RoutingParameterDialog.class); sparams = "";
i.putExtra("PROFILE", selectedProfile); }
i.putExtra("PROFILE_HASH", String.format("B%X", profile.getAbsolutePath().hashCode())); if (listParams.size() > 0) {
i.putExtra("PARAMS", (Serializable) listParams); Intent i = new Intent(BRouterActivity.this, RoutingParameterDialog.class);
i.putExtra("PARAMS_VALUES", sparams); i.putExtra("PROFILE", selectedProfile);
//startActivityForResult(i, 100); i.putExtra("PROFILE_HASH", String.format("B%X", profile.getAbsolutePath().hashCode()));
someActivityResultLauncher.launch(i); i.putExtra("PARAMS", (Serializable) listParams);
} else { i.putExtra("PARAMS_VALUES", sparams);
Toast.makeText(this, R.string.msg_no_profile, Toast.LENGTH_LONG).show(); //startActivityForResult(i, 100);
finish(); someActivityResultLauncher.launch(i);
}
} else { } else {
Toast.makeText(this, selectedProfile + getString(R.string.msg_no_used_profile), Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.msg_no_profile, Toast.LENGTH_LONG).show();
finish(); finish();
} }
} }
@ -539,10 +545,11 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
} }
} }
public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) { public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message, String sparams) {
routingModes = modes; routingModes = modes;
routingModesChecked = modesChecked; routingModesChecked = modesChecked;
this.message = message; this.message = message;
this.configuredParams = sparams;
showADialog(DIALOG_ROUTINGMODES_ID); showADialog(DIALOG_ROUTINGMODES_ID);
} }
@ -666,7 +673,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
private void onItemClick(AdapterView<?> adapterView, View view, int which, long l) { private void onItemClick(AdapterView<?> adapterView, View view, int which, long l) {
if (which == 0) { if (which == 0) {
if (wpCount == 0) { if (wpCount == 0) {
mBRouterView.startConfigureService(); mBRouterView.startConfigureService(null);
} else if (wpCount == -3) { } else if (wpCount == -3) {
showRepeatTimeoutHelp(); showRepeatTimeoutHelp();
} else if (wpCount >= 2) { } else if (wpCount >= 2) {

View File

@ -817,17 +817,17 @@ public class BRouterView extends View {
} }
} }
public void startConfigureService() { public void startConfigureService(String sparams) {
String[] modes = new String[] String[] modes = new String[]
{"foot_short", "foot_fast", "bicycle_short", "bicycle_fast", "motorcar_short", "motorcar_fast"}; {"foot_short", "foot_fast", "bicycle_short", "bicycle_fast", "motorcar_short", "motorcar_fast"};
boolean[] modesChecked = new boolean[6]; boolean[] modesChecked = new boolean[6];
String msg = "Choose service-modes to configure (" + profileName + " [" + nogoVetoList.size() + "])"; String msg = "Choose service-modes to configure (" + profileName + " [" + nogoVetoList.size() + "])";
((BRouterActivity) getContext()).selectRoutingModes(modes, modesChecked, msg); ((BRouterActivity) getContext()).selectRoutingModes(modes, modesChecked, msg, sparams);
} }
public void configureService(String[] routingModes, boolean[] checkedModes) { public void configureService(String[] routingModes, boolean[] checkedModes, String sparams) {
// read in current config // read in current config
TreeMap<String, ServiceModeConfig> map = new TreeMap<>(); TreeMap<String, ServiceModeConfig> map = new TreeMap<>();
BufferedReader br = null; BufferedReader br = null;
@ -861,7 +861,8 @@ public class BRouterView extends View {
s = sm.params; s = sm.params;
p = sm.profile; p = sm.profile;
} }
if (s == null || !p.equals(profileName)) s = "noparams"; if (!p.equals(profileName)) s = sparams;
if (s == null || s.equals("")) s = "noparams";
ServiceModeConfig smc = new ServiceModeConfig(routingModes[i], profileName, s); ServiceModeConfig smc = new ServiceModeConfig(routingModes[i], profileName, s);
for (OsmNodeNamed nogo : nogoVetoList) { for (OsmNodeNamed nogo : nogoVetoList) {
smc.nogoVetos.add(nogo.ilon + "," + nogo.ilat); smc.nogoVetos.add(nogo.ilon + "," + nogo.ilat);

View File

@ -53,7 +53,6 @@
<string name="action_select_to">اختر إلى/عبر</string> <string name="action_select_to">اختر إلى/عبر</string>
<string name="msg_no_profile">لا توجد بيانات ملف التعريف</string> <string name="msg_no_profile">لا توجد بيانات ملف التعريف</string>
<string name="msg_no_used_profile">، لا يوجد ملف تعريف مستخدم</string>
<string name="msg_too_much_data">هناك الكثير من البيانات للتنزيل، من فضلك قم بتقليلها.</string> <string name="msg_too_much_data">هناك الكثير من البيانات للتنزيل، من فضلك قم بتقليلها.</string>
<string name="msg_download_start">تمت جدولة التنزيل، وتحقق من اتصالك بالإنترنت إذا لم يبدأ التنزيل.</string> <string name="msg_download_start">تمت جدولة التنزيل، وتحقق من اتصالك بالإنترنت إذا لم يبدأ التنزيل.</string>
<string name="msg_wpt_selection">نقاط الطريق الحالية المحددة:\n</string> <string name="msg_wpt_selection">نقاط الطريق الحالية المحددة:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Seleccionar a/via</string> <string name="action_select_to">Seleccionar a/via</string>
<string name="msg_no_profile">no hi ha dades al perfil</string> <string name="msg_no_profile">no hi ha dades al perfil</string>
<string name="msg_no_used_profile">, cap perfil utilitzat</string>
<string name="msg_too_much_data">Massa dades per baixar. Si us plau, redueix-les.</string> <string name="msg_too_much_data">Massa dades per baixar. Si us plau, redueix-les.</string>
<string name="msg_download_start">Baixada programada. Comprovar la connexió a internet si no comença.</string> <string name="msg_download_start">Baixada programada. Comprovar la connexió a internet si no comença.</string>
<string name="msg_wpt_selection">selecció actual de fita:\n</string> <string name="msg_wpt_selection">selecció actual de fita:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">"Nach"/Via wählen</string> <string name="action_select_to">"Nach"/Via wählen</string>
<string name="msg_no_profile">Keine Profildaten</string> <string name="msg_no_profile">Keine Profildaten</string>
<string name="msg_no_used_profile">, kein verwendetes Profil</string>
<string name="msg_too_much_data">Zu viele Daten für den Download. Bitte reduzieren.</string> <string name="msg_too_much_data">Zu viele Daten für den Download. Bitte reduzieren.</string>
<string name="msg_download_start">Download geplant. Überprüfen Sie die Internetverbindung, wenn der Download nicht startet.</string> <string name="msg_download_start">Download geplant. Überprüfen Sie die Internetverbindung, wenn der Download nicht startet.</string>
<string name="msg_wpt_selection">aktuelle Wegpunktauswahl:\n</string> <string name="msg_wpt_selection">aktuelle Wegpunktauswahl:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Επιλέξτε προς/μέσω</string> <string name="action_select_to">Επιλέξτε προς/μέσω</string>
<string name="msg_no_profile">μη δεδομένα προφίλ</string> <string name="msg_no_profile">μη δεδομένα προφίλ</string>
<string name="msg_no_used_profile">, μη χρησιμοποιημένο προφίλ</string>
<string name="msg_too_much_data">Πάρα πολλά δεδομένα για λήψη. Παρακαλώ μειώστε.</string> <string name="msg_too_much_data">Πάρα πολλά δεδομένα για λήψη. Παρακαλώ μειώστε.</string>
<string name="msg_download_start">Προγραμματισμένη λήψη. Ελέγξτε τη σύνδεση στο διαδίκτυο εάν δεν ξεκινά.</string> <string name="msg_download_start">Προγραμματισμένη λήψη. Ελέγξτε τη σύνδεση στο διαδίκτυο εάν δεν ξεκινά.</string>
<string name="msg_wpt_selection">τρέχουσα επιλογή σημείου:\n</string> <string name="msg_wpt_selection">τρέχουσα επιλογή σημείου:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Seleccionar a/vía</string> <string name="action_select_to">Seleccionar a/vía</string>
<string name="msg_no_profile">no hay datos en el perfil</string> <string name="msg_no_profile">no hay datos en el perfil</string>
<string name="msg_no_used_profile">, ningún perfil utilizado</string>
<string name="msg_too_much_data">Demasiados datos a descargar. Por favor, reducidlos.</string> <string name="msg_too_much_data">Demasiados datos a descargar. Por favor, reducidlos.</string>
<string name="msg_download_start">Descarga programada. Comprueba la conexión a internet si no se inicia.</string> <string name="msg_download_start">Descarga programada. Comprueba la conexión a internet si no se inicia.</string>
<string name="msg_wpt_selection">selección actual de waypoint:\n</string> <string name="msg_wpt_selection">selección actual de waypoint:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Sélectionner vers/via</string> <string name="action_select_to">Sélectionner vers/via</string>
<string name="msg_no_profile">aucune donnée de profil</string> <string name="msg_no_profile">aucune donnée de profil</string>
<string name="msg_no_used_profile">, aucun profil utilisé</string>
<string name="msg_too_much_data">Trop de données à télécharger. Veuillez réduire.</string> <string name="msg_too_much_data">Trop de données à télécharger. Veuillez réduire.</string>
<string name="msg_download_start">Téléchargement planifié. Vérifiez la connexion Internet si elle ne démarre pas.</string> <string name="msg_download_start">Téléchargement planifié. Vérifiez la connexion Internet si elle ne démarre pas.</string>
<string name="msg_wpt_selection">sélection actuelle du waypoint:\n</string> <string name="msg_wpt_selection">sélection actuelle du waypoint:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Seleziona a/via</string> <string name="action_select_to">Seleziona a/via</string>
<string name="msg_no_profile">nessun dato del profilo</string> <string name="msg_no_profile">nessun dato del profilo</string>
<string name="msg_no_used_profile">, nessun profilo utilizzato</string>
<string name="msg_too_much_data">Troppi dati per il download. Per favore riduci.</string> <string name="msg_too_much_data">Troppi dati per il download. Per favore riduci.</string>
<string name="msg_download_start">Download programmato. Controlla la connessione Internet se non si avvia.</string> <string name="msg_download_start">Download programmato. Controlla la connessione Internet se non si avvia.</string>
<string name="msg_wpt_selection">selezione del waypoint corrente:\n</string> <string name="msg_wpt_selection">selezione del waypoint corrente:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">선택 ~로/경유하여</string> <string name="action_select_to">선택 ~로/경유하여</string>
<string name="msg_no_profile">프로필 데이터 없음</string> <string name="msg_no_profile">프로필 데이터 없음</string>
<string name="msg_no_used_profile">, 사용된 프로필 없음</string>
<string name="msg_too_much_data">다운로드 하기에 너무 많은 데이터. 줄이도록 하세요.</string> <string name="msg_too_much_data">다운로드 하기에 너무 많은 데이터. 줄이도록 하세요.</string>
<string name="msg_download_start">다운로드 계획되어 있음. 인터넷 연결 체크 그렇지 않다면 시작.</string> <string name="msg_download_start">다운로드 계획되어 있음. 인터넷 연결 체크 그렇지 않다면 시작.</string>
<string name="msg_wpt_selection">현재 장소 선택:\n</string> <string name="msg_wpt_selection">현재 장소 선택:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Selecteer naar/via</string> <string name="action_select_to">Selecteer naar/via</string>
<string name="msg_no_profile">geen profiel data</string> <string name="msg_no_profile">geen profiel data</string>
<string name="msg_no_used_profile">, geen gebruikt profiel</string>
<string name="msg_too_much_data">Te veel gegevens om te downloaden. Verminder a.u.b.</string> <string name="msg_too_much_data">Te veel gegevens om te downloaden. Verminder a.u.b.</string>
<string name="msg_download_start">Download is gepland. Controleer de internetverbinding als deze niet start.</string> <string name="msg_download_start">Download is gepland. Controleer de internetverbinding als deze niet start.</string>
<string name="msg_wpt_selection">huidige waypointselectie:\n</string> <string name="msg_wpt_selection">huidige waypointselectie:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Wybierz do/przez</string> <string name="action_select_to">Wybierz do/przez</string>
<string name="msg_no_profile">brak danych profilu</string> <string name="msg_no_profile">brak danych profilu</string>
<string name="msg_no_used_profile">, brak używanego profilu</string>
<string name="msg_too_much_data">Za dużo danych do pobrania. Proszę ogranicz.</string> <string name="msg_too_much_data">Za dużo danych do pobrania. Proszę ogranicz.</string>
<string name="msg_download_start">Pobieranie zaplanowane. Jeśli się nie rozpocznie, sprawdź połączenie internetowe.</string> <string name="msg_download_start">Pobieranie zaplanowane. Jeśli się nie rozpocznie, sprawdź połączenie internetowe.</string>
<string name="msg_wpt_selection">bieżący wybór punktu trasy:\n</string> <string name="msg_wpt_selection">bieżący wybór punktu trasy:\n</string>

View File

@ -53,7 +53,6 @@
<string name="action_select_to">Select to/via</string> <string name="action_select_to">Select to/via</string>
<string name="msg_no_profile">no profile data</string> <string name="msg_no_profile">no profile data</string>
<string name="msg_no_used_profile">, no used profile</string>
<string name="msg_too_much_data">Too much data for download. Please reduce.</string> <string name="msg_too_much_data">Too much data for download. Please reduce.</string>
<string name="msg_download_start">Download scheduled. Check internet connection if it doesn\'t start.</string> <string name="msg_download_start">Download scheduled. Check internet connection if it doesn\'t start.</string>
<string name="msg_wpt_selection">current waypoint selection:\n</string> <string name="msg_wpt_selection">current waypoint selection:\n</string>