Merge pull request #653 from afischerdev/engine-mode

App: some error handling
This commit is contained in:
afischerdev 2024-01-15 18:08:26 +01:00 committed by GitHub
commit 6b659def02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 30 deletions

View file

@ -96,11 +96,13 @@ public class BRouterService extends Service {
if (errMsg != null) { if (errMsg != null) {
return errMsg; return errMsg;
} }
// profile is already done
params.remove("profile");
boolean canCompress = "true".equals(params.getString("acceptCompressedResult")); boolean canCompress = "true".equals(params.getString("acceptCompressedResult"));
try { try {
String gpxMessage = worker.getTrackFromParams(params); String gpxMessage = worker.getTrackFromParams(params);
if (canCompress) { if (canCompress && (gpxMessage.startsWith("<") || gpxMessage.startsWith("{"))) {
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix

View file

@ -10,6 +10,7 @@ import android.os.Bundle;
import android.window.OnBackInvokedCallback; import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher; import android.window.OnBackInvokedDispatcher;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -168,41 +169,52 @@ public class RoutingParameterDialog extends AppCompatActivity {
new OnBackInvokedCallback() { new OnBackInvokedCallback() {
@Override @Override
public void onBackInvoked() { public void onBackInvoked() {
StringBuilder sb = null; handleBackPressed();
if (sharedValues != null) {
// fill preference with used params
// for direct use in the BRouter interface "extraParams"
sb = new StringBuilder();
for (Map.Entry<String, ?> entry : sharedValues.getAll().entrySet()) {
if (!entry.getKey().equals("params")) {
sb.append(sb.length() > 0 ? "&" : "")
.append(entry.getKey())
.append("=");
String s = entry.getValue().toString();
if (s.equals("true")) s = "1";
else if (s.equals("false")) s = "0";
sb.append(s);
}
}
}
// and return the array
// one should be enough
Intent i = new Intent();
// i.putExtra("PARAMS", listParams);
i.putExtra("PROFILE", profile);
i.putExtra("PROFILE_HASH", profile_hash);
if (sb != null) i.putExtra("PARAMS_VALUES", sb.toString());
setResult(Activity.RESULT_OK, i);
finish();
} }
} }
); );
} else {
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
handleBackPressed();
}
};
getOnBackPressedDispatcher().addCallback(this, callback);
} }
} }
private void handleBackPressed() {
StringBuilder sb = null;
if (sharedValues != null) {
// fill preference with used params
// for direct use in the BRouter interface "extraParams"
sb = new StringBuilder();
for (Map.Entry<String, ?> entry : sharedValues.getAll().entrySet()) {
if (!entry.getKey().equals("params")) {
sb.append(sb.length() > 0 ? "&" : "")
.append(entry.getKey())
.append("=");
String s = entry.getValue().toString();
if (s.equals("true")) s = "1";
else if (s.equals("false")) s = "0";
sb.append(s);
}
}
}
// and return the array
// one should be enough
Intent i = new Intent();
// i.putExtra("PARAMS", listParams);
i.putExtra("PROFILE", profile);
i.putExtra("PROFILE_HASH", profile_hash);
if (sb != null) i.putExtra("PARAMS_VALUES", sb.toString());
setResult(Activity.RESULT_OK, i);
finish();
}
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);