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

Migrate simple cases of get current account to get user #4853

Merged

Conversation

ezaquarii
Copy link
Collaborator

@ezaquarii ezaquarii commented Nov 18, 2019

This branch is an attempt to migrate all trivial use cases of UserAccountManager.getCurrentAccount() to UserAccountManager.getUser(), leveraging User.toPlatformAccount() and User.toOwnCloudAccount() APIs whenever refactoring becomes problematic or too risky.

Since UserAccountManager is injected in top-level component, such as Activities (top), this PR shall open path to migration of internal components, deeper in the object hierarchy (bottom).

My initial plan to start from internal componentsand taking migration up to Activity/Fragment/Service level - botton-top approach - turned out to not be feasible, because various internal componetns require refactoring of the callers anyway (top) atd those refactorings spill horribly all over the codebase.

I try to keep the risk of this change in reasonable bounds, but it will require complehensive application testing nevertheless.

@ezaquarii ezaquarii self-assigned this Nov 18, 2019
@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch from 097addd to e6fc540 Compare November 19, 2019 00:40
@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch 2 times, most recently from 0779a6b to 84b0849 Compare November 21, 2019 21:05
@ezaquarii ezaquarii changed the title [WIP] Migrate simple cases of get current account to get user Migrate simple cases of get current account to get user Nov 22, 2019
@tobiasKaminsky
Copy link
Member

I guess this needs to be rebased on master, as newUser PR is now in.

@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch from 84b0849 to faa9d77 Compare November 22, 2019 18:51
@codecov
Copy link

codecov bot commented Nov 22, 2019

Codecov Report

Merging #4853 into master will increase coverage by 0.06%.
The diff coverage is 15.38%.

@@             Coverage Diff              @@
##             master    #4853      +/-   ##
============================================
+ Coverage     17.62%   17.69%   +0.06%     
  Complexity        3        3              
============================================
  Files           383      384       +1     
  Lines         32509    32528      +19     
  Branches       4587     4588       +1     
============================================
+ Hits           5731     5757      +26     
+ Misses        25857    25848       -9     
- Partials        921      923       +2
Impacted Files Coverage Δ Complexity Δ
...m/nextcloud/client/account/UserAccountManager.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...m/owncloud/android/ui/adapter/TemplateAdapter.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...ndroid/ui/dialog/ChooseTemplateDialogFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...oud/android/ui/activity/NotificationsActivity.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...droid/providers/DiskLruImageCacheFileProvider.java 9.3% <0%> (ø) 0 <0> (ø) ⬇️
...i/fragment/contactsbackup/ContactListFragment.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...loud/android/ui/fragment/ExtendedListFragment.java 51.81% <0%> (-0.16%) 0 <0> (ø)
.../android/ui/trashbin/RemoteTrashbinRepository.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...loud/android/ui/activities/ActivitiesActivity.java 0% <0%> (ø) 0 <0> (ø) ⬇️
.../ui/activities/data/files/FilesServiceApiImpl.java 0% <0%> (ø) 0 <0> (ø) ⬇️
... and 51 more

@nextcloud nextcloud deleted a comment from ezaquarii Nov 22, 2019
@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch from 522e79f to 33afcbc Compare November 22, 2019 20:36
@nextcloud nextcloud deleted a comment from ezaquarii Nov 22, 2019
@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch 3 times, most recently from c3e5f70 to dc4f44a Compare November 22, 2019 23:09
@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch 2 times, most recently from c2473b4 to 436b564 Compare November 24, 2019 23:57
@nextcloud-android-bot
Copy link
Collaborator

boolean isSearchSupported(@Nullable Account account);

@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

can you add here, what to use instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

JavaDoc updated.

