-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Direct editing support #4890
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
Direct editing support #4890
Conversation
ezaquarii
left a comment
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.
just some random rambling
| @ContributesAndroidInjector abstract ReceiveExternalFilesActivity receiveExternalFilesActivity(); | ||
| @ContributesAndroidInjector abstract RequestCredentialsActivity requestCredentialsActivity(); | ||
| @ContributesAndroidInjector abstract RichDocumentsWebView richDocumentsWebView(); | ||
|
|
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.
Whitespace? Not that I care, but it's editable in column mode this way :)
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.
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())); |
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.
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.
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.
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) { |
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.
Not sure what it checks for? isRichDocumentEditingSupported()?
| @@ -0,0 +1,228 @@ | |||
| /* | |||
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.
kt maybe?
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.owncloud.android.ui.asynctasks; | ||
|
|
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.
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) { |
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.
editorWebViewWeakReference can become null between line 52 and 53.
| 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; |
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.
Watch out for proprietary annotation!
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.
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(); |
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.
getUser? You can plug any rabbit holes with toPlatformAccount() - I'll scoop them.
| public class RichDocumentsUrlOperation extends RemoteOperation { | ||
|
|
||
| /** | ||
| * TODO move to library |
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.
separate issue or move within this PR?
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.
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"); |
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.
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 |
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.
this PR or separate issue?
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.
This is what EditorWebView is doing :-)
| int placeholder; | ||
|
|
||
| switch (template.getType()) { | ||
| case "document": |
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.
case strings should be defined as constants
| @@ -0,0 +1,38 @@ | |||
| /* | |||
| * | |||
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.
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") |
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.
should be a constant
|
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) |
5e60212 to
a03a6cf
Compare
Codecov Report
@@ 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
|
|
IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/11863 |
|
IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/11866 |
|
@tobiasKaminsky looks good, the unused variable should be removed and spotbugs might be fine after a rebase(?). |
|
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? |
|
Thank you for your answer Andy, but I do have the text app installed in version 1.1.1. |
|
Then @tobiasKaminsky might need to do some bugfixing |
|
Sorry for not being clear: this needs text app master, and NC18. |
Then it's settled! Thank you for clarifying Tobias! :) |
2f892e7 to
2900568
Compare
- 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>
3a2e573 to
0d84a2d
Compare
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
|
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); |
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> | ||
| * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction | ||
| */ | ||
| public PreviewTextStringFragment() { |
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.
| View view = super.onCreateView(inflater, container, savedInstanceState); | ||
|
|
||
| if (view == null) { | ||
| throw new RuntimeException("View may not be null"); |
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.
Issue found: Avoid throwing raw exception types.
|
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12062.apk |
Codacy615Lint
SpotBugs (new)
SpotBugs (master)
|
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

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