Skip to content
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

Fix upload list comparator to make it respect the comparator contract #4245

Merged
merged 1 commit into from
Aug 20, 2019

Conversation

fogninid
Copy link
Member

the current comparator implementation is correct only if there is only one "isUpdating" file in the array.
This can happen for example as a result of #4244, or if concurrent uploads will be impelmented.

Change the implementation to make it follow the simpler Comparator.thenComparing pattern

@fogninid fogninid force-pushed the fixUploadListComparator branch from 5f52998 to 6541907 Compare July 20, 2019 15:37
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.

While being here, I'm sure we can apply Scout's Rule #1 - leave the place cleaner than we found it. ;)

Also, if possible, could we write the test in Kotlin? The goal is to accelerate and encourage it's adoption, as Kotlin is de facto primary development language for Android now.

@fogninid fogninid force-pushed the fixUploadListComparator branch 2 times, most recently from 965bcad to afd4315 Compare July 23, 2019 14:22
@codecov
Copy link

codecov bot commented Jul 23, 2019

Codecov Report

Merging #4245 into master will increase coverage by 0.05%.
The diff coverage is 62.06%.

@@             Coverage Diff              @@
##             master    #4245      +/-   ##
============================================
+ Coverage     15.99%   16.05%   +0.05%     
  Complexity        1        1              
============================================
  Files           340      341       +1     
  Lines         31155    31158       +3     
  Branches       4424     4421       -3     
============================================
+ Hits           4983     5002      +19     
+ Misses        25313    25295      -18     
- Partials        859      861       +2
Impacted Files Coverage Δ Complexity Δ
...rc/main/java/com/owncloud/android/db/OCUpload.java 34.23% <0%> (ø) 0 <0> (ø) ⬇️
...owncloud/android/ui/adapter/UploadListAdapter.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...java/com/owncloud/android/db/OCUploadComparator.kt 75% <75%> (ø) 0 <0> (?)
.../java/com/owncloud/android/utils/DisplayUtils.java 22.97% <0%> (-1.28%) 0% <0%> (ø)
...in/java/com/owncloud/android/datamodel/OCFile.java 64.67% <0%> (-0.92%) 0% <0%> (ø)
...loud/android/datamodel/ThumbnailsCacheManager.java 35.66% <0%> (-0.56%) 0% <0%> (ø)
...ncloud/android/ui/fragment/OCFileListFragment.java 24.73% <0%> (+0.26%) 0% <0%> (ø) ⬇️
...owncloud/android/ui/adapter/OCFileListAdapter.java 31.15% <0%> (+0.63%) 0% <0%> (ø) ⬇️
...va/com/owncloud/android/ui/SquareLinearLayout.java 50% <0%> (+50%) 0% <0%> (ø) ⬇️

@nextcloud-android-bot
Copy link
Collaborator

@fogninid fogninid force-pushed the fixUploadListComparator branch 2 times, most recently from 88e6465 to f19f5f9 Compare July 23, 2019 15:37
@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii
Copy link
Collaborator

ezaquarii commented Jul 26, 2019 via email

@fogninid fogninid force-pushed the fixUploadListComparator branch 2 times, most recently from 6f8aeb3 to 54529f9 Compare July 31, 2019 08:22
@nextcloud nextcloud deleted a comment Jul 31, 2019
@nextcloud nextcloud deleted a comment Jul 31, 2019
@nextcloud nextcloud deleted a comment Jul 31, 2019
@nextcloud nextcloud deleted a comment Jul 31, 2019
@fogninid fogninid force-pushed the fixUploadListComparator branch from 54529f9 to 00aacf1 Compare July 31, 2019 10:01
@nextcloud nextcloud deleted a comment Jul 31, 2019
@nextcloud nextcloud deleted a comment Jul 31, 2019
Signed-off-by: Daniele Fognini <dfogni@gmail.com>
@fogninid fogninid force-pushed the fixUploadListComparator branch from 00aacf1 to 51ff5c3 Compare August 1, 2019 11:36
@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/10214.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 nextcloud deleted a comment Aug 1, 2019
@nextcloud nextcloud deleted a comment Aug 1, 2019
@nextcloud nextcloud deleted a comment from fogninid Aug 1, 2019
@nextcloud nextcloud deleted a comment from ezaquarii Aug 1, 2019
@nextcloud nextcloud deleted a comment from fogninid Aug 1, 2019
@nextcloud-android-bot
Copy link
Collaborator

