Prechádzať zdrojové kódy

findbugs: fix literal string comparisons passing the literal as an argument

AndyScherzinger 6 rokov pred
rodič
commit
3dffdfdc5e

+ 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 ((getIntent().getAction() != null && 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 &&

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

@@ -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();

+ 1 - 1
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 {

+ 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);
         }
 

+ 23 - 26
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;
             }
 
@@ -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)

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

@@ -148,11 +148,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 ("url".equalsIgnoreCase(fileExt) || "desktop".equalsIgnoreCase(fileExt)) {
                 // Windows internet shortcut file .url
                 // Ubuntu internet shortcut file .desktop
                 url = getUrlFromFile(storagePath, mPatternUrl);
-            } else if (fileExt.equalsIgnoreCase("webloc")) {
+            } else if ("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();
         }
 

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

@@ -159,7 +159,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/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.getAction() != null && Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())) {
                     FilesSyncHelper.restartJobsIfNeeded();
                 }
             }