-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Whiteboard on Mobile #16998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tobiasKaminsky
wants to merge
1
commit into
master
Choose a base branch
from
whiteboard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
β0
Open
Whiteboard on Mobile #16998
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
227 changes: 227 additions & 0 deletions
227
app/src/main/java/com/owncloud/android/ui/activity/WhiteboardWebView.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2019 Chris Narkiewicz <hello@ezaquarii.com> | ||
| * SPDX-FileCopyrightText: 2018 Tobias Kaminsky <tobias@kaminsky.me> | ||
| * SPDX-FileCopyrightText: 2018 Nextcloud GmbH | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
| */ | ||
| package com.owncloud.android.ui.activity | ||
|
|
||
| import android.content.Intent | ||
| import android.net.Uri | ||
| import android.os.Bundle | ||
| import android.text.TextUtils | ||
| import android.view.KeyEvent | ||
| import android.webkit.JavascriptInterface | ||
| import androidx.activity.result.ActivityResult | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.core.net.toUri | ||
| import com.nextcloud.client.account.CurrentAccountProvider | ||
| import com.nextcloud.client.network.ClientFactory | ||
| import com.nextcloud.utils.extensions.getParcelableArgument | ||
| import com.owncloud.android.R | ||
| import com.owncloud.android.datamodel.OCFile | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import com.owncloud.android.operations.RichDocumentsCreateAssetOperation | ||
| import com.owncloud.android.ui.asynctasks.RichDocumentsLoadUrlTask | ||
| import com.owncloud.android.ui.fragment.OCFileListFragment | ||
| import com.owncloud.android.utils.DisplayUtils | ||
| import com.owncloud.android.utils.FileStorageUtils | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings | ||
| import org.json.JSONException | ||
| import org.json.JSONObject | ||
| import java.io.File | ||
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * Opens document for editing via Richdocuments app in a web view | ||
| */ | ||
| class WhiteboardWebView : EditorWebView() { | ||
| @JvmField | ||
| @Inject | ||
| var currentAccountProvider: CurrentAccountProvider? = null | ||
|
|
||
| @JvmField | ||
| @Inject | ||
| var clientFactory: ClientFactory? = null | ||
|
|
||
| private var activityResult: ActivityResultLauncher<Intent>? = null | ||
|
|
||
| @SuppressFBWarnings("ANDROID_WEB_VIEW_JAVASCRIPT_INTERFACE") | ||
| override fun postOnCreate() { | ||
| super.postOnCreate() | ||
|
|
||
| webView.addJavascriptInterface(RichDocumentsMobileInterface(), "RichDocumentsMobileInterface") | ||
|
|
||
| loadUrl(intent.getStringExtra(EXTRA_URL)) | ||
|
|
||
| registerActivityResult() | ||
| } | ||
|
|
||
| override fun onNewIntent(intent: Intent) { | ||
| super.onNewIntent(intent) | ||
| } | ||
|
|
||
| private fun openFileChooser() { | ||
| val action = Intent(this, FilePickerActivity::class.java) | ||
| action.putExtra(OCFileListFragment.ARG_MIMETYPE, "image/") | ||
| activityResult?.launch(action) | ||
| } | ||
|
|
||
| private fun registerActivityResult() { | ||
| activityResult = | ||
| registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> | ||
| if (RESULT_OK == result.resultCode) { | ||
| result.data?.let { | ||
| handleRemoteFile(it) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun handleRemoteFile(data: Intent) { | ||
| val file = FolderPickerActivity.EXTRA_FILES?.let { data.getParcelableArgument(it, OCFile::class.java) } | ||
|
|
||
| Thread { | ||
| val user = currentAccountProvider?.user | ||
| val operation = RichDocumentsCreateAssetOperation(file?.remotePath) | ||
| val result = operation.execute(user, this) | ||
| if (result.isSuccess) { | ||
| val asset = result.singleData as String | ||
| runOnUiThread { | ||
| webView.evaluateJavascript( | ||
| "OCA.RichDocuments.documentsMain.postAsset('" + | ||
| file?.fileName + "', '" + asset + "');", | ||
| null | ||
| ) | ||
| } | ||
| } else { | ||
| runOnUiThread { DisplayUtils.showSnackMessage(this, "Inserting image failed!") } | ||
| } | ||
| }.start() | ||
| } | ||
|
|
||
| override fun onSaveInstanceState(outState: Bundle) { | ||
| outState.putString(EXTRA_URL, url) | ||
| super.onSaveInstanceState(outState) | ||
| } | ||
|
|
||
| override fun onRestoreInstanceState(savedInstanceState: Bundle) { | ||
| url = savedInstanceState.getString(EXTRA_URL) | ||
| super.onRestoreInstanceState(savedInstanceState) | ||
| } | ||
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| webView.evaluateJavascript( | ||
| "if (typeof OCA.RichDocuments.documentsMain.postGrabFocus !== 'undefined') " + | ||
| "{ OCA.RichDocuments.documentsMain.postGrabFocus(); }", | ||
| null | ||
| ) | ||
| } | ||
|
|
||
| private fun printFile(url: Uri) { | ||
| val account = accountManager.currentOwnCloudAccount | ||
| if (account == null) { | ||
| DisplayUtils.showSnackMessage(webView, getString(R.string.failed_to_print)) | ||
| return | ||
| } | ||
| val targetFile = File(FileStorageUtils.getTemporalPath(account.name) + "/print.pdf") | ||
| // PrintAsyncTask(targetFile, url.toString(), WeakReference(this)).execute() | ||
| } | ||
|
|
||
| public override fun loadUrl(url: String?) { | ||
| if (TextUtils.isEmpty(url)) { | ||
| RichDocumentsLoadUrlTask(this, user.get(), file).execute() | ||
| } else { | ||
| super.loadUrl(url) | ||
| } | ||
| } | ||
|
|
||
| private fun showSlideShow(url: Uri) { | ||
| val intent = Intent(this, ExternalSiteWebView::class.java) | ||
| intent.putExtra(EXTRA_URL, url.toString()) | ||
| intent.putExtra(EXTRA_SHOW_SIDEBAR, false) | ||
| intent.putExtra(EXTRA_SHOW_TOOLBAR, false) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| private inner class RichDocumentsMobileInterface : MobileInterface() { | ||
| @JavascriptInterface | ||
| fun insertGraphic() { | ||
| openFileChooser() | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun documentLoaded() { | ||
| runOnUiThread { hideLoading() } | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun downloadAs(json: String?) { | ||
| try { | ||
| json ?: return | ||
| val downloadJson = JSONObject(json) | ||
| val url = downloadJson.getString(URL).toUri() | ||
| when (downloadJson.getString(TYPE)) { | ||
| PRINT -> printFile(url) | ||
|
|
||
| SLIDESHOW -> showSlideShow(url) | ||
|
|
||
| else -> { | ||
| val downloadFileName = downloadJson.optString(FILENAME, fileName) | ||
| downloadFile(url, downloadFileName) | ||
| } | ||
| } | ||
| } catch (e: JSONException) { | ||
| Log_OC.e(this, "Failed to parse download json message: $e") | ||
| } | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun fileRename(renameString: String?) { | ||
| // when shared file is renamed in another instance, we will get notified about it | ||
| // need to change filename for sharing | ||
| try { | ||
| renameString ?: return | ||
| val renameJson = JSONObject(renameString) | ||
| val newName = renameJson.getString(NEW_NAME) | ||
| file?.fileName = newName | ||
| } catch (e: JSONException) { | ||
| Log_OC.e(this, "Failed to parse rename json message: $e") | ||
| } | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun paste() { | ||
| // Javascript cannot do this by itself, so help out. | ||
| webView.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE)) | ||
| webView.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE)) | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun hyperlink(hyperlink: String?) { | ||
| try { | ||
| hyperlink ?: return | ||
| val url = JSONObject(hyperlink).getString(HYPERLINK) | ||
| val intent = Intent(Intent.ACTION_VIEW) | ||
| intent.data = url.toUri() | ||
| startActivity(intent) | ||
| } catch (e: JSONException) { | ||
| Log_OC.e(this, "Failed to parse download json message: $e") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val URL = "URL" | ||
| private const val HYPERLINK = "Url" | ||
| private const val TYPE = "Type" | ||
| private const val PRINT = "print" | ||
| private const val SLIDESHOW = "slideshow" | ||
| private const val NEW_NAME = "NewName" | ||
| private const val FILENAME = "filename" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ | |
| import com.owncloud.android.ui.activity.RichDocumentsEditorWebView; | ||
| import com.owncloud.android.ui.activity.ShareActivity; | ||
| import com.owncloud.android.ui.activity.TextEditorWebView; | ||
| import com.owncloud.android.ui.activity.WhiteboardWebView; | ||
| import com.owncloud.android.ui.dialog.SendFilesDialog; | ||
| import com.owncloud.android.ui.dialog.SendShareDialog; | ||
| import com.owncloud.android.ui.events.EncryptionEvent; | ||
|
|
@@ -355,6 +356,14 @@ public void openFile(OCFile file) { | |
| }); | ||
| }).start(); | ||
| } | ||
|
|
||
| public void openFileAsWhiteboard(OCFile file, Context context) { | ||
| Intent collaboraWebViewIntent = new Intent(context, WhiteboardWebView.class); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming? π |
||
| collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Whiteboard"); | ||
| collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_FILE, file); | ||
| collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false); | ||
| context.startActivity(collaboraWebViewIntent); | ||
| } | ||
|
|
||
| public void openFileAsRichDocument(OCFile file, Context context) { | ||
| Intent collaboraWebViewIntent = new Intent(context, RichDocumentsEditorWebView.class); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€
P.S.: OK, got it, essentially an mostly unadjusted copy of the richdocs view at this state π