public OwnCloudClient create(User user) throws CreationException {
try {
return OwnCloudClientFactory.createOwnCloudClient(user.toPlatformAccount(), context);
} catch (OperationCanceledException|AuthenticatorException|IOException|AccountUtils.AccountNotFoundException e) {
Copy link
Member

Choose a reason for hiding this comment

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

as this is too long, please also line wrap it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Long exceptions list reformatted into vertical.

@@ -217,8 +214,8 @@ private Cursor searchForUsersOrGroups(Uri uri) {
Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();

FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing()
FileDataStorageManager manager = new FileDataStorageManager(user.toPlatformAccount(), getContext().getContentResolver());
Copy link
Member

Choose a reason for hiding this comment

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

line wrap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lines broken.

Account account = accountManager.getCurrentAccount();
GetActivityListTask getActivityListTask = new GetActivityListTask(account, accountManager, lastGiven, callback);
User user = accountManager.getUser();
GetActivityListTask getActivityListTask = new GetActivityListTask(user.toPlatformAccount(), accountManager, lastGiven, callback);
Copy link
Member

Choose a reason for hiding this comment

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

line wrap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lines broken

@tobiasKaminsky
Copy link
Member

Nice! Again this is a great PR!
I cannot express how much valuable your help is ❤️

Some very small issues and then we can merge.

Migrate trivially convertible uses of getCurrentAccount()
to new user model - getUser().

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
@ezaquarii ezaquarii force-pushed the migrate-simple-cases-of-get-current-account-to-get-user branch from 1c2ae46 to a7eb714 Compare November 25, 2019 08:54
Copy link
Collaborator Author

@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.

All issues addressed.

@ezaquarii
Copy link
Collaborator Author

@tobiasKaminsky Please bear in mind that #4884 is causing CI to fail sporadicaly. Just restart the build if this particular test fails.

drone and others added 2 commits November 25, 2019 12:08
@nextcloud-android-bot
Copy link
Collaborator

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

Issues
======
+ Solved 3
- Added 3
           

Complexity increasing per file
==============================
- src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java  2
- src/main/java/com/owncloud/android/ui/trashbin/RemoteTrashbinRepository.java  1
- src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java  2
         

Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java  -2
+ src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java  -3
         

See the complete overview on Codacy

String accountName = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
if(accountName != null && optionalUser.isPresent()) {
User user = optionalUser.get();
if (user.getAccountName().equalsIgnoreCase(accountName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (optionalUser.isPresent()) {
mLastDisplayedAccount = optionalUser.get().toPlatformAccount();
} else {
mLastDisplayedAccount = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional<User> optionalUser = getUser();
if (optionalUser.isPresent() && accountName != null) {
User user = optionalUser.get();
if (!accountName.equalsIgnoreCase(user.getAccountName())) {
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

@nextcloud-android-bot
Copy link
Collaborator

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

@ezaquarii
Copy link
Collaborator Author

@tobiasKaminsky UserAccountManagerImplTest.java:43 failed for some reason. This is not a code that I touched and I don't suspect it to fail. The method under test contacts backend so this can be geuinely flaky test. I restarted it now.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

312

Lint

TypemasterPR
Warnings5959
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings117
Security Warnings44
Dodgy code Warnings134
Total418

SpotBugs (master)

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

@tobiasKaminsky
Copy link
Member

Ha finally greeeen :-)
(Except of codacy, which is ok)

@tobiasKaminsky tobiasKaminsky merged commit e92daa2 into master Nov 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the migrate-simple-cases-of-get-current-account-to-get-user branch November 26, 2019 13:04
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.10.0 milestone Nov 26, 2019
tobiasKaminsky added a commit that referenced this pull request Nov 27, 2019
e92daa2 Merge pull request #4853 from nextcloud/migrate-simple-cases-of-get-current-account-to-get-user
99d9a69 Merge pull request #4885 from nextcloud/disable_android_backup_qa
10960bf [tx-robot] updated from transifex
9f24b25 [tx-robot] updated from transifex
b7876c4 disable GoogleAppIndexingWarning lint check
11687c6 Drone: update FindBugs results to reflect reduced error/warning count [skip ci]
80fb800 Merge commit 'a7eb7148fa0ceb42981366eb2ddcf0ff921e6a55'
b91136c Disable android backup on the QA app
a7eb714 Migrate simple cases of getCurrentAccount() to getUser()
6249a06 daily dev 20191123
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.

4 participants