Skip to content

Commit

Permalink
Merge pull request abrensch#724 from janschopohl/master
Browse files Browse the repository at this point in the history
Configure profile as service when changing profile settings
  • Loading branch information
afischerdev authored Sep 2, 2024
2 parents e63cc98 + e18e2a1 commit f38fec1
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
private String title;
private int wpCount;
private boolean startSilent;
private String configuredParams = null;

ActivityResultLauncher<Intent> someActivityResultLauncher;

Expand Down Expand Up @@ -108,7 +109,12 @@ public void onActivityResult(ActivityResult result) {
if (data != null && data.hasExtra("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);
}
}

}
Expand Down Expand Up @@ -203,6 +209,7 @@ public void onClick(DialogInterface dialog, int id) {
return builder.create();
*/
case DIALOG_ROUTINGMODES_ID:
String configuredParams = this.configuredParams;
builder.setTitle(message);
builder.setMultiChoiceItems(routingModes, routingModesChecked,
new DialogInterface.OnMultiChoiceClickListener() {
Expand All @@ -213,7 +220,7 @@ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
});
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mBRouterView.configureService(routingModes, routingModesChecked);
mBRouterView.configureService(routingModes, routingModesChecked, configuredParams);
}
});
return builder.create();
Expand Down Expand Up @@ -345,7 +352,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
public void onClick(DialogInterface dialog, int item) {
if (slist.size() > 1 && item == 0) {
if (wpCount == 0) {
mBRouterView.startConfigureService();
mBRouterView.startConfigureService(null);
} else if (wpCount == -3) {
showRepeatTimeoutHelp();
} else if (wpCount >= 2) {
Expand Down Expand Up @@ -456,21 +463,20 @@ private void showProfileSettings(String selectedProfile) {
}

String sparams = mBRouterView.getConfigureServiceParams(selectedProfile);
if (sparams != null) {
if (listParams.size() > 0) {
Intent i = new Intent(BRouterActivity.this, RoutingParameterDialog.class);
i.putExtra("PROFILE", selectedProfile);
i.putExtra("PROFILE_HASH", String.format("B%X", profile.getAbsolutePath().hashCode()));
i.putExtra("PARAMS", (Serializable) listParams);
i.putExtra("PARAMS_VALUES", sparams);
//startActivityForResult(i, 100);
someActivityResultLauncher.launch(i);
} else {
Toast.makeText(this, R.string.msg_no_profile, Toast.LENGTH_LONG).show();
finish();
}
if (sparams == null) {
// profile is not used yet
sparams = "";
}
if (listParams.size() > 0) {
Intent i = new Intent(BRouterActivity.this, RoutingParameterDialog.class);
i.putExtra("PROFILE", selectedProfile);
i.putExtra("PROFILE_HASH", String.format("B%X", profile.getAbsolutePath().hashCode()));
i.putExtra("PARAMS", (Serializable) listParams);
i.putExtra("PARAMS_VALUES", sparams);
//startActivityForResult(i, 100);
someActivityResultLauncher.launch(i);
} 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();
}
}
Expand Down Expand Up @@ -539,10 +545,11 @@ public void selectBasedir(ArrayList<File> items, String message) {
}
}

public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) {
public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message, String sparams) {
routingModes = modes;
routingModesChecked = modesChecked;
this.message = message;
this.configuredParams = sparams;
showADialog(DIALOG_ROUTINGMODES_ID);
}

Expand Down Expand Up @@ -666,7 +673,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
private void onItemClick(AdapterView<?> adapterView, View view, int which, long l) {
if (which == 0) {
if (wpCount == 0) {
mBRouterView.startConfigureService();
mBRouterView.startConfigureService(null);
} else if (wpCount == -3) {
showRepeatTimeoutHelp();
} else if (wpCount >= 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,17 @@ private void writeRawTrackToPath(String rawTrackPath) {
}
}

public void startConfigureService() {
public void startConfigureService(String sparams) {
String[] modes = new String[]
{"foot_short", "foot_fast", "bicycle_short", "bicycle_fast", "motorcar_short", "motorcar_fast"};
boolean[] modesChecked = new boolean[6];

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
TreeMap<String, ServiceModeConfig> map = new TreeMap<>();
BufferedReader br = null;
Expand Down Expand Up @@ -861,7 +861,8 @@ public void configureService(String[] routingModes, boolean[] checkedModes) {
s = sm.params;
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);
for (OsmNodeNamed nogo : nogoVetoList) {
smc.nogoVetos.add(nogo.ilon + "," + nogo.ilat);
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">اختر إلى/عبر</string>

<string name="msg_no_profile">لا توجد بيانات ملف التعريف</string>
<string name="msg_no_used_profile">، لا يوجد ملف تعريف مستخدم</string>
<string name="msg_too_much_data">هناك الكثير من البيانات للتنزيل، من فضلك قم بتقليلها.</string>
<string name="msg_download_start">تمت جدولة التنزيل، وتحقق من اتصالك بالإنترنت إذا لم يبدأ التنزيل.</string>
<string name="msg_wpt_selection">نقاط الطريق الحالية المحددة:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<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_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_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>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">"Nach"/Via wählen</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_download_start">Download geplant. Überprüfen Sie die Internetverbindung, wenn der Download nicht startet.</string>
<string name="msg_wpt_selection">aktuelle Wegpunktauswahl:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">Επιλέξτε προς/μέσω</string>

<string name="msg_no_profile">μη δεδομένα προφίλ</string>
<string name="msg_no_used_profile">, μη χρησιμοποιημένο προφίλ</string>
<string name="msg_too_much_data">Πάρα πολλά δεδομένα για λήψη. Παρακαλώ μειώστε.</string>
<string name="msg_download_start">Προγραμματισμένη λήψη. Ελέγξτε τη σύνδεση στο διαδίκτυο εάν δεν ξεκινά.</string>
<string name="msg_wpt_selection">τρέχουσα επιλογή σημείου:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<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_used_profile">, ningún perfil utilizado</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_wpt_selection">selección actual de waypoint:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<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_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_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>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">Seleziona a/via</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_download_start">Download programmato. Controlla la connessione Internet se non si avvia.</string>
<string name="msg_wpt_selection">selezione del waypoint corrente:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">선택 ~로/경유하여</string>

<string name="msg_no_profile">프로필 데이터 없음</string>
<string name="msg_no_used_profile">, 사용된 프로필 없음</string>
<string name="msg_too_much_data">다운로드 하기에 너무 많은 데이터. 줄이도록 하세요.</string>
<string name="msg_download_start">다운로드 계획되어 있음. 인터넷 연결 체크 그렇지 않다면 시작.</string>
<string name="msg_wpt_selection">현재 장소 선택:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">Selecteer naar/via</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_download_start">Download is gepland. Controleer de internetverbinding als deze niet start.</string>
<string name="msg_wpt_selection">huidige waypointselectie:\n</string>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">Wybierz do/przez</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_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>
Expand Down
1 change: 0 additions & 1 deletion brouter-routing-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<string name="action_select_to">Select to/via</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_download_start">Download scheduled. Check internet connection if it doesn\'t start.</string>
<string name="msg_wpt_selection">current waypoint selection:\n</string>
Expand Down

0 comments on commit f38fec1

Please sign in to comment.