-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Create text #4915
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
Create text #4915
Conversation
5e60212 to
a03a6cf
Compare
198c39b to
c8aa596
Compare
028ea47 to
2bc455e
Compare
c8aa596 to
e0fa258
Compare
3a2e573 to
0d84a2d
Compare
| } | ||
|
|
||
| private CapabilityBooleanType getBoolean(Cursor cursor, String columnName) { | ||
| return CapabilityBooleanType.fromValue(cursor.getInt(cursor.getColumnIndex(columnName))); |
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.
CapabilityBooleanType.fromValue can return null - is it safe? While here, we could revisit this behaviour and maybe make it non-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.
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")), |
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.
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.
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.
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?
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.
It input is invalid, return sane default, ie. switch default case. Provided it makes sense to continue in such situation...
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.
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.
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) { |
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 could use DeviceInfo here with editorSupported property.
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.
Good point 👍
| item.setTitle(String.format(openWith, productName)); | ||
| } | ||
| @Nullable | ||
| public static Editor getEditor(ContentResolver contentResolver, Account account, 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.
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.
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.
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); |
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.
Can it 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.
Yes, for example if text app is not installed on server.
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.
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()); |
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.
Can we inject it via contructor? It's de factor another dependency and we just made it less visible.
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.
Unfortunately not as this can be called directly via Android (e.g. if you open up any app that can read storage access framework.
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.
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? |
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.
Probably not :)
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.
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.
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.
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) |
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 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.
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.
Done, but I chose not to throw an exception, but return "n/a" as it is not critical to have the exact number.
src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java
Show resolved
Hide resolved
src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java
Show resolved
Hide resolved
e51be4b to
1268eb1
Compare
Codecov Report
@@ 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
|
93a0712 to
62b6edd
Compare
- 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>
62b6edd to
74f8a72
Compare
Codacy329Lint
SpotBugs (new)
SpotBugs (master)
|
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
|
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) { |
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: Useless parentheses.
|
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12148.apk |
Codacy329Lint
SpotBugs (new)
SpotBugs (master)
|
|
Tested by Julius |
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

Fix #4930