Skip to content

Conversation

@tobiasKaminsky
Copy link
Member

  • abstract EditorWebView
  • support direct editing endpoint
  • needs Text app
  • behaviour:
  • if downloaded show it locally, use edit for remote editing
  • if not downloaded, open it remote directly

Signed-off-by: tobiasKaminsky tobias@kaminsky.me

Copy link
Collaborator

@ezaquarii ezaquarii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some random rambling

@ContributesAndroidInjector abstract ReceiveExternalFilesActivity receiveExternalFilesActivity();
@ContributesAndroidInjector abstract RequestCredentialsActivity requestCredentialsActivity();
@ContributesAndroidInjector abstract RichDocumentsWebView richDocumentsWebView();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace? Not that I care, but it's editable in column mode this way :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn AndroidStudio is reformatting it…

cv.put(ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES, capability.getRichDocumentsTemplatesAvailable()
.getValue());
cv.put(ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME, capability.getRichDocumentsProductName());
cv.put(ProviderTableMeta.CAPABILITIES_DIRECT_EDITING, new Gson().toJson(capability.getDirectEditing()));
Copy link
Collaborator

@ezaquarii ezaquarii Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danger! Crevasses!

IIRC Gson had some serious issues around Kotlin data classes. Can't remember what it was exactly, but I'll do some research and circle back. null handling was an issue for sure.

In the meantime, I'd seal that behind an interface and inject JSON serializer via Dagger top-down. I know it's not pretty, but we might need to revisit our JSON serializer choice in the near future and swap it out when we discover some funky behaviors. This area is full of nasty surprises, such as deserializers that use non-List-conforming lists and similar plesantries.

The upside is that we can supply serializer/deserializer with our custom type adapters (Date :) ) that will behave consistently across all modules.

