Skip to content

Commit

Permalink
Merge pull request #3484 from deltachat/adb/issue-3479
Browse files Browse the repository at this point in the history
download .xdc files in background
  • Loading branch information
adbenitez authored Dec 13, 2024
2 parents a93c8ab + b3c50b9 commit 8c89c3e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/java/org/thoughtcrime/securesms/WebxdcStoreActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.Util;

import java.io.ByteArrayInputStream;
import java.util.HashMap;
Expand Down Expand Up @@ -53,17 +54,19 @@ protected void onCreate(Bundle state, boolean ready) {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String ext = MediaUtil.getFileExtensionFromUrl(Uri.parse(url).getPath());
if ("xdc".equals(ext)) {
try {
HttpResponse httpResponse = rpc.getHttpResponse(dcContext.getAccountId(), url);
Uri uri = PersistentBlobProvider.getInstance().create(WebxdcStoreActivity.this, httpResponse.getBlob(), "application/octet-stream", "app.xdc");
Intent intent = new Intent();
intent.setData(uri);
setResult(Activity.RESULT_OK, intent);
finish();
} catch (RpcException e) {
e.printStackTrace();
Toast.makeText(WebxdcStoreActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
Util.runOnAnyBackgroundThread(() -> {
try {
HttpResponse httpResponse = rpc.getHttpResponse(dcContext.getAccountId(), url);
Uri uri = PersistentBlobProvider.getInstance().create(WebxdcStoreActivity.this, httpResponse.getBlob(), "application/octet-stream", "app.xdc");
Intent intent = new Intent();
intent.setData(uri);
setResult(Activity.RESULT_OK, intent);
finish();
} catch (RpcException e) {
e.printStackTrace();
Util.runOnMain(() -> Toast.makeText(WebxdcStoreActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show());
}
});
} else {
WebViewActivity.openUrlInBrowser(WebxdcStoreActivity.this, url);
}
Expand Down

0 comments on commit 8c89c3e

Please sign in to comment.