瀏覽代碼

Merge pull request #2860 from nextcloud/findbugs

Fix findbugs
Andy Scherzinger 6 年之前
父節點
當前提交
3839d47ede
共有 26 個文件被更改,包括 110 次插入127 次删除
  1. 4 4
      src/main/java/com/owncloud/android/MainApp.java
  2. 2 5
      src/main/java/com/owncloud/android/datamodel/OCFile.java
  3. 2 3
      src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java
  4. 1 1
      src/main/java/com/owncloud/android/files/FileMenuFilter.java
  5. 1 1
      src/main/java/com/owncloud/android/jobs/MediaFoldersDetectionJob.java
  6. 1 1
      src/main/java/com/owncloud/android/operations/UploadFileOperation.java
  7. 15 18
      src/main/java/com/owncloud/android/services/OperationsService.java
  8. 2 2
      src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java
  9. 3 6
      src/main/java/com/owncloud/android/ui/activity/ManageSpaceActivity.java
  10. 7 7
      src/main/java/com/owncloud/android/ui/activity/Preferences.java
  11. 3 4
      src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java
  12. 2 2
      src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java
  13. 7 6
      src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java
  14. 1 1
      src/main/java/com/owncloud/android/ui/adapter/TrashbinListAdapter.java
  15. 2 2
      src/main/java/com/owncloud/android/ui/components/CustomEditText.java
  16. 1 1
      src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java
  17. 1 1
      src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java
  18. 24 27
      src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java
  19. 1 1
      src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java
  20. 1 1
      src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java
  21. 5 2
      src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java
  22. 17 23
      src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java
  23. 2 2
      src/main/java/com/owncloud/android/utils/DisplayUtils.java
  24. 3 4
      src/main/java/com/owncloud/android/utils/FileStorageUtils.java
  25. 1 1
      src/main/java/com/owncloud/android/utils/FilesSyncHelper.java
  26. 1 1
      src/main/java/com/owncloud/android/utils/ReceiversHelper.java

+ 4 - 4
src/main/java/com/owncloud/android/MainApp.java

