CR changes

This commit is contained in:
Andy Scherzinger 2016-07-20 14:24:03 +02:00
parent 2af26edb0b
commit 71a44db0dd
6 changed files with 57 additions and 52 deletions

View file

@ -35,6 +35,8 @@ import com.owncloud.android.ui.activity.ComponentsGetter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -45,7 +47,7 @@ public class FileMenuFilter {
private static final int SINGLE_SELECT_ITEMS = 1; private static final int SINGLE_SELECT_ITEMS = 1;
private List<OCFile> mFiles; private Collection<OCFile> mFiles;
private ComponentsGetter mComponentsGetter; private ComponentsGetter mComponentsGetter;
private Account mAccount; private Account mAccount;
private Context mContext; private Context mContext;
@ -53,12 +55,12 @@ public class FileMenuFilter {
/** /**
* Constructor * Constructor
* *
* @param targetFiles List of {@link OCFile} file targets of the action to filter in the {@link Menu}. * @param targetFiles Collection of {@link OCFile} file targets of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile. * @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services * @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources. * @param context Android {@link Context}, needed to access build setup resources.
*/ */
public FileMenuFilter(List<OCFile> targetFiles, Account account, ComponentsGetter cg, public FileMenuFilter(Collection<OCFile> targetFiles, Account account, ComponentsGetter cg,
Context context) { Context context) {
mFiles = targetFiles; mFiles = targetFiles;
mAccount = account; mAccount = account;
@ -261,8 +263,8 @@ public class FileMenuFilter {
private boolean anyFileSynchronizing(OperationsServiceBinder opsBinder) { private boolean anyFileSynchronizing(OperationsServiceBinder opsBinder) {
boolean synchronizing = false; boolean synchronizing = false;
if (opsBinder != null) { if (opsBinder != null) {
for (int i=0; !synchronizing && i < mFiles.size(); i++) { for (Iterator<OCFile> iterator = mFiles.iterator(); !synchronizing && iterator.hasNext();) {
synchronizing = opsBinder.isSynchronizing(mAccount, mFiles.get(i)); synchronizing = opsBinder.isSynchronizing(mAccount, iterator.next());
} }
} }
return synchronizing; return synchronizing;
@ -271,8 +273,8 @@ public class FileMenuFilter {
private boolean anyFileDownloading(FileDownloaderBinder downloaderBinder) { private boolean anyFileDownloading(FileDownloaderBinder downloaderBinder) {
boolean downloading = false; boolean downloading = false;
if (downloaderBinder != null) { if (downloaderBinder != null) {
for (int i=0; !downloading && i < mFiles.size(); i++) { for (Iterator<OCFile> iterator = mFiles.iterator(); !downloading && iterator.hasNext();) {
downloading = downloaderBinder.isDownloading(mAccount, mFiles.get(i)); downloading = downloaderBinder.isDownloading(mAccount, iterator.next());
} }
} }
return downloading; return downloading;
@ -281,8 +283,8 @@ public class FileMenuFilter {
private boolean anyFileUploading(FileUploaderBinder uploaderBinder) { private boolean anyFileUploading(FileUploaderBinder uploaderBinder) {
boolean uploading = false; boolean uploading = false;
if (uploaderBinder != null) { if (uploaderBinder != null) {
for (int i=0; !uploading && i < mFiles.size(); i++) { for (Iterator<OCFile> iterator = mFiles.iterator(); !uploading && iterator.hasNext();) {
uploading = uploaderBinder.isUploading(mAccount, mFiles.get(i)); uploading = uploaderBinder.isUploading(mAccount, iterator.next());
} }
} }
return uploading; return uploading;
@ -293,7 +295,7 @@ public class FileMenuFilter {
} }
private boolean isSingleFile() { private boolean isSingleFile() {
return isSingleSelection() && !mFiles.get(0).isFolder(); return isSingleSelection() && !mFiles.iterator().next().isFolder();
} }
private boolean allFiles() { private boolean allFiles() {
@ -335,5 +337,4 @@ public class FileMenuFilter {
} }
return true; return true;
} }
} }

View file

@ -40,20 +40,16 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
@ -94,9 +90,9 @@ import com.owncloud.android.utils.PermissionUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.Collection;
import static com.owncloud.android.db.PreferenceManager.*; import static com.owncloud.android.db.PreferenceManager.getSortOrder;
/** /**
* Displays, what files the user has available in his ownCloud. This is the main view. * Displays, what files the user has available in his ownCloud. This is the main view.
@ -970,9 +966,7 @@ public class FileDisplayActivity extends HookActivity
if (synchResult != null && !synchResult.isSuccess()) { if (synchResult != null && !synchResult.isSuccess()) {
/// TODO refactor and make common /// TODO refactor and make common
if (ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || if (checkForRemoteOperationError(synchResult)) {
(synchResult.isException() && synchResult.getException()
instanceof AuthenticatorException)) {
requestCredentialsUpdate(context); requestCredentialsUpdate(context);
@ -1007,6 +1001,12 @@ public class FileDisplayActivity extends HookActivity
} }
} }
private boolean checkForRemoteOperationError(RemoteOperationResult syncResult) {
return ResultCode.UNAUTHORIZED.equals(syncResult.getCode()) ||
(syncResult.isException() && syncResult.getException()
instanceof AuthenticatorException);
}
/** /**
* Show a text message on screen view for notifying user if content is * Show a text message on screen view for notifying user if content is
* loading or folder is empty * loading or folder is empty
@ -1745,9 +1745,9 @@ public class FileDisplayActivity extends HookActivity
/** /**
* Request stopping all upload/download operations in progress over the given {@link OCFile} files. * Request stopping all upload/download operations in progress over the given {@link OCFile} files.
* *
* @param files list of {@link OCFile} files which operations are wanted to be cancel * @param files collection of {@link OCFile} files which operations are wanted to be cancel
*/ */
public void cancelTransference(List<OCFile> files) { public void cancelTransference(Collection<OCFile> files) {
for(OCFile file: files) { for(OCFile file: files) {
cancelTransference(file); cancelTransference(file);
} }

View file

@ -35,7 +35,6 @@ import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources.NotFoundException; import android.content.res.Resources.NotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
@ -269,19 +268,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
CharSequence dialogItems[] = new CharSequence[accounts.length]; CharSequence dialogItems[] = new CharSequence[accounts.length];
OwnCloudAccount oca; OwnCloudAccount oca;
for (int i = 0; i < dialogItems.length; ++i) { for (int i = 0; i < dialogItems.length; ++i) {
try { dialogItems[i] = DisplayUtils.getAccountNameDisplayText(
oca = new OwnCloudAccount(accounts[i], this); this, accounts[i], accounts[i].name, DisplayUtils.convertIdn(accounts[i].name, false));
dialogItems[i] =
oca.getDisplayName() + " @ " +
DisplayUtils.convertIdn(
accounts[i].name.substring(accounts[i].name.lastIndexOf("@") + 1),
false
);
} catch (Exception e) {
Log_OC.w(TAG, "Couldn't read display name of account; using account name instead");
dialogItems[i] = DisplayUtils.convertIdn(accounts[i].name, false);
}
} }
builder.setTitle(R.string.common_choose_account); builder.setTitle(R.string.common_choose_account);
builder.setItems(dialogItems, new OnClickListener() { builder.setItems(dialogItems, new OnClickListener() {

View file

@ -45,7 +45,6 @@ import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
import com.owncloud.android.db.OCUpload; import com.owncloud.android.db.OCUpload;
import com.owncloud.android.db.UploadResult; import com.owncloud.android.db.UploadResult;
import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileActivity;
@ -241,17 +240,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
uploadDateTextView.setText(dateString); uploadDateTextView.setText(dateString);
TextView accountNameTextView = (TextView) view.findViewById(R.id.upload_account); TextView accountNameTextView = (TextView) view.findViewById(R.id.upload_account);
try { Account account = AccountUtils.getOwnCloudAccountByName(mParentActivity, upload.getAccountName());
Account account = AccountUtils.getOwnCloudAccountByName(mParentActivity, upload.getAccountName()); accountNameTextView.setText(
OwnCloudAccount oca = new OwnCloudAccount(account, mParentActivity); DisplayUtils.getAccountNameDisplayText(
accountNameTextView.setText( mParentActivity, account, account.name, upload.getAccountName())
oca.getDisplayName() + " @ " + );
DisplayUtils.convertIdn(account.name.substring(account.name.lastIndexOf("@") + 1), false)
);
} catch (Exception e) {
Log_OC.w(TAG, "Couldn't get display name for account, using old style");
accountNameTextView.setText(upload.getAccountName());
}
TextView statusTextView = (TextView) view.findViewById(R.id.upload_status); TextView statusTextView = (TextView) view.findViewById(R.id.upload_status);

View file

@ -35,11 +35,12 @@ import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
public class RemoveFilesDialogFragment extends ConfirmationDialogFragment public class RemoveFilesDialogFragment extends ConfirmationDialogFragment
implements ConfirmationDialogFragmentListener { implements ConfirmationDialogFragmentListener {
private ArrayList<OCFile> mTargetFiles; private Collection<OCFile> mTargetFiles;
private static final String ARG_TARGET_FILES = "TARGET_FILES"; private static final String ARG_TARGET_FILES = "TARGET_FILES";
@ -58,9 +59,9 @@ implements ConfirmationDialogFragmentListener {
boolean containsDown = false; boolean containsDown = false;
boolean containsFavorite = false; boolean containsFavorite = false;
for (OCFile file: files) { for (OCFile file: files) {
if (file.isFolder()) containsFolder = true; containsFolder |= file.isFolder();
if (file.isDown()) containsDown = true; containsDown |= file.isDown();
if (file.isFavorite()) containsFavorite = true; containsFavorite |= file.isFavorite();
} }
if (files.size() == 1) { if (files.size() == 1) {

View file

@ -47,6 +47,7 @@ import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.TextDrawable; import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.activity.ToolbarActivity; import com.owncloud.android.ui.activity.ToolbarActivity;
@ -173,6 +174,27 @@ public class DisplayUtils {
} }
} }
/**
* creates the display string for an account.
*
* @param context the actual activity
* @param savedAccount the actual, saved account
* @param accountName the account name
* @param fallbackString String to be used in case of an error
* @return the display string for the given account data
*/
public static String getAccountNameDisplayText(Context context, Account savedAccount, String accountName, String
fallbackString) {
try {
return new OwnCloudAccount(savedAccount, context).getDisplayName()
+ " @ "
+ convertIdn(accountName.substring(accountName.lastIndexOf("@") + 1), false);
} catch (Exception e) {
Log_OC.w(TAG, "Couldn't get display name for account, using old style");
return fallbackString;
}
}
/** /**
* calculates the relative time string based on the given modificaion timestamp. * calculates the relative time string based on the given modificaion timestamp.
* *