Skip to content

Conversation

@tobiasKaminsky
Copy link
Member

@tobiasKaminsky tobiasKaminsky commented Dec 2, 2019

Fix #4930

}

private CapabilityBooleanType getBoolean(Cursor cursor, String columnName) {
return CapabilityBooleanType.fromValue(cursor.getInt(cursor.getColumnIndex(columnName)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

CapabilityBooleanType.fromValue can return null - is it safe? While here, we could revisit this behaviour and maybe make it non-null?

Copy link
Member Author

Choose a reason for hiding this comment

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

I created a new issue for this, so we can fix this separately.

templateObject.getString("extension")));
templateObject.getString("name"),
templateObject.optString("preview"),
Template.Type.valueOf(templateObject.getString("type")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if conversion fails, for example due to a corruption of future data format change?
This can be addressed by providing custom constructor method with defensive behaviour.

Also, I find having a test case for data format conversions helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

How would you do this?
Create a constructor that accepts a JSONObject? And do the "getInt", "getString" there?

And what do you mean with "defensive behaviour"? If it fails, do not create the template?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It input is invalid, return sane default, ie. switch default case. Provided it makes sense to continue in such situation...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@ezaquarii ezaquarii Dec 20, 2019

Choose a reason for hiding this comment

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

How would you do this?

Something like this:

    enum Type {
        UNKNOWN,
        ALPHA,
        BRAVO;

        Type parse(String type) {
            switch (type.toLowerCase(Locale.US)) {
                case "alpha": return ALPHA;
                case "bravo": return BRAVO;
                default: return UNKNOWN;
            }
        }
    }

Or maybe use a temporary variable if linter complains about multiple returns.
Same in in Kotlin:

enum class Type {
        UNKNOWN,
        ALPHA,
        BRAVO;

        fun parse(type: String) = when (type.toLowerCase(Locale.US)) {
            "alpha" -> ALPHA
            "bravo" -> BRAVO
            else -> UNKNOWN
        }
    }

Enum.valueOf() will throw if you give it an invalid string:
https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#valueOf(java.lang.Class,%20java.lang.String)
causing a hard crash.

List<Integer> toHide,
OCCapability capability
) {
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use DeviceInfo here with editorSupported property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point 👍

item.setTitle(String.format(openWith, productName));
}
@Nullable
public static Editor getEditor(ContentResolver contentResolver, Account account, 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.

Can we use User object? toPlatformAccount() can be used to satisfy ArbitraryDataProvider dependency, but this way we'd make FileMenuFilter.getEditor() calls using new API. ArbitraryDataProvider would catch up later.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I forget about this all the time :/

}
@Nullable
public static Editor getEditor(ContentResolver contentResolver, Account account, String mimeType) {
String json = new ArbitraryDataProvider(contentResolver).getValue(account, ArbitraryDataProvider.DIRECT_EDITING);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can it be null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, for example if text app is not installed on server.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd consider makeing it explicit by wrapping it in Java8 Optional<Editor> (we have a port in com.nextcloud.client.jav.util), as this is truly optional feature. This way nobody will accidentally trip over null.

We have Optional ported from Java8 stdlib, so it is independent from Android Runtime version and can be used safely.

BTW If you expect it to be non-null, optionals can be unwrapped quickly with Optional.orElseThrow.

boolean isLoading = false;
if (parentFolder.isExpired()) {
final ReloadFolderDocumentTask task = new ReloadFolderDocumentTask(parentFolder, result -> {
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we inject it via contructor? It's de factor another dependency and we just made it less visible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately not as this can be called directly via Android (e.g. if you open up any app that can read storage access framework.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm... Is MainApp started in such case? I'd say it is and Dagger should be enabled by that time.

I think we decided not Dagger-ize this component for some reason - can't remember exactly what it was...

initLoadingScreen();
}

// TODO really here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not :)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is really the right place as TextEditor can use it, but RichDocumentsEditor overwrites it.
But the later one will be removed with EOL of NC19.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put a comment that this code is scheduled for retirement in near future?

This Todo line is a bit scary :)

appVersion = pInfo.versionName
}
} catch (e: NameNotFoundException) {
Log_OC.e(this, "Trying to get packageName", e.cause)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have AppInfo and DeviceInfo to provide data about runtime environment. Both appVersion and androidVersion could be moved there.

This way we don't need to do all the error handling in UI and we can inject them in tests. This exception is effectively unhandled, leading to undefined behaviour.

Not that we expect it to fail... We can assume that if it fails, it will be because of a platform bug or some "security features", possibly causing some sort of unexplained "glitch".

I'd consider moving that to AppInfo and throw RuntimeException("Platform bug?", e) if we can't retrieve it.

Copy link
Member Author

@tobiasKaminsky tobiasKaminsky Dec 20, 2019

Choose a reason for hiding this comment

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

Done, but I chose not to throw an exception, but return "n/a" as it is not critical to have the exact number.

@tobiasKaminsky tobiasKaminsky changed the base branch from directEditing to master January 6, 2020 09:15
@tobiasKaminsky tobiasKaminsky force-pushed the createText branch 2 times, most recently from e51be4b to 1268eb1 Compare January 6, 2020 14:10
@codecov
Copy link

codecov bot commented Jan 6, 2020

Codecov Report

Merging #4915 into master will decrease coverage by 0.16%.
The diff coverage is 0.96%.

@@             Coverage Diff              @@
##             master    #4915      +/-   ##
============================================
- Coverage     17.79%   17.62%   -0.17%     
  Complexity        3        3              
============================================
  Files           389      392       +3     
  Lines         32890    33105     +215     
  Branches       4626     4647      +21     
============================================
- Hits           5852     5835      -17     
- Misses        26082    26315     +233     
+ Partials        956      955       -1
Impacted Files Coverage Δ Complexity Δ
...java/com/nextcloud/client/di/ComponentsModule.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...ain/java/com/owncloud/android/db/ProviderMeta.java 84.61% <ø> (ø) 0 <0> (ø) ⬇️
...m/owncloud/android/ui/adapter/TemplateAdapter.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...ndroid/ui/asynctasks/RichDocumentsLoadUrlTask.java 0% <0%> (ø) 0 <0> (?)
...ndroid/ui/dialog/ChooseTemplateDialogFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...droid/ui/fragment/OCFileListBottomSheetDialog.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...owncloud/android/files/FetchTemplateOperation.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...cloud/android/ui/preview/PreviewMediaFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...d/android/ui/asynctasks/TextEditorLoadUrlTask.java 0% <0%> (ø) 0 <0> (?)
.../owncloud/android/ui/activity/TextEditorWebView.kt 0% <0%> (ø) 0 <0> (ø) ⬇️
... and 24 more

- abstract EditorWebView
- support direct editing endpoint
Create new files via direct editing

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

Codacy

329

Lint

TypemasterPR
Warnings7474
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 Warnings71
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings106
Security Warnings44
Dodgy code Warnings138
Total412

@tobiasKaminsky tobiasKaminsky added this to the Nextcloud App 3.10.0 milestone Jan 7, 2020
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
======
- Added 1
           

Complexity increasing per file
==============================
- src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java  7
- src/main/java/com/owncloud/android/ui/asynctasks/RichDocumentsLoadUrlTask.java  3
- src/main/java/com/owncloud/android/ui/asynctasks/TextEditorLoadUrlTask.java  4
- src/main/java/com/nextcloud/client/appinfo/AppInfoImpl.java  2
- src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java  3
- src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java  4
         

Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java  -1
+ src/main/java/com/owncloud/android/ui/adapter/TemplateAdapter.java  -2
+ src/main/java/com/owncloud/android/ui/activity/EditorWebView.java  -4
         

See the complete overview on Codacy


private void filterSync(List<Integer> toShow, List<Integer> toHide, boolean synchronizing) {
if (mFiles.isEmpty() || (!anyFileDown() && !containsFolder()) || synchronizing) {
if (files.isEmpty() || (!anyFileDown() && !containsFolder()) || synchronizing) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Codacy Issue found: Useless parentheses.

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12148.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

329

Lint

TypemasterPR
Warnings7474
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 Warnings71
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings106
Security Warnings44
Dodgy code Warnings138
Total412

@tobiasKaminsky
Copy link
Member Author

Tested by Julius

@tobiasKaminsky tobiasKaminsky merged commit 6cb0f10 into master Jan 8, 2020
@delete-merged-branch delete-merged-branch bot deleted the createText branch January 8, 2020 05:24
tobiasKaminsky added a commit that referenced this pull request Jan 9, 2020
8751c85 Merge pull request #5120 from nextcloud/spinner
9d2b80d spinner: if primary color is white, use grey
de269b2 Merge pull request #5115 from nextcloud/311bump
3baa9fe Merge pull request #5118 from nextcloud/fastlane
ee6e7ce fix fastlane RC
1343ba0 Merge pull request #5114 from nextcloud/richWorkspaceFixes
1ec8b06 - fix not clickable rich workspace area - fix crash on first loading
62aaed7 bump to 3.11 alpha
9a47a4d Merge pull request #5107 from nextcloud/whiteHeader
6cb0f10 Merge pull request #4915 from nextcloud/createText
3011097 [tx-robot] updated from transifex
248fe1a daily dev 20200108
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.

Create new text document

4 participants