Skip to content

Commit

Permalink
Merge pull request #653 from afischerdev/engine-mode
Browse files Browse the repository at this point in the history
App: some error handling
  • Loading branch information
afischerdev authored Jan 15, 2024
2 parents 7ffee3a + ec3461d commit 6b659de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ public String getTrackFromParams(Bundle params) throws RemoteException {
if (errMsg != null) {
return errMsg;
}
// profile is already done
params.remove("profile");

boolean canCompress = "true".equals(params.getString("acceptCompressedResult"));
try {
String gpxMessage = worker.getTrackFromParams(params);
if (canCompress) {
if (canCompress && (gpxMessage.startsWith("<") || gpxMessage.startsWith("{"))) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -168,39 +169,50 @@ protected void onCreate(final Bundle savedInstanceState) {
new OnBackInvokedCallback() {
@Override
public void onBackInvoked() {
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();
handleBackPressed();
}
}
);
} 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
Expand Down

0 comments on commit 6b659de

Please sign in to comment.