Please don't ask which one will work. I don't know - this area is changing like frontend frameworks, with new library of the quater every month. (-: I'm just sharing my past pains here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using Gson() in many other places.
Let us address this entirely (if needed) in a new issue / PR.

* This will be replaced by unified editor and can be removed once EOL of corresponding server version.
*/
@NextcloudServer(max = 18)
private boolean checkRichDocumentRequirement(OCCapability capability, String mimeType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what it checks for? isRichDocumentEditingSupported()?

@@ -0,0 +1,228 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kt maybe?

* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.asynctasks;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this one so simplified, I'd also consider converting it to a function and using AsyncRunner. This way this can be covered with tests. Async tasks - not so much.

}

RemoteOperationResult result = null;
if (editorWebViewWeakReference.get() instanceof RichDocumentsEditorWebView) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editorWebViewWeakReference can become null between line 52 and 53.

Suggested change
if (editorWebViewWeakReference.get() instanceof RichDocumentsEditorWebView) {
final editorWebViewWeak = editorWebViewWeakReference.get(); // lock reference so it's not GC'd between lines
if (editorWebViewWeak == null) {
return;
}
and so on

Just discovered suggestions feature. Neat!

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for proprietary annotation!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice finding!
This was auto-picked by Android Studio.
I will have a look for other usages within our project and do a PR then.

case R.id.action_open_file_as_richdocument: {
mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(singleFile, getContext());
case R.id.action_edit: {
Account account = ((FileActivity) mContainerActivity).getAccount();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUser? You can plug any rabbit holes with toPlatformAccount() - I'll scoop them.

public class RichDocumentsUrlOperation extends RemoteOperation {

/**
* TODO move to library
Copy link
Member

@AndyScherzinger AndyScherzinger Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate issue or move within this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be outdated once we switch entire RichDocuments to use new DirectEditing endpoint (just like Text).
I annotate it with EOL 18 and we keep it here, as otherwise other library users might use it.

webview.setFocusable(true);
webview.setFocusableInTouchMode(true);
webview.setClickable(true);
// webview.addJavascriptInterface(new TestMobileInterface(), "RichDocumentsMobileInterface");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove then?

public class RichDocumentsWebView extends ExternalSiteWebView {
public class RichDocumentsEditorWebView extends EditorWebView {
/**
* TODO: create intermediate abstract class, which has "loadURL", create this and TextWebView as children
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR or separate issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what EditorWebView is doing :-)

int placeholder;

switch (template.getType()) {
case "document":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case strings should be defined as constants

@@ -0,0 +1,38 @@
/*
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line can e removed

result = new RichDocumentsUrlOperation(fileId[0]).execute(account, editorWebViewWeakReference.get());
} else if (editorWebViewWeakReference.get() instanceof TextEditorWebView) {
result = new DirectEditingOpenFileRemoteOperation(fileId[0],
"text")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a constant

@AndyScherzinger
Copy link
Member

Besides the exisitng review comments, just some minor issues regarding use of constants.

@tobiasKaminsky needs a rebase, db cange will conflict with #4784 (whichever makes it to master first)

@codecov
Copy link

codecov bot commented Dec 2, 2019

Codecov Report

Merging #4890 into master will decrease coverage by 0.07%.
The diff coverage is 14.85%.

@@             Coverage Diff              @@
##             master    #4890      +/-   ##
============================================
- Coverage     17.94%   17.87%   -0.08%     
  Complexity        3        3              
============================================
  Files           385      389       +4     
  Lines         32679    32887     +208     
  Branches       4594     4620      +26     
============================================
+ Hits           5864     5877      +13     
- Misses        25872    26064     +192     
- Partials        943      946       +3
Impacted Files Coverage Δ Complexity Δ
...droid/ui/fragment/OCFileListBottomSheetDialog.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...java/com/nextcloud/client/di/ComponentsModule.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...cloud/android/datamodel/ArbitraryDataProvider.java 67.9% <ø> (ø) 0 <0> (ø) ⬇️
...ain/java/com/owncloud/android/db/ProviderMeta.java 84.61% <ø> (ø) 0 <0> (ø) ⬇️
...owncloud/android/ui/asynctasks/PrintAsyncTask.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...cloud/android/ui/activity/ExternalSiteWebView.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...owncloud/android/files/FetchTemplateOperation.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...cloud/android/ui/helpers/FileOperationsHelper.java 2.34% <0%> (-0.07%) 0 <0> (ø)
...ncloud/android/ui/fragment/OCFileListFragment.java 25.3% <0%> (-0.56%) 0 <0> (ø)
...ndroid/ui/dialog/ChooseTemplateDialogFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
... and 30 more

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

@AndyScherzinger
Copy link
Member

@tobiasKaminsky looks good, the unused variable should be removed and spotbugs might be fine after a rebase(?).

@elpraga
Copy link

elpraga commented Dec 9, 2019

I've just tried the above app with nc17, and it did not offer online md editing. Do I need st to switch it on on the server side?

@AndyScherzinger
Copy link
Member

  • needs Text app

@elpraga
Copy link

elpraga commented Dec 9, 2019

  • needs Text app

Thank you for your answer Andy, but I do have the text app installed in version 1.1.1.

@AndyScherzinger
Copy link
Member

Then @tobiasKaminsky might need to do some bugfixing

@tobiasKaminsky
Copy link
Member Author

Sorry for not being clear: this needs text app master, and NC18.

@elpraga
Copy link

elpraga commented Dec 9, 2019

Sorry for not being clear: this needs text app master, and NC18.

Then it's settled! Thank you for clarifying Tobias! :)

@nextcloud nextcloud deleted a comment from AndyScherzinger Dec 17, 2019
@tobiasKaminsky tobiasKaminsky force-pushed the directEditing branch 2 times, most recently from 2f892e7 to 2900568 Compare December 18, 2019 08:54
- abstract EditorWebView
- support direct editing endpoint

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
…ity reason of javascript interface

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
- abstract EditorWebView
- support direct editing endpoint

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
@nextcloud-android-bot
Copy link
Collaborator

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 8
- Added 4
           

Complexity increasing per file
==============================
- src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java  5
- src/main/java/com/owncloud/android/providers/FileContentProvider.java  6
- src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java  3
- src/main/java/com/owncloud/android/ui/asynctasks/LoadUrlTask.java  3
- src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java  11
- src/main/java/com/owncloud/android/ui/activity/EditorWebView.java  13
- src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java  2
- src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java  1
         

Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java  -6
         

See the complete overview on Codacy

try {
File file = new File(location);
reader = ReaderFactory.createReaderFromFile(file);
scanner = new Scanner(reader);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* <p>
* DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
*/
public PreviewTextStringFragment() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View view = super.onCreateView(inflater, container, savedInstanceState);

if (view == null) {
throw new RuntimeException("View may not be null");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12062.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

615

Lint

TypemasterPR
Warnings7374
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings71
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings106
Security Warnings44
Dodgy code Warnings139
Total413

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings106
Security Warnings44
Dodgy code Warnings136
Total409

@tobiasKaminsky tobiasKaminsky merged commit 6af9523 into master Dec 19, 2019
@delete-merged-branch delete-merged-branch bot deleted the directEditing branch December 19, 2019 14:12
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.10.0 milestone Dec 19, 2019
tobiasKaminsky added a commit that referenced this pull request Dec 20, 2019
6af9523 Merge pull request #4890 from nextcloud/directEditing
b4c3a7d Merge pull request #5018 from grote/thumbnail-fix
b207671 fix during CI
d231370 Merge pull request #4829 from nextcloud/dependabot/gradle/tools.fastlane-screengrab-2.0.0
0d84a2d warning about used feature in newer SDK
b4ea014 use master branch
ec2cfef Direct editing support - abstract EditorWebView - support direct editing endpoint
f2627a2 enable caching
ddffaf7 use custom user agent for onlyOffice
0178499 remove unneeded static string
f25127d revert to master snapshot
95afe8c use editor id to use any editor
d05de98 use file path as parameter for open direct editing file
300abba make sure TextEditor is also only used ond >= Android 5, due to security reason of javascript interface
994817c get direct editing info from endpoint
b31cee5 prevent NPE
d1611f6 Direct editing support - abstract EditorWebView - support direct editing endpoint
516c464 override minSDK for lib
10a667b Bump screengrab from 1.2.0 to 2.0.0
9fbedb4 Merge pull request #4992 from nextcloud/uiComparison
751301c daily dev 20191219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants