mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 14:45:47 +03:00
Collabora: hide loading delay warning if document is loaded (#3945)
Collabora: hide loading delay warning if document is loaded
This commit is contained in:
commit
9a4b6996f0
3 changed files with 110 additions and 61 deletions
|
@ -42,6 +42,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This activity shows an URL as a web view
|
* This activity shows an URL as a web view
|
||||||
|
@ -55,11 +56,11 @@ public class ExternalSiteWebView extends FileActivity {
|
||||||
|
|
||||||
private static final String TAG = ExternalSiteWebView.class.getSimpleName();
|
private static final String TAG = ExternalSiteWebView.class.getSimpleName();
|
||||||
|
|
||||||
private boolean showSidebar;
|
|
||||||
protected boolean showToolbar = true;
|
protected boolean showToolbar = true;
|
||||||
private int menuItemId;
|
|
||||||
protected WebView webview;
|
|
||||||
protected int webViewLayout = R.layout.externalsite_webview;
|
protected int webViewLayout = R.layout.externalsite_webview;
|
||||||
|
private int menuItemId;
|
||||||
|
@Getter protected WebView webview;
|
||||||
|
private boolean showSidebar;
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
|
|
@ -30,10 +30,8 @@ import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.JavascriptInterface;
|
import android.webkit.JavascriptInterface;
|
||||||
|
@ -56,7 +54,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.operations.RichDocumentsCreateAssetOperation;
|
import com.owncloud.android.operations.RichDocumentsCreateAssetOperation;
|
||||||
import com.owncloud.android.operations.RichDocumentsUrlOperation;
|
import com.owncloud.android.ui.asynctasks.LoadUrlTask;
|
||||||
import com.owncloud.android.ui.fragment.OCFileListFragment;
|
import com.owncloud.android.ui.fragment.OCFileListFragment;
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.MimeTypeUtil;
|
import com.owncloud.android.utils.MimeTypeUtil;
|
||||||
|
@ -64,14 +62,14 @@ import com.owncloud.android.utils.glide.CustomGlideStreamLoader;
|
||||||
|
|
||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens document for editing via Richdocuments app in a web view
|
* Opens document for editing via Richdocuments app in a web view
|
||||||
|
@ -88,6 +86,7 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
private OCFile file;
|
private OCFile file;
|
||||||
|
@Getter @Setter private Snackbar loadingSnackbar;
|
||||||
|
|
||||||
public ValueCallback<Uri[]> uploadMessage;
|
public ValueCallback<Uri[]> uploadMessage;
|
||||||
|
|
||||||
|
@ -182,7 +181,7 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||||
// load url in background
|
// load url in background
|
||||||
url = getIntent().getStringExtra(EXTRA_URL);
|
url = getIntent().getStringExtra(EXTRA_URL);
|
||||||
if (TextUtils.isEmpty(url)) {
|
if (TextUtils.isEmpty(url)) {
|
||||||
new LoadUrl(this, getAccount()).execute(file.getLocalId());
|
new LoadUrlTask(this, getAccount()).execute(file.getLocalId());
|
||||||
} else {
|
} else {
|
||||||
webview.loadUrl(url);
|
webview.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
@ -334,7 +333,7 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeView() {
|
public void closeView() {
|
||||||
webview.destroy();
|
webview.destroy();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@ -344,6 +343,10 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||||
fileName.setVisibility(View.GONE);
|
fileName.setVisibility(View.GONE);
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
webview.setVisibility(View.VISIBLE);
|
webview.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (loadingSnackbar != null) {
|
||||||
|
loadingSnackbar.dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RichDocumentsMobileInterface {
|
private class RichDocumentsMobileInterface {
|
||||||
|
@ -368,56 +371,5 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LoadUrl extends AsyncTask<String, Void, String> {
|
|
||||||
|
|
||||||
private Account account;
|
|
||||||
private WeakReference<RichDocumentsWebView> richDocumentsWebViewWeakReference;
|
|
||||||
|
|
||||||
LoadUrl(RichDocumentsWebView richDocumentsWebView, Account account) {
|
|
||||||
this.account = account;
|
|
||||||
this.richDocumentsWebViewWeakReference = new WeakReference<>(richDocumentsWebView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(String... fileId) {
|
|
||||||
if (richDocumentsWebViewWeakReference.get() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
RichDocumentsUrlOperation richDocumentsUrlOperation = new RichDocumentsUrlOperation(fileId[0]);
|
|
||||||
RemoteOperationResult result = richDocumentsUrlOperation.execute(account,
|
|
||||||
richDocumentsWebViewWeakReference.get());
|
|
||||||
|
|
||||||
if (!result.isSuccess()) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return (String) result.getData().get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String url) {
|
|
||||||
RichDocumentsWebView richDocumentsWebView = richDocumentsWebViewWeakReference.get();
|
|
||||||
|
|
||||||
if (richDocumentsWebView == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!url.isEmpty()) {
|
|
||||||
richDocumentsWebView.webview.loadUrl(url);
|
|
||||||
|
|
||||||
new Handler().postDelayed(() -> {
|
|
||||||
if (richDocumentsWebView.webview.getVisibility() != View.VISIBLE) {
|
|
||||||
DisplayUtils.createSnackbar(richDocumentsWebView.findViewById(android.R.id.content),
|
|
||||||
R.string.timeout_richDocuments, Snackbar.LENGTH_INDEFINITE)
|
|
||||||
.setActionTextColor(richDocumentsWebView.getResources().getColor(R.color.white))
|
|
||||||
.setAction(R.string.fallback_weblogin_back, v -> richDocumentsWebView.closeView()).show();
|
|
||||||
}
|
|
||||||
}, 10 * 1000);
|
|
||||||
} else {
|
|
||||||
Toast.makeText(richDocumentsWebView.getApplicationContext(),
|
|
||||||
R.string.richdocuments_failed_to_load_document, Toast.LENGTH_LONG).show();
|
|
||||||
richDocumentsWebView.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Nextcloud Android client application
|
||||||
|
*
|
||||||
|
* @author Tobias Kaminsky
|
||||||
|
* Copyright (C) 2019 Tobias Kaminsky
|
||||||
|
* Copyright (C) 2019 Nextcloud GmbH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.ui.asynctasks;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
import com.owncloud.android.R;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.operations.RichDocumentsUrlOperation;
|
||||||
|
import com.owncloud.android.ui.activity.RichDocumentsWebView;
|
||||||
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
public class LoadUrlTask extends AsyncTask<String, Void, String> {
|
||||||
|
|
||||||
|
private Account account;
|
||||||
|
private WeakReference<RichDocumentsWebView> richDocumentsWebViewWeakReference;
|
||||||
|
|
||||||
|
public LoadUrlTask(RichDocumentsWebView richDocumentsWebView, Account account) {
|
||||||
|
this.account = account;
|
||||||
|
this.richDocumentsWebViewWeakReference = new WeakReference<>(richDocumentsWebView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(String... fileId) {
|
||||||
|
if (richDocumentsWebViewWeakReference.get() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
RichDocumentsUrlOperation richDocumentsUrlOperation = new RichDocumentsUrlOperation(fileId[0]);
|
||||||
|
RemoteOperationResult result = richDocumentsUrlOperation.execute(account,
|
||||||
|
richDocumentsWebViewWeakReference.get());
|
||||||
|
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (String) result.getData().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String url) {
|
||||||
|
RichDocumentsWebView richDocumentsWebView = richDocumentsWebViewWeakReference.get();
|
||||||
|
|
||||||
|
if (richDocumentsWebView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url.isEmpty()) {
|
||||||
|
richDocumentsWebView.getWebview().loadUrl(url);
|
||||||
|
|
||||||
|
new Handler().postDelayed(() -> {
|
||||||
|
if (richDocumentsWebView.getWebview().getVisibility() != View.VISIBLE) {
|
||||||
|
Snackbar snackbar = DisplayUtils.createSnackbar(richDocumentsWebView.findViewById(android.R.id.content),
|
||||||
|
R.string.timeout_richDocuments, Snackbar.LENGTH_INDEFINITE)
|
||||||
|
.setActionTextColor(richDocumentsWebView.getResources().getColor(R.color.white))
|
||||||
|
.setAction(R.string.fallback_weblogin_back, v -> richDocumentsWebView.closeView());
|
||||||
|
|
||||||
|
richDocumentsWebView.setLoadingSnackbar(snackbar);
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
}, 10 * 1000);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(richDocumentsWebView.getApplicationContext(),
|
||||||
|
R.string.richdocuments_failed_to_load_document, Toast.LENGTH_LONG).show();
|
||||||
|
richDocumentsWebView.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue