|
@@ -30,41 +30,31 @@ import android.app.DownloadManager;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
-import android.graphics.Bitmap;
|
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
-import android.text.TextUtils;
|
|
|
|
import android.view.KeyEvent;
|
|
import android.view.KeyEvent;
|
|
-import android.view.View;
|
|
|
|
import android.webkit.JavascriptInterface;
|
|
import android.webkit.JavascriptInterface;
|
|
import android.webkit.ValueCallback;
|
|
import android.webkit.ValueCallback;
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
-import android.widget.ImageView;
|
|
|
|
-import android.widget.ProgressBar;
|
|
|
|
-import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.Glide;
|
|
-import com.google.android.material.snackbar.Snackbar;
|
|
|
|
import com.nextcloud.client.account.CurrentAccountProvider;
|
|
import com.nextcloud.client.account.CurrentAccountProvider;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.network.ClientFactory;
|
|
import com.nextcloud.client.network.ClientFactory;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.Template;
|
|
import com.owncloud.android.datamodel.Template;
|
|
-import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
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.ui.asynctasks.LoadUrlTask;
|
|
|
|
import com.owncloud.android.ui.asynctasks.PrintAsyncTask;
|
|
import com.owncloud.android.ui.asynctasks.PrintAsyncTask;
|
|
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.FileStorageUtils;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
-import com.owncloud.android.utils.MimeTypeUtil;
|
|
|
|
import com.owncloud.android.utils.glide.CustomGlideStreamLoader;
|
|
import com.owncloud.android.utils.glide.CustomGlideStreamLoader;
|
|
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONException;
|
|
@@ -77,42 +67,26 @@ 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.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
|
|
*/
|
|
*/
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
-public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
|
|
-
|
|
|
|
|
|
+public class RichDocumentsEditorWebView extends EditorWebView {
|
|
public static final int MINIMUM_API = Build.VERSION_CODES.LOLLIPOP;
|
|
public static final int MINIMUM_API = Build.VERSION_CODES.LOLLIPOP;
|
|
public static final int REQUEST_LOCAL_FILE = 101;
|
|
public static final int REQUEST_LOCAL_FILE = 101;
|
|
private static final int REQUEST_REMOTE_FILE = 100;
|
|
private static final int REQUEST_REMOTE_FILE = 100;
|
|
- private static final String TAG = RichDocumentsWebView.class.getSimpleName();
|
|
|
|
private static final String URL = "URL";
|
|
private static final String URL = "URL";
|
|
private static final String TYPE = "Type";
|
|
private static final String TYPE = "Type";
|
|
private static final String PRINT = "print";
|
|
private static final String PRINT = "print";
|
|
private static final String NEW_NAME = "NewName";
|
|
private static final String NEW_NAME = "NewName";
|
|
|
|
|
|
private Unbinder unbinder;
|
|
private Unbinder unbinder;
|
|
- private OCFile file;
|
|
|
|
- @Getter @Setter private Snackbar loadingSnackbar;
|
|
|
|
|
|
|
|
public ValueCallback<Uri[]> uploadMessage;
|
|
public ValueCallback<Uri[]> uploadMessage;
|
|
|
|
|
|
- @BindView(R.id.progressBar2)
|
|
|
|
- ProgressBar progressBar;
|
|
|
|
-
|
|
|
|
- @BindView(R.id.thumbnail)
|
|
|
|
- ImageView thumbnail;
|
|
|
|
-
|
|
|
|
- @BindView(R.id.filename)
|
|
|
|
- TextView fileName;
|
|
|
|
-
|
|
|
|
@Inject
|
|
@Inject
|
|
protected CurrentAccountProvider currentAccountProvider;
|
|
protected CurrentAccountProvider currentAccountProvider;
|
|
|
|
|
|
@@ -122,54 +96,16 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
@SuppressLint("AddJavascriptInterface") // suppress warning as webview is only used >= Lollipop
|
|
@SuppressLint("AddJavascriptInterface") // suppress warning as webview is only used >= Lollipop
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
- showToolbar = false;
|
|
|
|
- webViewLayout = R.layout.richdocuments_webview;
|
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
- unbinder = ButterKnife.bind(this);
|
|
|
|
-
|
|
|
|
- file = getIntent().getParcelableExtra(EXTRA_FILE);
|
|
|
|
-
|
|
|
|
- // TODO make file nullable
|
|
|
|
- if (file == null) {
|
|
|
|
- fileName.setText(R.string.create_file_from_template);
|
|
|
|
-
|
|
|
|
- Template template = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_TEMPLATE));
|
|
|
|
-
|
|
|
|
- int placeholder;
|
|
|
|
-
|
|
|
|
- switch (template.getType()) {
|
|
|
|
- case "document":
|
|
|
|
- placeholder = R.drawable.file_doc;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case "spreadsheet":
|
|
|
|
- placeholder = R.drawable.file_xls;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case "presentation":
|
|
|
|
- placeholder = R.drawable.file_ppt;
|
|
|
|
- break;
|
|
|
|
|
|
|
|
- default:
|
|
|
|
- placeholder = R.drawable.file;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
|
|
|
- .load(template.getThumbnailLink())
|
|
|
|
- .placeholder(placeholder)
|
|
|
|
- .error(placeholder)
|
|
|
|
- .into(thumbnail);
|
|
|
|
- } else {
|
|
|
|
- setThumbnail(file, thumbnail);
|
|
|
|
- fileName.setText(file.getFileName());
|
|
|
|
- }
|
|
|
|
|
|
+ unbinder = ButterKnife.bind(this);
|
|
|
|
|
|
|
|
+ WebView.setWebContentsDebuggingEnabled(true);
|
|
webview.addJavascriptInterface(new RichDocumentsMobileInterface(), "RichDocumentsMobileInterface");
|
|
webview.addJavascriptInterface(new RichDocumentsMobileInterface(), "RichDocumentsMobileInterface");
|
|
|
|
|
|
webview.setWebChromeClient(new WebChromeClient() {
|
|
webview.setWebChromeClient(new WebChromeClient() {
|
|
- RichDocumentsWebView activity = RichDocumentsWebView.this;
|
|
|
|
|
|
+ RichDocumentsEditorWebView activity = RichDocumentsEditorWebView.this;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
|
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
|
|
@@ -197,70 +133,49 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
});
|
|
});
|
|
|
|
|
|
// load url in background
|
|
// load url in background
|
|
- url = getIntent().getStringExtra(EXTRA_URL);
|
|
|
|
- if (TextUtils.isEmpty(url)) {
|
|
|
|
- new LoadUrlTask(this, getAccount()).execute(file.getLocalId());
|
|
|
|
- } else {
|
|
|
|
- webview.loadUrl(url);
|
|
|
|
- }
|
|
|
|
|
|
+ loadUrl(getIntent().getStringExtra(EXTRA_URL), file);
|
|
}
|
|
}
|
|
|
|
|
|
- private void setThumbnail(OCFile file, ImageView thumbnailView) {
|
|
|
|
- // Todo minimize: only icon by mimetype
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void initLoadingScreen() {
|
|
|
|
+ if (file == null) {
|
|
|
|
+ fileName.setText(R.string.create_file_from_template);
|
|
|
|
|
|
- if (file.isFolder()) {
|
|
|
|
- thumbnailView.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() ||
|
|
|
|
- file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(),
|
|
|
|
- this));
|
|
|
|
- } else {
|
|
|
|
- if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) && file.getRemoteId() != null) {
|
|
|
|
- // Thumbnail in cache?
|
|
|
|
- Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
|
|
- ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
|
|
|
|
-
|
|
|
|
- if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
|
|
|
|
- if (MimeTypeUtil.isVideo(file)) {
|
|
|
|
- Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail);
|
|
|
|
- thumbnailView.setImageBitmap(withOverlay);
|
|
|
|
- } else {
|
|
|
|
- thumbnailView.setImageBitmap(thumbnail);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // generate new thumbnail
|
|
|
|
- if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
|
|
|
|
- try {
|
|
|
|
- final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
|
|
- new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
|
|
|
- getStorageManager(), getAccount());
|
|
|
|
-
|
|
|
|
- if (thumbnail == null) {
|
|
|
|
- if (MimeTypeUtil.isVideo(file)) {
|
|
|
|
- thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
|
|
|
- } else {
|
|
|
|
- thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
|
|
- new ThumbnailsCacheManager.AsyncThumbnailDrawable(getResources(), thumbnail, task);
|
|
|
|
- thumbnailView.setImageDrawable(asyncDrawable);
|
|
|
|
- task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file,
|
|
|
|
- file.getRemoteId()));
|
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
|
- Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ Template template = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_TEMPLATE));
|
|
|
|
|
|
- if ("image/png".equalsIgnoreCase(file.getMimeType())) {
|
|
|
|
- thumbnailView.setBackgroundColor(getResources().getColor(R.color.bg_default));
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(),
|
|
|
|
- getAccount(), this));
|
|
|
|
|
|
+ int placeholder;
|
|
|
|
+
|
|
|
|
+ switch (template.getType()) {
|
|
|
|
+ case DOCUMENT:
|
|
|
|
+ placeholder = R.drawable.file_doc;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case SPREADSHEET:
|
|
|
|
+ placeholder = R.drawable.file_xls;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case PRESENTATION:
|
|
|
|
+ placeholder = R.drawable.file_ppt;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ placeholder = R.drawable.file;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
|
|
|
+ .load(template.getThumbnailLink())
|
|
|
|
+ .placeholder(placeholder)
|
|
|
|
+ .error(placeholder)
|
|
|
|
+ .into(thumbnail);
|
|
|
|
+ } else {
|
|
|
|
+ setThumbnail(file, thumbnail);
|
|
|
|
+ fileName.setText(file.getFileName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void onNewIntent(Intent intent) {
|
|
protected void onNewIntent(Intent intent) {
|
|
super.onNewIntent(intent);
|
|
super.onNewIntent(intent);
|
|
@@ -272,13 +187,6 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
startActivityForResult(action, REQUEST_REMOTE_FILE);
|
|
startActivityForResult(action, REQUEST_REMOTE_FILE);
|
|
}
|
|
}
|
|
|
|
|
|
- private void openShareDialog() {
|
|
|
|
- Intent intent = new Intent(this, ShareActivity.class);
|
|
|
|
- intent.putExtra(FileActivity.EXTRA_FILE, file);
|
|
|
|
- intent.putExtra(FileActivity.EXTRA_ACCOUNT, getAccount());
|
|
|
|
- startActivity(intent);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
if (RESULT_OK != resultCode) {
|
|
if (RESULT_OK != resultCode) {
|
|
@@ -351,22 +259,6 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
}
|
|
}
|
|
|
|
|
|
- public void closeView() {
|
|
|
|
- webview.destroy();
|
|
|
|
- finish();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void hideLoading() {
|
|
|
|
- thumbnail.setVisibility(View.GONE);
|
|
|
|
- fileName.setVisibility(View.GONE);
|
|
|
|
- progressBar.setVisibility(View.GONE);
|
|
|
|
- webview.setVisibility(View.VISIBLE);
|
|
|
|
-
|
|
|
|
- if (loadingSnackbar != null) {
|
|
|
|
- loadingSnackbar.dismiss();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
protected void onResume() {
|
|
protected void onResume() {
|
|
super.onResume();
|
|
super.onResume();
|
|
@@ -403,25 +295,15 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
downloadmanager.enqueue(request);
|
|
downloadmanager.enqueue(request);
|
|
}
|
|
}
|
|
|
|
|
|
- private class RichDocumentsMobileInterface {
|
|
|
|
- @JavascriptInterface
|
|
|
|
- public void close() {
|
|
|
|
- runOnUiThread(RichDocumentsWebView.this::closeView);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ private class RichDocumentsMobileInterface extends MobileInterface {
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
public void insertGraphic() {
|
|
public void insertGraphic() {
|
|
openFileChooser();
|
|
openFileChooser();
|
|
}
|
|
}
|
|
|
|
|
|
- @JavascriptInterface
|
|
|
|
- public void share() {
|
|
|
|
- openShareDialog();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
public void documentLoaded() {
|
|
public void documentLoaded() {
|
|
- runOnUiThread(RichDocumentsWebView.this::hideLoading);
|
|
|
|
|
|
+ runOnUiThread(RichDocumentsEditorWebView.this::hideLoading);
|
|
}
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
@@ -440,8 +322,6 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
Log_OC.e(this, "Failed to parse download json message: " + e);
|
|
Log_OC.e(this, "Failed to parse download json message: " + e);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
@@ -466,6 +346,4 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|