From c4116456fa46539d1ae918487affeaa6b04bd8fa Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Sun, 4 Jul 2021 23:34:36 +0100 Subject: [PATCH] Migrate FileDisplayActivity to User model 1. server version is available from User, so we can skip redundant retrieval via Account 2. last displayed account can be safely changed to User, eliminating name comparison complexities Signed-off-by: Chris Narkiewicz --- .../ui/activity/FileDisplayActivity.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 75b2787485..19316855da 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -26,7 +26,6 @@ package com.owncloud.android.ui.activity; import android.Manifest; -import android.accounts.Account; import android.accounts.AuthenticatorException; import android.app.Activity; import android.content.BroadcastReceiver; @@ -72,7 +71,6 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.files.services.NameCollisionPolicy; -import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; @@ -217,7 +215,7 @@ public class FileDisplayActivity extends FileActivity private SearchView searchView; private PlayerServiceConnection mPlayerConnection; - private Account mLastDisplayedAccount; + private Optional lastDisplayedUser; private int menuItemId = -1; @Inject @@ -388,18 +386,12 @@ public class FileDisplayActivity extends FileActivity } private void checkOutdatedServer() { - Account account = getAccount(); - - if (getResources().getBoolean(R.bool.show_outdated_server_warning) && account != null) { - OwnCloudVersion serverVersion = AccountUtils.getServerVersionForAccount(account, this); - - if (serverVersion == null) { - serverVersion = getCapabilities().getVersion(); - } + Optional user = getUser(); + if (getResources().getBoolean(R.bool.show_outdated_server_warning) && user.isPresent()) { + OwnCloudVersion serverVersion = user.get().getServer().getVersion(); // show outdated warning - if (getResources().getBoolean(R.bool.show_outdated_server_warning) && - MainApp.OUTDATED_SERVER_VERSION.isSameMajorVersion(serverVersion) && + if (MainApp.OUTDATED_SERVER_VERSION.isSameMajorVersion(serverVersion) && getCapabilities().getExtendedSupport().isFalse()) { DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG); } @@ -2422,10 +2414,8 @@ public class FileDisplayActivity extends FileActivity DisplayUtils.setAvatar(user, this, getResources() .getDimension(R.dimen.nav_drawer_menu_avatar_radius), getResources(), mSwitchAccountButton, this); - - final String lastDisplayedAccountName = mLastDisplayedAccount != null ? mLastDisplayedAccount.name : null; - final boolean accountChanged = !user.getAccountName().equals(lastDisplayedAccountName); - if (accountChanged) { + final boolean userChanged = !user.nameEquals(lastDisplayedUser.orElse(null)); + if (userChanged) { Log_OC.d(TAG, "Initializing Fragments in onAccountChanged.."); initFragmentsWithFile(user, file); if (file.isFolder() && TextUtils.isEmpty(searchQuery)) { @@ -2435,11 +2425,7 @@ public class FileDisplayActivity extends FileActivity updateActionBarTitleAndHomeButton(file.isFolder() ? null : file); } } - if (optionalUser.isPresent()) { - mLastDisplayedAccount = optionalUser.get().toPlatformAccount(); - } else { - mLastDisplayedAccount = null; - } + lastDisplayedUser = optionalUser; EventBus.getDefault().post(new TokenPushEvent()); checkForNewDevVersionNecessary(getApplicationContext());