Codacy

281

Lint

TypemasterPR
Warnings5959
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings25
Correctness Warnings70
Internationalization Warnings12
Malicious code vulnerability Warnings4
Multithreaded correctness Warnings9
Performance Warnings120
Security Warnings47
Dodgy code Warnings136
Total423

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings25
Correctness Warnings70
Internationalization Warnings12
Malicious code vulnerability Warnings4
Multithreaded correctness Warnings9
Performance Warnings120
Security Warnings47
Dodgy code Warnings136
Total423

@fogninid
Copy link
Member Author

fogninid commented Aug 1, 2019

@nextcloud-android-bot well done for deleting the unresolved conversation /s

I added the @Suppress("ReturnCount") because I understand that kotlin.Comparator is just a typealias for the java class, so Comparator.nullsFirst(...) would crash at Runtime because java on android does not have it for old API levels

@ezaquarii
Copy link
Collaborator

ezaquarii commented Aug 1, 2019

I added the @Suppress("ReturnCount") because I understand that kotlin.Comparator is just a typealias

Ok, let's go with the old impl and not spend more time massaging it into unreachable perfection.

Thanks. Awesome work with valuable analysis as a byproduct.

@AndyScherzinger AndyScherzinger changed the title fix upload list comparator to make it respect the comparator contract Fix upload list comparator to make it respect the comparator contract Aug 2, 2019
@AndyScherzinger AndyScherzinger mentioned this pull request Aug 2, 2019
68 tasks
@tobiasKaminsky
Copy link
Member

Thanks for your awesome work!

@tobiasKaminsky tobiasKaminsky merged commit f26095f into nextcloud:master Aug 20, 2019
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.8.0 milestone Aug 20, 2019
tobiasKaminsky added a commit that referenced this pull request Aug 21, 2019
b36067d Merge pull request #4294 from AlexNi245/#2216-activity-data-divers-design
9624019 activity header has now the same font size as a activity element
fa11565 fixed issue  Avoid reassigning parameters such as 'itemPosition'
5a3db5e replace do while loop in getHeaderPositionForItem with while loop
1dd2a5a change naming of Canvas c to Canvas canvas
f4e964e change class name of ActivityListItemDecoration to StickyHeaderItemDecoration, which is more generic
52a7ffe add license text
6ffa9d0 remove duplicate entry of setContentView
cdd5d38 add getHeaderPositionForItem unit test
0ac5a8b add static import for com.owncloud.android.lib.resources.activities.model.Activity;
4ea9667 unit test for isHeader(int pos)
b61f9e0 format ActivityListAdapter
9012f43 set visibility from ActivityViewHeaderHolder back to protected
7a30070 remove unnecessary TAG field and replace nested if statement with && to fix codeacy-bot issues
a26a895 apply changes to java doc
c41dd38 optimize imports
b4764f7 remove unnecessary files
792a6b9 finish implementation of sticky header implementation. This feature was created according to the this implementation : https://stackoverflow.com/questions/32949971/how-can-i-make-sticky-headers-in-recyclerview-without-external-lib
13e7aff increase height of header element and set backgroundcolor to white
a184345 first implementation of sticky header logic.
cd3d8dc start to implement sticky header behavior
259e106 Merge pull request #4355 from nextcloud/drawer
caf1842 drawer: show only server address
cb7d4a3 revert to old image (#4356)
7e44fec revert to old image
f7c4eec Merge pull request #4345 from nextcloud/push
a3fda5a no need to use owncloudClient
9a023c6 Check if app is excluded from battery optimization (#3589)
527c5db Use conscrypt (#4314)
6014e90 use conscrypt
5373660 Provide a banal 'paste' postmessage implementation. (#4189)
68cebf8 revert DeviceModule back to Kotlin
969ce78 Drone: update FindBugs results to reflect reduced error/warning count [skip ci]
f26095f Merge pull request #4245 from fogninid/fixUploadListComparator
e72a789 show on special vendors "disable power check" in auto upload menu - tint button - change logic when to show battery warning
c8173c3 Use reloading on photo view (#2250)
c38dcf3 Delete temp file on receive external files (#4349)
c155edf Merge pull request #4347 from nextcloud/blacklistThumbnail
a03ff84 daily dev 20190820
@fogninid fogninid deleted the fixUploadListComparator branch August 22, 2019 10:26
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.

5 participants