Migrate FileMenuFiler to User model

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2020-07-09 22:25:35 +01:00
parent a7b90ed588
commit 69414303a8
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
14 changed files with 62 additions and 71 deletions

View file

@ -21,7 +21,6 @@
package com.owncloud.android.files;
import android.accounts.Account;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Build;
@ -63,7 +62,6 @@ public class FileMenuFilter {
private int numberOfAllFiles;
private Collection<OCFile> files;
private ComponentsGetter componentsGetter;
private Account account;
private Context context;
private boolean overflowMenu;
private DeviceInfo deviceInfo;
@ -74,14 +72,14 @@ public class FileMenuFilter {
*
* @param numberOfAllFiles Number of all displayed files
* @param files Collection of {@link OCFile} file targets of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param componentsGetter Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param overflowMenu true if the overflow menu items are being filtered
* @param deviceInfo Device information provider
* @param user currently active user
*/
public FileMenuFilter(int numberOfAllFiles,
Collection<OCFile> files,
Account account,
ComponentsGetter componentsGetter,
Context context,
boolean overflowMenu,
@ -90,7 +88,6 @@ public class FileMenuFilter {
) {
this.numberOfAllFiles = numberOfAllFiles;
this.files = files;
this.account = account;
this.componentsGetter = componentsGetter;
this.context = context;
this.overflowMenu = overflowMenu;
@ -102,20 +99,19 @@ public class FileMenuFilter {
* Constructor
*
* @param file {@link OCFile} target of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param componentsGetter Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param overflowMenu true if the overflow menu items are being filtered
* @param user currently active user
*/
public FileMenuFilter(OCFile file,
Account account,
ComponentsGetter componentsGetter,
Context context,
boolean overflowMenu,
DeviceInfo deviceInfo,
User user
) {
this(1, Collections.singletonList(file), account, componentsGetter, context, overflowMenu, deviceInfo, user);
this(1, Collections.singletonList(file), componentsGetter, context, overflowMenu, deviceInfo, user);
}
/**
@ -193,7 +189,7 @@ public class FileMenuFilter {
boolean inSingleFileFragment,
boolean isMediaSupported) {
boolean synchronizing = anyFileSynchronizing();
OCCapability capability = componentsGetter.getStorageManager().getCapability(account.name);
OCCapability capability = componentsGetter.getStorageManager().getCapability(user.getAccountName());
boolean endToEndEncryptionEnabled = capability.getEndToEndEncryption().isTrue();
filterEdit(toShow, toHide, capability);
@ -433,7 +429,7 @@ public class FileMenuFilter {
private boolean anyFileSynchronizing() {
boolean synchronizing = false;
if (componentsGetter != null && !files.isEmpty() && account != null) {
if (componentsGetter != null && !files.isEmpty() && user != null) {
OperationsServiceBinder opsBinder = componentsGetter.getOperationsServiceBinder();
FileUploaderBinder uploaderBinder = componentsGetter.getFileUploaderBinder();
FileDownloaderBinder downloaderBinder = componentsGetter.getFileDownloaderBinder();
@ -448,7 +444,7 @@ public class FileMenuFilter {
boolean synchronizing = false;
if (opsBinder != null) {
for (Iterator<OCFile> iterator = files.iterator(); !synchronizing && iterator.hasNext(); ) {
synchronizing = opsBinder.isSynchronizing(account, iterator.next());
synchronizing = opsBinder.isSynchronizing(user, iterator.next());
}
}
return synchronizing;
@ -458,7 +454,7 @@ public class FileMenuFilter {
boolean downloading = false;
if (downloaderBinder != null) {
for (Iterator<OCFile> iterator = files.iterator(); !downloading && iterator.hasNext(); ) {
downloading = downloaderBinder.isDownloading(account, iterator.next());
downloading = downloaderBinder.isDownloading(user, iterator.next());
}
}
return downloading;
@ -468,7 +464,7 @@ public class FileMenuFilter {
boolean uploading = false;
if (uploaderBinder != null) {
for (Iterator<OCFile> iterator = files.iterator(); !uploading && iterator.hasNext(); ) {
uploading = uploaderBinder.isUploading(account, iterator.next());
uploading = uploaderBinder.isUploading(user, iterator.next());
}
}
return uploading;

View file

@ -335,11 +335,11 @@ public class FileDownloader extends Service
* If 'file' is a directory, returns 'true' if any of its descendant files is downloading or
* waiting to download.
*
* @param account ownCloud account where the remote file is stored.
* @param user user where the remote file is stored.
* @param file A file that could be in the queue of downloads.
*/
public boolean isDownloading(Account account, OCFile file) {
return account != null && file != null && mPendingDownloads.contains(account.name, file.getRemotePath());
public boolean isDownloading(User user, OCFile file) {
return user != null && file != null && mPendingDownloads.contains(user.getAccountName(), file.getRemotePath());
}

View file

@ -1185,15 +1185,15 @@ public class FileUploader extends Service
* Warning: If remote file exists and target was renamed the original file is being returned here. That is, it
* seems as if the original file is being updated when actually a new file is being uploaded.
*
* @param account Owncloud account where the remote file will be stored.
* @param user user where the remote file will be stored.
* @param file A file that could be in the queue of pending uploads
*/
public boolean isUploading(Account account, OCFile file) {
if (account == null || file == null) {
public boolean isUploading(User user, OCFile file) {
if (user == null || file == null) {
return false;
}
return mPendingUploads.contains(account.name, file.getRemotePath());
return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
}
public boolean isUploadingNow(OCUpload upload) {

View file

@ -366,12 +366,12 @@ public class OperationsService extends Service {
* If 'file' is a directory, returns 'true' if some of its descendant files is downloading
* or waiting to download.
*
* @param account ownCloud account where the remote file is stored.
* @param user user where the remote file is stored.
* @param file File to check if something is synchronizing
* / downloading / uploading inside.
*/
public boolean isSynchronizing(Account account, OCFile file) {
return mSyncFolderHandler.isSynchronizing(account, file.getRemotePath());
public boolean isSynchronizing(User user, OCFile file) {
return mSyncFolderHandler.isSynchronizing(user, file.getRemotePath());
}
}

View file

@ -27,6 +27,7 @@ import android.os.Looper;
import android.os.Message;
import android.util.Pair;
import com.nextcloud.client.account.User;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
@ -71,14 +72,14 @@ class SyncFolderHandler extends Handler {
* Returns True when the folder located in 'remotePath' in the ownCloud account 'account', or any of its
* descendants, is being synchronized (or waiting for it).
*
* @param account ownCloud account where the remote folder is stored.
* @param user user where the remote folder is stored.
* @param remotePath The path to a folder that could be in the queue of synchronizations.
*/
public boolean isSynchronizing(Account account, String remotePath) {
if (account == null || remotePath == null) {
public boolean isSynchronizing(User user, String remotePath) {
if (user == null || remotePath == null) {
return false;
}
return mPendingOperations.contains(account.name, remotePath);
return mPendingOperations.contains(user.getAccountName(), remotePath);
}
@Override

View file

@ -1939,7 +1939,7 @@ public class FileDisplayActivity extends FileActivity
private void requestForDownload() {
User user = getUser().orElseThrow(RuntimeException::new);
//if (!mWaitingToPreview.isDownloading()) {
if (!mDownloaderBinder.isDownloading(user.toPlatformAccount(), mWaitingToPreview)) {
if (!mDownloaderBinder.isDownloading(user, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_USER, user);
i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
@ -2032,7 +2032,7 @@ public class FileDisplayActivity extends FileActivity
private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
final User currentUser = getUser().orElseThrow(RuntimeException::new);
if (!mDownloaderBinder.isDownloading(currentUser.toPlatformAccount(), mWaitingToPreview)) {
if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_USER, currentUser);
i.putExtra(FileDownloader.EXTRA_FILE, file);

View file

@ -510,17 +510,17 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user.toPlatformAccount(), file)) {
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
//synchronizing
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user.toPlatformAccount(), file)) {
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
// downloading
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user.toPlatformAccount(), file)) {
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
//uploading
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);

View file

@ -404,20 +404,19 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
private void prepareOptionsMenu(Menu menu) {
if (containerActivity.getStorageManager() != null) {
Account currentAccount = containerActivity.getStorageManager().getAccount();
User currentUser = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
getFile(),
currentAccount,
containerActivity,
getActivity(),
false,
deviceInfo,
accountManager.getUser()
currentUser
);
mf.filter(menu,
true,
accountManager.isMediaStreamingSupported(currentAccount));
currentUser.getServer().getVersion().isMediaStreamingSupported());
}
if (getFile().isFolder()) {
@ -564,8 +563,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
if (transferring
|| (downloaderBinder != null && downloaderBinder.isDownloading(user.toPlatformAccount(), file))
|| (uploaderBinder != null && uploaderBinder.isUploading(user.toPlatformAccount(), file))) {
|| (downloaderBinder != null && downloaderBinder.isDownloading(user, file))
|| (uploaderBinder != null && uploaderBinder.isUploading(user, file))) {
setButtonsForTransferring();
} else if (file.isDown()) {
@ -680,11 +679,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
//if (getFile().isDownloading()) {
if (downloaderBinder != null && downloaderBinder.isDownloading(user.toPlatformAccount(), getFile())) {
if (downloaderBinder != null && downloaderBinder.isDownloading(user, getFile())) {
progressText.setText(R.string.downloader_download_in_progress_ticker);
}
else {
if (uploaderBinder != null && uploaderBinder.isUploading(user.toPlatformAccount(), getFile())) {
if (uploaderBinder != null && uploaderBinder.isUploading(user, getFile())) {
progressText.setText(R.string.uploader_upload_in_progress_ticker);
}
}

View file

@ -24,11 +24,9 @@
*/
package com.owncloud.android.ui.fragment;
import android.accounts.Account;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Build;
@ -509,17 +507,17 @@ public class OCFileListFragment extends ExtendedListFragment implements
public void onOverflowIconClicked(OCFile file, View view) {
PopupMenu popup = new PopupMenu(getActivity(), view);
popup.inflate(R.menu.item_file);
Account currentAccount = ((FileActivity) getActivity()).getAccount();
User currentUser = ((FileActivity) getActivity()).getUser().orElseThrow(IllegalStateException::new);
FileMenuFilter mf = new FileMenuFilter(mAdapter.getFiles().size(),
Collections.singleton(file),
currentAccount,
mContainerActivity, getActivity(),
true,
deviceInfo,
accountManager.getUser());
final boolean isMediaStreamingSupported = currentUser.getServer().getVersion().isMediaStreamingSupported();
mf.filter(popup.getMenu(),
true,
accountManager.isMediaStreamingSupported(currentAccount));
isMediaStreamingSupported);
popup.setOnMenuItemClickListener(item -> {
Set<OCFile> checkedFiles = new HashSet<>();
checkedFiles.add(file);
@ -670,11 +668,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
Set<OCFile> checkedFiles = mAdapter.getCheckedItems();
String title = getResources().getQuantityString(R.plurals.items_selected_count, checkedCount, checkedCount);
mode.setTitle(title);
Account currentAccount = ((FileActivity) getActivity()).getAccount();
User currentUser = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
mAdapter.getFiles().size(),
checkedFiles,
currentAccount,
mContainerActivity,
getActivity(),
false,
@ -682,9 +679,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
accountManager.getUser()
);
final boolean isMediaStreamingSupported = currentUser.getServer().getVersion().isMediaStreamingSupported();
mf.filter(menu,
false,
accountManager.isMediaStreamingSupported(currentAccount));
isMediaStreamingSupported);
// Determine if we need to finish the action mode because there are no items selected
if (checkedCount == 0 && !mIsActionModeNew) {
@ -1525,7 +1523,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
final User currentAccount = accountManager.getUser();
final User currentUser = accountManager.getUser();
final RemoteOperation remoteOperation;
if (currentSearchType != SearchType.SHARED_FILTER) {
@ -1546,7 +1544,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
setTitle();
if (getContext() != null && !isCancelled()) {
RemoteOperationResult remoteOperationResult = remoteOperation.execute(
currentAccount.toPlatformAccount(), getContext());
currentUser.toPlatformAccount(), getContext());
FileDataStorageManager storageManager = null;
if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) {

View file

@ -925,23 +925,23 @@ public class FileOperationsHelper {
* @param file OCFile
*/
public void cancelTransference(OCFile file) {
Account account = fileActivity.getAccount();
User currentUser = fileActivity.getUser().orElseThrow(IllegalStateException::new);
if (file.isFolder()) {
OperationsService.OperationsServiceBinder opsBinder =
fileActivity.getOperationsServiceBinder();
if (opsBinder != null) {
opsBinder.cancel(account, file);
opsBinder.cancel(currentUser.toPlatformAccount(), file);
}
}
// for both files and folders
FileDownloaderBinder downloaderBinder = fileActivity.getFileDownloaderBinder();
if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
downloaderBinder.cancel(account, file);
if (downloaderBinder != null && downloaderBinder.isDownloading(currentUser, file)) {
downloaderBinder.cancel(currentUser.toPlatformAccount(), file);
}
FileUploaderBinder uploaderBinder = fileActivity.getFileUploaderBinder();
if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
uploaderBinder.cancel(account, file);
if (uploaderBinder != null && uploaderBinder.isUploading(currentUser, file)) {
uploaderBinder.cancel(currentUser.toPlatformAccount(), file);
}
}

View file

@ -358,7 +358,7 @@ public class PreviewImageActivity extends FileActivity implements
if (mDownloaderBinder == null) {
Log_OC.d(TAG, "requestForDownload called without binder to download service");
} else if (!mDownloaderBinder.isDownloading(getAccount(), file)) {
} else if (!mDownloaderBinder.isDownloading(getUserAccountManager().getUser(), file)) {
final User user = getUser().orElseThrow(RuntimeException::new);
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_USER, user);

View file

@ -55,6 +55,7 @@ import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;
import com.github.chrisbanes.photoview.PhotoView;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.client.di.Injectable;
@ -368,20 +369,19 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
// Update the file
setFile(containerActivity.getStorageManager().getFileById(getFile().getFileId()));
Account currentAccount = containerActivity.getStorageManager().getAccount();
User currentUser = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
getFile(),
currentAccount,
containerActivity,
getActivity(),
false,
deviceInfo,
accountManager.getUser()
currentUser
);
mf.filter(menu,
true,
accountManager.isMediaStreamingSupported(currentAccount));
currentUser.getServer().getVersion().isMediaStreamingSupported());
}
// additional restriction for this fragment

View file

@ -63,9 +63,7 @@ import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.files.StreamMediaFileOperation;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.media.MediaControlView;
@ -348,20 +346,19 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
super.onPrepareOptionsMenu(menu);
if (containerActivity.getStorageManager() != null) {
Account currentAccount = containerActivity.getStorageManager().getAccount();
User currentUser = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
getFile(),
currentAccount,
containerActivity,
getActivity(),
false,
deviceInfo,
accountManager.getUser()
currentUser
);
mf.filter(menu,
true,
accountManager.isMediaStreamingSupported(currentAccount));
currentUser.getServer().getVersion().isMediaStreamingSupported());
}
// additional restriction for this fragment

View file

@ -33,6 +33,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
@ -260,19 +261,18 @@ public class PreviewTextFileFragment extends PreviewTextFragment {
super.onPrepareOptionsMenu(menu);
if (containerActivity.getStorageManager() != null) {
Account currentAccount = containerActivity.getStorageManager().getAccount();
User user = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
getFile(),
currentAccount,
containerActivity,
getActivity(),
false,
deviceInfo,
accountManager.getUser()
user
);
mf.filter(menu,
true,
accountManager.isMediaStreamingSupported(currentAccount));
user.getServer().getVersion().isMediaStreamingSupported());
}
// additional restriction for this fragment