@@ -579,8 +579,8 @@ public class MainApp extends MultiDexApplication {
                 Log_OC.i(TAG, "Migration check for synced_folders record: "
                         + syncedFolder.getId() + " - " + syncedFolder.getLocalPath());
 
-                for (int i = 0; i < imageMediaFolders.size(); i++) {
-                    if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {
+                for (MediaFolder imageMediaFolder : imageMediaFolders) {
+                    if (imageMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                         newSyncedFolder.setType(MediaFolderType.IMAGE);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
@@ -590,8 +590,8 @@ public class MainApp extends MultiDexApplication {
                     }
                 }
 
-                for (int j = 0; j < videoMediaFolders.size(); j++) {
-                    if (videoMediaFolders.get(j).absolutePath.equals(syncedFolder.getLocalPath())) {
+                for (MediaFolder videoMediaFolder : videoMediaFolders) {
+                    if (videoMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                         newSyncedFolder.setType(MediaFolderType.VIDEO);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);

+ 2 - 5
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -665,19 +665,16 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
 
     @Override
     public int hashCode() {
-        int result = (int) (mId ^ (mId >>> 32));
-        result = 31 * result + (int) (mParentId ^ (mParentId >>> 32));
-        return result;
+        return 31 * (int) (mId ^ (mId >>> 32)) + (int) (mParentId ^ (mParentId >>> 32));
     }
 
     @Override
     public String toString() {
         String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, " +
                 "parentId=%s, availableOffline=%s etag=%s favourite=%s]";
-        asString = String.format(asString, mId, getFileName(), mMimeType, isDown(),
+        return String.format(asString, mId, getFileName(), mMimeType, isDown(),
                 mLocalPath, mRemotePath, mParentId, mAvailableOffline,
                 mEtag, mIsFavorite);
-        return asString;
     }
 
     public String getEtag() {

+ 2 - 3
src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

@@ -281,8 +281,7 @@ public class SyncedFolderProvider extends Observable {
      */
     public void updateAutoUploadPaths(Context context) {
         List<SyncedFolder> syncedFolders = getSyncedFolders();
-        for (int i = 0; i < syncedFolders.size(); i++) {
-            SyncedFolder syncedFolder = syncedFolders.get(i);
+        for (SyncedFolder syncedFolder : syncedFolders) {
             if (!new File(syncedFolder.getLocalPath()).exists()) {
                 String localPath = syncedFolder.getLocalPath();
                 if (localPath.endsWith("/")) {
@@ -290,7 +289,7 @@ public class SyncedFolderProvider extends Observable {
                 }
                 localPath = localPath.substring(0, localPath.lastIndexOf('/'));
                 if (new File(localPath).exists()) {
-                    syncedFolders.get(i).setLocalPath(localPath);
+                    syncedFolder.setLocalPath(localPath);
                     updateSyncFolder(syncedFolder);
                 } else {
                     deleteSyncFolderWithId(syncedFolder.getId());

+ 1 - 1
src/main/java/com/owncloud/android/files/FileMenuFilter.java

@@ -99,7 +99,7 @@ public class FileMenuFilter {
      * @param inSingleFileFragment  True if this is not listing, but single file fragment, like preview or details.
      */
     public void filter(Menu menu, boolean inSingleFileFragment) {
-        if (mFiles == null || mFiles.size() <= 0) {
+        if (mFiles == null || mFiles.isEmpty()) {
             hideAll(menu);
         } else {
             List<Integer> toShow = new ArrayList<>();

+ 1 - 1
src/main/java/com/owncloud/android/jobs/MediaFoldersDetectionJob.java

@@ -98,7 +98,7 @@ public class MediaFoldersDetectionJob extends Job {
             imageMediaFolderPaths.removeAll(mediaFoldersModel.getImageMediaFolders());
             videoMediaFolderPaths.removeAll(mediaFoldersModel.getVideoMediaFolders());
 
-            if (imageMediaFolderPaths.size() > 0 || videoMediaFolderPaths.size() > 0) {
+            if (!imageMediaFolderPaths.isEmpty() || !videoMediaFolderPaths.isEmpty()) {
                 Account[] accounts = AccountUtils.getAccounts(getContext());
                 List<Account> accountList = new ArrayList<>();
                 for (Account account : accounts) {

+ 1 - 1
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -1166,7 +1166,7 @@ public class UploadFileOperation extends SyncOperation {
 
         RemoteOperationResult result = null;
 
-        if (FileStorageUtils.getUsableSpace(mAccount.name) < sourceFile.length()) {
+        if (FileStorageUtils.getUsableSpace() < sourceFile.length()) {
             result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
             return result;  // error condition when the file should be copied
 

+ 15 - 18
src/main/java/com/owncloud/android/services/OperationsService.java

@@ -522,9 +522,6 @@ public class OperationsService extends Service {
                 mService.dispatchResultToOperationListeners(mCurrentOperation, result);
             }
         }
-
-
-
     }
 
 
@@ -557,7 +554,7 @@ public class OperationsService extends Service {
                 
                 String action = operationIntent.getAction();
 
-                if (action.equals(ACTION_CREATE_SHARE_VIA_LINK)) {  // Create public share via link
+                if (ACTION_CREATE_SHARE_VIA_LINK.equals(action)) {  // Create public share via link
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                     if (remotePath.length() > 0) {
@@ -600,7 +597,7 @@ public class OperationsService extends Service {
                         ((UpdateSharePermissionsOperation)operation).setPassword(password);
                     }
 
-                } else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {
+                } else if (ACTION_CREATE_SHARE_WITH_SHAREE.equals(action)) {
                     // Create private share with user or group
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
@@ -615,7 +612,7 @@ public class OperationsService extends Service {
                         );
                     }
 
-                } else if (action.equals(ACTION_UNSHARE)) {  // Unshare file
+                } else if (ACTION_UNSHARE.equals(action)) {  // Unshare file
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     ShareType shareType = (ShareType) operationIntent.
                             getSerializableExtra(EXTRA_SHARE_TYPE);
@@ -629,11 +626,11 @@ public class OperationsService extends Service {
                         );
                     }
                     
-                } else if (action.equals(ACTION_GET_SERVER_INFO)) { 
+                } else if (ACTION_GET_SERVER_INFO.equals(action)) {
                     // check OC server and get basic information from it
                     operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
 
-                } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
+                } else if (ACTION_OAUTH2_GET_ACCESS_TOKEN.equals(action)) {
                     /// GET ACCESS TOKEN to the OAuth server
                     String oauth2QueryParameters =
                             operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
@@ -643,17 +640,17 @@ public class OperationsService extends Service {
                             getString(R.string.oauth2_grant_type),
                             oauth2QueryParameters);
 
-                } else if (action.equals(ACTION_GET_USER_NAME)) {
+                } else if (ACTION_GET_USER_NAME.equals(action)) {
                     // Get User Name
                     operation = new GetRemoteUserInfoOperation();
                     
-                } else if (action.equals(ACTION_RENAME)) {
+                } else if (ACTION_RENAME.equals(action)) {
                     // Rename file or folder
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
                     operation = new RenameFileOperation(remotePath, newName);
                     
-                } else if (action.equals(ACTION_REMOVE)) {
+                } else if (ACTION_REMOVE.equals(action)) {
                     // Remove file or folder
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
@@ -661,20 +658,20 @@ public class OperationsService extends Service {
                     operation = new RemoveFileOperation(remotePath, onlyLocalCopy, account, inBackground,
                             getApplicationContext());
                     
-                } else if (action.equals(ACTION_CREATE_FOLDER)) {
+                } else if (ACTION_CREATE_FOLDER.equals(action)) {
                     // Create Folder
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
                     operation = new CreateFolderOperation(remotePath, createFullPath);
 
-                } else if (action.equals(ACTION_SYNC_FILE)) {
+                } else if (ACTION_SYNC_FILE.equals(action)) {
                     // Sync file
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
                     operation = new SynchronizeFileOperation(remotePath, account, syncFileContents,
                             getApplicationContext());
                     
-                } else if (action.equals(ACTION_SYNC_FOLDER)) {
+                } else if (ACTION_SYNC_FOLDER.equals(action)) {
                     // Sync folder (all its descendant files are sync'ed)
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     operation = new SynchronizeFolderOperation(
@@ -684,22 +681,22 @@ public class OperationsService extends Service {
                             System.currentTimeMillis()  // TODO remove this dependency from construction time
                     );
 
-                } else if (action.equals(ACTION_MOVE_FILE)) {
+                } else if (ACTION_MOVE_FILE.equals(action)) {
                     // Move file/folder
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                     operation = new MoveFileOperation(remotePath, newParentPath);
 
-                } else if (action.equals(ACTION_COPY_FILE)) {
+                } else if (ACTION_COPY_FILE.equals(action)) {
                     // Copy file/folder
                     String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                     String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                     operation = new CopyFileOperation(remotePath, newParentPath);
 
-                } else if (action.equals(ACTION_CHECK_CURRENT_CREDENTIALS)) {
+                } else if (ACTION_CHECK_CURRENT_CREDENTIALS.equals(action)) {
                     // Check validity of currently stored credentials for a given account
                     operation = new CheckCurrentCredentialsOperation(account);
-                } else if (action.equals(ACTION_RESTORE_VERSION)) {
+                } else if (ACTION_RESTORE_VERSION.equals(action)) {
                     FileVersion fileVersion = operationIntent.getParcelableExtra(EXTRA_FILE_VERSION);
                     String userId = operationIntent.getStringExtra(EXTRA_USER_ID);
                     operation = new RestoreFileVersionOperation(fileVersion.getRemoteId(), fileVersion.getFileName(),

+ 2 - 2
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -529,7 +529,7 @@ public class FileDisplayActivity extends HookActivity
     @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
-        if (intent.getAction() != null && intent.getAction().equalsIgnoreCase(ACTION_DETAILS)) {
+        if (ACTION_DETAILS.equalsIgnoreCase(intent.getAction())) {
             setIntent(intent);
             setFile(intent.getParcelableExtra(EXTRA_FILE));
         } else if (RESTART.equals(intent.getAction())) {
@@ -1142,7 +1142,7 @@ public class FileDisplayActivity extends HookActivity
             // all closed
 
             //if PreviewImageActivity called this activity and mDualPane==false  then calls PreviewImageActivity again
-            if ((getIntent().getAction() != null && getIntent().getAction().equalsIgnoreCase(ACTION_DETAILS)) && !mDualPane) {
+            if (ACTION_DETAILS.equalsIgnoreCase(getIntent().getAction()) && !mDualPane) {
                 getIntent().setAction(null);
                 getIntent().putExtra(EXTRA_FILE, (OCFile) null);
                 startImagePreview(getFile(), false);

+ 3 - 6
src/main/java/com/owncloud/android/ui/activity/ManageSpaceActivity.java

@@ -88,15 +88,13 @@ public class ManageSpaceActivity extends AppCompatActivity {
         @Override
         protected Boolean doInBackground(Void... params) {
 
-            boolean result = true;
-
             // Save passcode from Share preferences
             SharedPreferences appPrefs = PreferenceManager
                     .getDefaultSharedPreferences(getApplicationContext());
 
             String lockPref = appPrefs.getString(Preferences.PREFERENCE_LOCK, Preferences.LOCK_NONE);
-            boolean passCodeEnable = appPrefs.getString(Preferences.PREFERENCE_LOCK, "")
-                    .equals(Preferences.LOCK_PASSCODE);
+            boolean passCodeEnable = Preferences.LOCK_PASSCODE.equals(
+                    appPrefs.getString(Preferences.PREFERENCE_LOCK, ""));
 
             String passCodeDigits[] = new String[4];
             if (passCodeEnable) {
@@ -107,8 +105,7 @@ public class ManageSpaceActivity extends AppCompatActivity {
             }
 
             // Clear data
-            result = clearApplicationData();
-
+            boolean result = clearApplicationData();
 
             // Clear SharedPreferences
             SharedPreferences.Editor appPrefsEditor = PreferenceManager

+ 7 - 7
src/main/java/com/owncloud/android/ui/activity/Preferences.java

@@ -658,7 +658,7 @@ public class Preferences extends PreferenceActivity
                     String oldValue = ((ListPreference) preference).getValue();
                     String newValue = (String) o;
                     if (!oldValue.equals(newValue)) {
-                        if (oldValue.equals(LOCK_NONE)) {
+                        if (LOCK_NONE.equals(oldValue)) {
                             enableLock(newValue);
                         } else {
                             pendingLock = newValue;
@@ -722,11 +722,11 @@ public class Preferences extends PreferenceActivity
 
     private void enableLock(String lock) {
         pendingLock = LOCK_NONE;
-        if (lock.equals(LOCK_PASSCODE)) {
+        if (LOCK_PASSCODE.equals(lock)) {
             Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
             i.setAction(PassCodeActivity.ACTION_REQUEST_WITH_RESULT);
             startActivityForResult(i, ACTION_REQUEST_PASSCODE);
-        } else if (lock.equals(LOCK_DEVICE_CREDENTIALS)){
+        } else if (LOCK_DEVICE_CREDENTIALS.equals(lock)){
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                     !DeviceCredentialUtils.areCredentialsAvailable(getApplicationContext())) {
                 DisplayUtils.showSnackMessage(this, R.string.prefs_lock_device_credentials_not_setup);
@@ -739,11 +739,11 @@ public class Preferences extends PreferenceActivity
     }
 
     private void disableLock(String lock) {
-        if (lock.equals(LOCK_PASSCODE)) {
+        if (LOCK_PASSCODE.equals(lock)) {
             Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
             i.setAction(PassCodeActivity.ACTION_CHECK_WITH_RESULT);
             startActivityForResult(i, ACTION_CONFIRM_PASSCODE);
-        } else if (lock.equals(LOCK_DEVICE_CREDENTIALS)) {
+        } else if (LOCK_DEVICE_CREDENTIALS.equals(lock)) {
             Intent i = new Intent(getApplicationContext(), RequestCredentialsActivity.class);
             startActivityForResult(i, ACTION_CONFIRM_DEVICE_CREDENTIALS);
         }
@@ -914,7 +914,7 @@ public class Preferences extends PreferenceActivity
                 mLock.setSummary(mLock.getEntry());
 
                 DisplayUtils.showSnackMessage(this, R.string.pass_code_removed);
-                if (!pendingLock.equals(LOCK_NONE)) {
+                if (!LOCK_NONE.equals(pendingLock)) {
                     enableLock(pendingLock);
                 }
             }
@@ -928,7 +928,7 @@ public class Preferences extends PreferenceActivity
             mLock.setValue(LOCK_NONE);
             mLock.setSummary(mLock.getEntry());
             DisplayUtils.showSnackMessage(this, R.string.credentials_disabled);
-            if (!pendingLock.equals(LOCK_NONE)) {
+            if (!LOCK_NONE.equals(pendingLock)) {
                 enableLock(pendingLock);
             }
         } else if (requestCode == PassCodeManager.PASSCODE_ACTIVITY && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&

+ 3 - 4
src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -640,7 +640,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
         List<OCFile> tmpFiles = getStorageManager().getFolderContent(mFile, false);
         tmpFiles = sortFileList(tmpFiles);
 
-        if (tmpFiles.size() <= 0) {
+        if (tmpFiles.isEmpty()) {
             return;
         }
         // filter on dirtype
@@ -749,7 +749,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
         if (mFile != null) {
             List<OCFile> files = getStorageManager().getFolderContent(mFile, false);
 
-            if (files.size() == 0) {
+            if (files.isEmpty()) {
                 setMessageForEmptyList(R.string.file_list_empty_headline, R.string.empty,
                         R.drawable.ic_list_empty_upload);
             } else {
@@ -873,8 +873,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
             mStreamsToUpload = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
         }
 
-        if (mStreamsToUpload == null || mStreamsToUpload.size() == 0 ||
-                mStreamsToUpload.get(0) == null) {
+        if (mStreamsToUpload == null || mStreamsToUpload.isEmpty() || mStreamsToUpload.get(0) == null) {
             mStreamsToUpload = null;
             saveTextsFromIntent(intent);
         }

+ 2 - 2
src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java

@@ -534,7 +534,7 @@ public class UploadFilesActivity extends FileActivity implements
                     File localFile = new File(localPath);
                     total += localFile.length();
                 }
-                return FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total;
+                return FileStorageUtils.getUsableSpace() >= total;
             }
 
             return true;
@@ -597,7 +597,7 @@ public class UploadFilesActivity extends FileActivity implements
     @Override
     public void onConfirmation(String callerTag) {
         Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
-        if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
+        if (QUERY_TO_MOVE_DIALOG_TAG.equals(callerTag)) {
             // return the list of selected files to the caller activity (success),
             // signaling that they should be moved to the ownCloud folder, instead of copied
             Intent data = new Intent();

+ 7 - 6
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -402,7 +402,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                     }
                 }
 
-                if (file.getMimeType().equalsIgnoreCase("image/png")) {
+                if ("image/png".equalsIgnoreCase(file.getMimeType())) {
                     thumbnailView.setBackgroundColor(mContext.getResources().getColor(R.color.background_color));
                 }
             } else {
@@ -571,10 +571,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
     private void parseShares(ArrayList<Object> objects) {
         List<OCShare> shares = new ArrayList<>();
-        for (int i = 0; i < objects.size(); i++) {
+
+        for (Object shareObject : objects) {
             // check type before cast as of long running data fetch it is possible that old result is filled
-            if (objects.get(i) instanceof OCShare) {
-                OCShare ocShare = (OCShare) objects.get(i);
+            if (shareObject instanceof OCShare) {
+                OCShare ocShare = (OCShare) shareObject;
 
                 shares.add(ocShare);
 
@@ -627,8 +628,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
         List<ContentValues> contentValues = new ArrayList<>();
 
-        for (int i = 0; i < objects.size(); i++) {
-            OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
+        for (Object remoteFile : objects) {
+            OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) remoteFile);
             searchForLocalFileInDefaultPath(ocFile);
 
             try {

+ 1 - 1
src/main/java/com/owncloud/android/ui/adapter/TrashbinListAdapter.java

@@ -243,7 +243,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
                     }
                 }
 
-                if (file.getMimeType().equalsIgnoreCase("image/png")) {
+                if ("image/png".equalsIgnoreCase(file.getMimeType())) {
                     thumbnailView.setBackgroundColor(context.getResources().getColor(R.color.background_color));
                 }
             } else {

+ 2 - 2
src/main/java/com/owncloud/android/ui/components/CustomEditText.java

@@ -42,10 +42,10 @@ public class CustomEditText extends android.support.v7.widget.AppCompatEditText
 
         String serverInputType = getResources().getString(R.string.server_input_type);
 
-        if (serverInputType.equals(AuthenticatorActivity.DIRECTORY_SERVER_INPUT_TYPE)) {
+        if (AuthenticatorActivity.DIRECTORY_SERVER_INPUT_TYPE.equals(serverInputType)) {
             isPrefixFixed = true;
             fixedText = getResources().getString(R.string.server_url) + "/";
-        } else if (serverInputType.equals(AuthenticatorActivity.SUBDOMAIN_SERVER_INPUT_TYPE)) {
+        } else if (AuthenticatorActivity.SUBDOMAIN_SERVER_INPUT_TYPE.equals(serverInputType)) {
             isPrefixFixed = false;
             fixedText = "." + getResources().getString(R.string.server_url);
         }

+ 1 - 1
src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java

@@ -150,7 +150,7 @@ public class SendShareDialog extends BottomSheetDialogFragment {
 
         List<SendButtonData> sendButtonDataList = setupSendButtonData(sendIntent);
 
-        if (getContext().getString(R.string.send_files_to_other_apps).equalsIgnoreCase("off")) {
+        if ("off".equalsIgnoreCase(getContext().getString(R.string.send_files_to_other_apps))) {
             sharePeopleText.setVisibility(View.GONE);
         }
 

+ 1 - 1
src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java

@@ -196,7 +196,7 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
     @OnClick(R.id.submitComment)
     public void submitComment() {
         if (commentInput.getText().toString().trim().length() > 0) {
-            new SubmitCommentTask(commentInput.getText().toString(), userId, file.getLocalId(),
+            new SubmitCommentTask(commentInput.getText().toString().trim(), userId, file.getLocalId(),
                     callback, ownCloudClient).execute();
         }
     }

+ 24 - 27
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -334,22 +334,22 @@ public class OCFileListFragment extends ExtendedListFragment implements
 
     private void prepareCurrentSearch(SearchEvent event) {
         if (event != null) {
-            if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
+            if (SearchOperation.SearchType.FILE_SEARCH.equals(event.getSearchType())) {
                 currentSearchType = SearchType.FILE_SEARCH;
 
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
-                if (event.getSearchQuery().equals("image/%")) {
+            } else if (SearchOperation.SearchType.CONTENT_TYPE_SEARCH.equals(event.getSearchType())) {
+                if ("image/%".equals(event.getSearchQuery())) {
                     currentSearchType = SearchType.PHOTO_SEARCH;
-                } else if (event.getSearchQuery().equals("video/%")) {
+                } else if ("video/%".equals(event.getSearchQuery())) {
                     currentSearchType = SearchType.VIDEO_SEARCH;
                 }
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
+            } else if (SearchOperation.SearchType.FAVORITE_SEARCH.equals(event.getSearchType())) {
                 currentSearchType = SearchType.FAVORITE_SEARCH;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_ADDED_SEARCH.equals(event.getSearchType())) {
                 currentSearchType = SearchType.RECENTLY_ADDED_SEARCH;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH.equals(event.getSearchType())) {
                 currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
+            } else if (SearchOperation.SearchType.SHARED_SEARCH.equals(event.getSearchType())) {
                 currentSearchType = SearchType.SHARED_FILTER;
             }
 
@@ -890,7 +890,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
      * @return 'true' if the menu selection started any action, 'false' otherwise.
      */
     public boolean onFileActionChosen(int menuId, Set<OCFile> checkedFiles) {
-        if (checkedFiles.size() <= 0) {
+        if (checkedFiles.isEmpty()) {
             return false;
         }
 
@@ -1115,7 +1115,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
      * @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
      */
     public boolean isGridViewPreferred(OCFile folder) {
-        return PreferenceManager.getFolderLayout(getActivity(), folder).equals(FOLDER_LAYOUT_GRID);
+        return FOLDER_LAYOUT_GRID.equals(PreferenceManager.getFolderLayout(getActivity(), folder));
     }
 
     public void setListAsPreferred() {
@@ -1244,22 +1244,21 @@ public class OCFileListFragment extends ExtendedListFragment implements
 
     private void prepareActionBarItems(SearchEvent event) {
         if (event != null) {
-            if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
-                if (event.getSearchQuery().equals("image/%")) {
+            if (SearchOperation.SearchType.CONTENT_TYPE_SEARCH.equals(event.getSearchType())) {
+                if ("image/%".equals(event.getSearchQuery())) {
                     menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
-                } else if (event.getSearchQuery().equals("video/%")) {
+                } else if ("video/%".equals(event.getSearchQuery())) {
                     menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
                 }
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
+            } else if (SearchOperation.SearchType.FAVORITE_SEARCH.equals(event.getSearchType())) {
                 menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_ADDED_SEARCH.equals(event.getSearchType())) {
                 menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH.equals(event.getSearchType())) {
                 menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
+            } else if (SearchOperation.SearchType.SHARED_SEARCH.equals(event.getSearchType())) {
                 menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
             }
-
         }
 
         if (currentSearchType != null && !currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {
@@ -1270,26 +1269,24 @@ public class OCFileListFragment extends ExtendedListFragment implements
     private void setEmptyView(SearchEvent event) {
 
         if (event != null) {
-            if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
+            if (SearchOperation.SearchType.FILE_SEARCH.equals(event.getSearchType())) {
                 setEmptyListMessage(SearchType.FILE_SEARCH);
             } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
-                if (event.getSearchQuery().equals("image/%")) {
+                if ("image/%".equals(event.getSearchQuery())) {
                     setEmptyListMessage(SearchType.PHOTO_SEARCH);
-                } else if (event.getSearchQuery().equals("video/%")) {
+                } else if ("video/%".equals(event.getSearchQuery())) {
                     setEmptyListMessage(SearchType.VIDEO_SEARCH);
                 }
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
+            } else if (SearchOperation.SearchType.FAVORITE_SEARCH.equals(event.getSearchType())) {
                 setEmptyListMessage(SearchType.FAVORITE_SEARCH);
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_ADDED_SEARCH.equals(event.getSearchType())) {
                 setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH);
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
+            } else if (SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH.equals(event.getSearchType())) {
                 setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
-            } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
+            } else if (SearchOperation.SearchType.SHARED_SEARCH.equals(event.getSearchType())) {
                 setEmptyListMessage(SearchType.SHARED_FILTER);
             }
-
         }
-
     }
 
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 1 - 1
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java

@@ -716,7 +716,7 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
                 checkedVCards.remove(verifiedPosition);
             }
 
-            if (checkedVCards.size() == 0) {
+            if (checkedVCards.isEmpty()) {
                 EventBus.getDefault().post(new VCardToggleEvent(false));
             }
         }

+ 1 - 1
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java

@@ -244,7 +244,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
 
                     Collections.sort(backupFiles, new AlphanumComparator<>());
 
-                    if (backupFiles == null || backupFiles.size() == 0) {
+                    if (backupFiles == null || backupFiles.isEmpty()) {
                         contactsDatePickerBtn.setVisibility(View.GONE);
                     } else {
                         contactsDatePickerBtn.setVisibility(View.VISIBLE);

+ 5 - 2
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -94,6 +94,9 @@ public class FileOperationsHelper {
     private static final String TAG = FileOperationsHelper.class.getSimpleName();
     private static final Pattern mPatternUrl = Pattern.compile("^URL=(.+)$");
     private static final Pattern mPatternString = Pattern.compile("<string>(.+)</string>");
+    private static final String FILE_EXTENSION_URL = "url";
+    private static final String FILE_EXTENSION_DESKTOP = "desktop";
+    private static final String FILE_EXTENSION_WEBLOC = "webloc";
     private FileActivity mFileActivity;
     /// Identifier of operation in progress which result shouldn't be lost
     private long mWaitingForOpId = Long.MAX_VALUE;
@@ -148,11 +151,11 @@ public class FileOperationsHelper {
         int lastIndexOfDot = storagePath.lastIndexOf('.');
         if (lastIndexOfDot >= 0) {
             String fileExt = storagePath.substring(lastIndexOfDot + 1);
-            if (fileExt.equalsIgnoreCase("url") || fileExt.equalsIgnoreCase("desktop")) {
+            if (FILE_EXTENSION_URL.equalsIgnoreCase(fileExt) || FILE_EXTENSION_DESKTOP.equalsIgnoreCase(fileExt)) {
                 // Windows internet shortcut file .url
                 // Ubuntu internet shortcut file .desktop
                 url = getUrlFromFile(storagePath, mPatternUrl);
-            } else if (fileExt.equalsIgnoreCase("webloc")) {
+            } else if (FILE_EXTENSION_WEBLOC.equalsIgnoreCase(fileExt)) {
                 // mac internet shortcut file .webloc
                 url = getUrlFromFile(storagePath, mPatternString);
             }

+ 17 - 23
src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -455,7 +455,7 @@ public class PreviewImageFragment extends FileFragment {
                 int minHeight = screenSize.y;
                 for (int i = 0; i < maxDownScale && bitmapResult == null && drawableResult == null; i++) {
 
-                    if (ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_SVG)) {
+                    if (MIME_TYPE_SVG.equalsIgnoreCase(ocFile.getMimeType())) {
                         if (isCancelled()) {
                             return null;
                         }
@@ -492,7 +492,7 @@ public class PreviewImageFragment extends FileFragment {
                                 Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath);
                                 break;
                             } else {
-                                if (ocFile.getMimeType().equalsIgnoreCase("image/jpeg")) {
+                                if ("image/jpeg".equalsIgnoreCase(ocFile.getMimeType())) {
                                     // Rotate image, obeying exif tag.
                                     bitmapResult = BitmapUtils.rotateImage(bitmapResult, storagePath);
                                 }
@@ -558,9 +558,9 @@ public class PreviewImageFragment extends FileFragment {
                 Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
                         bitmap.getHeight());
 
-                if (result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_PNG) ||
-                        result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_SVG) ||
-                        result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_GIF)) {
+                if (MIME_TYPE_PNG.equalsIgnoreCase(result.ocFile.getMimeType()) ||
+                        MIME_TYPE_SVG.equalsIgnoreCase(result.ocFile.getMimeType()) ||
+                        MIME_TYPE_GIF.equalsIgnoreCase(result.ocFile.getMimeType())) {
                     if (getResources() != null) {
                         imageView.setImageDrawable(generateCheckerboardLayeredDrawable(result, bitmap));
                     } else {
@@ -589,11 +589,11 @@ public class PreviewImageFragment extends FileFragment {
         layers[0] = r.getDrawable(R.color.white);
         Drawable bitmapDrawable;
 
-        if (result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_PNG)) {
+        if (MIME_TYPE_PNG.equalsIgnoreCase(result.ocFile.getMimeType())) {
             bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
-        } else if (result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_SVG)) {
+        } else if (MIME_TYPE_SVG.equalsIgnoreCase(result.ocFile.getMimeType())) {
             bitmapDrawable = result.drawable;
-        } else if (result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_GIF)) {
+        } else if (MIME_TYPE_GIF.equalsIgnoreCase(result.ocFile.getMimeType())) {
             try {
                 bitmapDrawable = new GifDrawable(result.ocFile.getStoragePath());
             } catch (IOException exception) {
@@ -612,22 +612,16 @@ public class PreviewImageFragment extends FileFragment {
                 int bitmapWidth;
                 int bitmapHeight;
 
-                if (result.ocFile.getMimeType().equalsIgnoreCase(MIME_TYPE_PNG)) {
-                    bitmapWidth = convertDpToPixel(bitmap.getWidth(),
-                            getActivity());
-                    bitmapHeight = convertDpToPixel(bitmap.getHeight(),
-                            getActivity());
+                if (MIME_TYPE_PNG.equalsIgnoreCase(result.ocFile.getMimeType())) {
+                    bitmapWidth = convertDpToPixel(bitmap.getWidth(), getActivity());
+                    bitmapHeight = convertDpToPixel(bitmap.getHeight(), getActivity());
                     layerDrawable.setLayerSize(0, bitmapWidth, bitmapHeight);
                     layerDrawable.setLayerSize(1, bitmapWidth, bitmapHeight);
                 } else {
-                    bitmapWidth = convertDpToPixel(bitmapDrawable.getIntrinsicWidth(),
-                            getActivity());
-                    bitmapHeight = convertDpToPixel(bitmapDrawable.getIntrinsicHeight(),
-                            getActivity());
-                    layerDrawable.setLayerSize(0, bitmapWidth,
-                            bitmapHeight);
-                    layerDrawable.setLayerSize(1, bitmapWidth,
-                            bitmapHeight);
+                    bitmapWidth = convertDpToPixel(bitmapDrawable.getIntrinsicWidth(), getActivity());
+                    bitmapHeight = convertDpToPixel(bitmapDrawable.getIntrinsicHeight(), getActivity());
+                    layerDrawable.setLayerSize(0, bitmapWidth, bitmapHeight);
+                    layerDrawable.setLayerSize(1, bitmapWidth, bitmapHeight);
                 }
             }
         }
@@ -717,8 +711,8 @@ public class PreviewImageFragment extends FileFragment {
 
     private void toggleImageBackground() {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && getFile() != null
-                && (getFile().getMimeType().equalsIgnoreCase(MIME_TYPE_PNG) ||
-                getFile().getMimeType().equalsIgnoreCase(MIME_TYPE_SVG)) && getActivity() != null
+                && (MIME_TYPE_PNG.equalsIgnoreCase(getFile().getMimeType()) ||
+                MIME_TYPE_SVG.equalsIgnoreCase(getFile().getMimeType())) && getActivity() != null
                 && getActivity() instanceof PreviewImageActivity && getResources() != null) {
             PreviewImageActivity previewImageActivity = (PreviewImageActivity) getActivity();
 

+ 2 - 2
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -200,11 +200,11 @@ public class DisplayUtils {
             return "";
         }
 
-        if (url.length() >= 7 && url.substring(0, 7).equalsIgnoreCase(HTTP_PROTOCOL)) {
+        if (url.length() >= 7 && HTTP_PROTOCOL.equalsIgnoreCase(url.substring(0, 7))) {
             return url.substring(HTTP_PROTOCOL.length()).trim();
         }
 
-        if (url.length() >= 8 && url.substring(0, 8).equalsIgnoreCase(HTTPS_PROTOCOL)) {
+        if (url.length() >= 8 && HTTPS_PROTOCOL.equalsIgnoreCase(url.substring(0, 8))) {
             return url.substring(HTTPS_PROTOCOL.length()).trim();
         }
 

+ 3 - 4
src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -94,11 +94,10 @@ public class FileStorageUtils {
 
     /**
      * Optimistic number of bytes available on sd-card. accountName is ignored.
-     *
-     * @param accountName not used. can thus be null.
+     * 
      * @return Optimistic number of available bytes (can be less)
      */
-    public static long getUsableSpace(String accountName) {
+    public static long getUsableSpace() {
         File savePath = new File(MainApp.getStoragePath());
         return savePath.getUsableSpace();
     }
@@ -159,7 +158,7 @@ public class FileStorageUtils {
     public static OCFile fillOCFile(RemoteFile remote) {
         OCFile file = new OCFile(remote.getRemotePath());
         file.setCreationTimestamp(remote.getCreationTimestamp());
-        if (remote.getMimeType().equalsIgnoreCase(MimeType.DIRECTORY)) {
+        if (MimeType.DIRECTORY.equalsIgnoreCase(remote.getMimeType())) {
             file.setFileLength(remote.getSize());
         } else {
             file.setFileLength(remote.getLength());

+ 1 - 1
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -254,7 +254,7 @@ public class FilesSyncHelper {
 
     public static void scheduleOfflineSyncIfNeeded() {
         Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(OfflineSyncJob.TAG);
-        if (jobRequests.size() == 0) {
+        if (jobRequests.isEmpty()) {
             new JobRequest.Builder(OfflineSyncJob.TAG)
                     .setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5))
                     .setUpdateCurrent(false)

+ 1 - 1
src/main/java/com/owncloud/android/utils/ReceiversHelper.java

@@ -63,7 +63,7 @@ public class ReceiversHelper {
         BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
+                if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())) {
                     FilesSyncHelper.restartJobsIfNeeded();
                 }
             }