Merge pull request #5209 from nextcloud/ooDownloadFile

OnlyOffice: make download possible
This commit is contained in:
Tobias Kaminsky 2020-01-30 15:30:04 +01:00 committed by GitHub
commit 8dc162960b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 17 deletions

View file

@ -23,8 +23,11 @@
package com.owncloud.android.ui.activity;
import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
@ -192,6 +195,21 @@ public abstract class EditorWebView extends ExternalSiteWebView {
}
}
protected void downloadFile(Uri url) {
DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
if (downloadmanager == null) {
DisplayUtils.showSnackMessage(webview, getString(R.string.failed_to_download));
return;
}
DownloadManager.Request request = new DownloadManager.Request(url);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadmanager.enqueue(request);
}
public class MobileInterface {
@JavascriptInterface
public void close() {

View file

@ -25,9 +25,7 @@
package com.owncloud.android.ui.activity;
import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
@ -235,21 +233,6 @@ public class RichDocumentsEditorWebView extends EditorWebView {
new PrintAsyncTask(targetFile, url.toString(), new WeakReference<>(this)).execute();
}
private void downloadFile(Uri url) {
DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
if (downloadmanager == null) {
DisplayUtils.showSnackMessage(webview, getString(R.string.failed_to_download));
return;
}
DownloadManager.Request request = new DownloadManager.Request(url);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadmanager.enqueue(request);
}
@Override
public void loadUrl(String url) {
if (TextUtils.isEmpty(url)) {

View file

@ -22,6 +22,7 @@
package com.owncloud.android.ui.activity
import android.annotation.SuppressLint
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.widget.Toast
@ -57,6 +58,10 @@ class TextEditorWebView : EditorWebView() {
webview.addJavascriptInterface(MobileInterface(), "DirectEditingMobileInterface")
webview.setDownloadListener({ url, userAgent, contentDisposition, mimetype, contentLength ->
downloadFile(Uri.parse(url))
})
loadUrl(intent.getStringExtra(ExternalSiteWebView.EXTRA_URL))
}