Browse Source

Merge pull request #950 from nextcloud/codacyCleanUps

further codacy clean ups
Tobias Kaminsky 8 years ago
parent
commit
12ae31601a

+ 2 - 1
src/main/java/com/owncloud/android/authentication/AccountUtils.java

@@ -96,7 +96,8 @@ public class AccountUtils {
             int lastAtPos = account.name.lastIndexOf("@");
             String hostAndPort = account.name.substring(lastAtPos + 1);
             String username = account.name.substring(0, lastAtPos);
-            String otherHostAndPort, otherUsername;
+            String otherHostAndPort;
+            String otherUsername;
             Locale currentLocale = context.getResources().getConfiguration().locale;
             for (Account otherAccount : ocAccounts) {
                 lastAtPos = otherAccount.name.lastIndexOf("@");

+ 3 - 3
src/main/java/com/owncloud/android/authentication/PassCodeManager.java

@@ -50,6 +50,9 @@ public class PassCodeManager {
 
     public static PassCodeManager mPassCodeManagerInstance = null;
 
+    private Long mTimestamp = 0l;
+    private int mVisibleActivitiesCounter = 0;
+
     public static PassCodeManager getPassCodeManager() {
         if (mPassCodeManagerInstance == null) {
             mPassCodeManagerInstance = new PassCodeManager();
@@ -57,9 +60,6 @@ public class PassCodeManager {
         return mPassCodeManagerInstance;
     }
 
-    private Long mTimestamp = 0l;
-    private int mVisibleActivitiesCounter = 0;
-
     protected PassCodeManager() {};
 
     public void onActivityCreated(Activity activity) {

+ 5 - 7
src/main/java/com/owncloud/android/authentication/SsoWebViewClient.java

@@ -55,18 +55,17 @@ import java.security.cert.X509Certificate;
 public class SsoWebViewClient extends WebViewClient {
         
     private static final String TAG = SsoWebViewClient.class.getSimpleName();
-    
-    public interface SsoWebViewClientListener {
-        public void onSsoFinished(String sessionCookie);
-    }
-    
+
     private Context mContext;
     private Handler mListenerHandler;
     private WeakReference<SsoWebViewClientListener> mListenerRef;
     private String mTargetUrl;
     private String mLastReloadedUrlAtError;
-
     
+    public interface SsoWebViewClientListener {
+        public void onSsoFinished(String sessionCookie);
+    }
+
     public SsoWebViewClient (Context context, Handler listenerHandler, SsoWebViewClientListener listener) {
         mContext = context;
         mListenerHandler = listenerHandler;
@@ -191,5 +190,4 @@ public class SsoWebViewClient extends WebViewClient {
 
         ((AuthenticatorActivity)mContext).createAuthenticationDialog(view, handler);
     }
-
 }

+ 5 - 2
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -302,7 +302,8 @@ public class FileUploader extends Service
             UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
             OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
             Account currentAccount = null;
-            boolean resultMatch, accountMatch;
+            boolean resultMatch;
+            boolean accountMatch;
             for ( OCUpload failedUpload: failedUploads) {
                 accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
                 resultMatch = (uploadResult == null || uploadResult.equals(failedUpload.getLastResult()));
@@ -434,7 +435,9 @@ public class FileUploader extends Service
                 return Service.START_NOT_STICKY;
             }
 
-            String[] localPaths = null, remotePaths = null, mimeTypes = null;
+            String[] localPaths = null;
+            String[] remotePaths = null;
+            String[] mimeTypes = null;
             OCFile[] files = null;
 
             if (intent.hasExtra(KEY_FILE)) {

+ 5 - 3
src/main/java/com/owncloud/android/files/services/IndexedForest.java

@@ -41,13 +41,13 @@ import java.util.concurrent.ConcurrentMap;
  */
 public class IndexedForest<V> {
 
-    private ConcurrentMap<String, Node<V>> mMap = new ConcurrentHashMap<String, Node<V>>();
+    private ConcurrentMap<String, Node<V>> mMap = new ConcurrentHashMap<>();
 
     @SuppressWarnings("PMD.ShortClassName")
     private class Node<V> {
         String mKey = null;
         Node<V> mParent = null;
-        Set<Node<V>> mChildren = new HashSet<Node<V>>();    // TODO be careful with hash()
+        Set<Node<V>> mChildren = new HashSet<>();    // TODO be careful with hash()
         V mPayload = null;
 
         // payload is optional
@@ -112,7 +112,9 @@ public class IndexedForest<V> {
 
         } else {
             // value really added
-            String currentPath = remotePath, parentPath = null, parentKey = null;
+            String currentPath = remotePath;
+            String parentPath = null;
+            String parentKey = null;
             Node<V> currentNode = valuedNode, parentNode = null;
             boolean linked = false;
             while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {

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

@@ -375,7 +375,9 @@ public class RefreshFolderOperation extends RemoteOperation {
         }
         
         // loop to update every child
-        OCFile remoteFile = null, localFile = null, updatedFile = null;
+        OCFile remoteFile = null;
+        OCFile localFile = null;
+        OCFile updatedFile = null;
         RemoteFile r;
         for (int i=1; i<folderAndFiles.size(); i++) {
             /// new OCFile instance with the data from the server

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

@@ -288,7 +288,9 @@ public class SynchronizeFolderOperation extends SyncOperation {
         }
 
         // loop to synchronize every child
-        OCFile remoteFile = null, localFile = null, updatedFile = null;
+        OCFile remoteFile = null;
+        OCFile localFile = null;
+        OCFile updatedFile = null;
         RemoteFile r;
         for (int i=1; i<folderAndFiles.size(); i++) {
             /// new OCFile instance with the data from the server

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

@@ -72,43 +72,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
  */
 public class UploadFileOperation extends SyncOperation {
 
+    private static final String TAG = UploadFileOperation.class.getSimpleName();
+
     public static final int CREATED_BY_USER = 0;
     public static final int CREATED_AS_INSTANT_PICTURE = 1;
     public static final int CREATED_AS_INSTANT_VIDEO = 2;
 
-    public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
-
-        // MIME type
-        if (mimeType == null || mimeType.length() <= 0) {
-            mimeType = MimeTypeUtil.getBestMimeTypeByFilename(localPath);
-        }
-
-        OCFile newFile = new OCFile(remotePath);
-        newFile.setStoragePath(localPath);
-        newFile.setLastSyncDateForProperties(0);
-        newFile.setLastSyncDateForData(0);
-
-        // size
-        if (localPath != null && localPath.length() > 0) {
-            File localFile = new File(localPath);
-            newFile.setFileLength(localFile.length());
-            newFile.setLastSyncDateForData(localFile.lastModified());
-        } // don't worry about not assigning size, the problems with localPath
-        // are checked when the UploadFileOperation instance is created
-
-
-        newFile.setMimetype(mimeType);
-
-        return newFile;
-    }
-
-    private static final String TAG = UploadFileOperation.class.getSimpleName();
-
-    private Account mAccount;
     /**
      * OCFile which is to be uploaded.
      */
     private OCFile mFile;
+
     /**
      * Original OCFile which is to be uploaded in case file had to be renamed
      * (if forceOverwrite==false and remote file already exists).
@@ -139,6 +113,34 @@ public class UploadFileOperation extends SyncOperation {
 
     protected RequestEntity mEntity = null;
 
+    private Account mAccount;
+
+    public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
+
+        // MIME type
+        if (mimeType == null || mimeType.length() <= 0) {
+            mimeType = MimeTypeUtil.getBestMimeTypeByFilename(localPath);
+        }
+
+        OCFile newFile = new OCFile(remotePath);
+        newFile.setStoragePath(localPath);
+        newFile.setLastSyncDateForProperties(0);
+        newFile.setLastSyncDateForData(0);
+
+        // size
+        if (localPath != null && localPath.length() > 0) {
+            File localFile = new File(localPath);
+            newFile.setFileLength(localFile.length());
+            newFile.setLastSyncDateForData(localFile.lastModified());
+        } // don't worry about not assigning size, the problems with localPath
+        // are checked when the UploadFileOperation instance is created
+
+
+        newFile.setMimetype(mimeType);
+
+        return newFile;
+    }
+
     public UploadFileOperation(Account account,
                                OCFile file,
                                OCUpload upload,
@@ -148,8 +150,7 @@ public class UploadFileOperation extends SyncOperation {
                                Context context
     ) {
         if (account == null) {
-            throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation " +
-                    "creation");
+            throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation " + "creation");
         }
         if (upload == null) {
             throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
@@ -293,7 +294,9 @@ public class UploadFileOperation extends SyncOperation {
         mCancellationRequested.set(false);
         mUploadStarted.set(true);
         RemoteOperationResult result = null;
-        File temporalFile = null, originalFile = new File(mOriginalStoragePath), expectedFile = null;
+        File temporalFile = null;
+        File originalFile = new File(mOriginalStoragePath);
+        File expectedFile = null;
 
         try {
 

+ 5 - 1
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -1131,7 +1131,11 @@ public class FileContentProvider extends ContentProvider {
             // AccountManager are not synchronous
             Account[] accounts = AccountManager.get(getContext()).getAccountsByType(
                     MainApp.getAccountType());
-            String serverUrl, username, oldAccountName, newAccountName;
+            String serverUrl;
+            String username;
+            String oldAccountName;
+            String newAccountName;
+
             for (Account account : accounts) {
                 // build both old and new account name
                 serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);

+ 7 - 13
src/main/java/com/owncloud/android/services/OperationsService.java

@@ -117,15 +117,16 @@ public class OperationsService extends Service {
     public static final String ACTION_COPY_FILE = "COPY_FILE";
     public static final String ACTION_CHECK_CURRENT_CREDENTIALS = "CHECK_CURRENT_CREDENTIALS";
 
-    public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() +
-            ".OPERATION_ADDED";
-    public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() +
-            ".OPERATION_FINISHED";
+    public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
+    public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
 
+    private ServiceHandler mOperationsHandler;
+    private OperationsServiceBinder mOperationsBinder;
+
+    private SyncFolderHandler mSyncFolderHandler;
 
     private ConcurrentMap<Integer, Pair<RemoteOperation, RemoteOperationResult>>
-            mUndispatchedFinishedOperations =
-            new ConcurrentHashMap<Integer, Pair<RemoteOperation, RemoteOperationResult>>();
+            mUndispatchedFinishedOperations = new ConcurrentHashMap<>();
 
     private static class Target {
         public Uri mServerUrl = null;
@@ -138,11 +139,6 @@ public class OperationsService extends Service {
             mCookie = cookie;
         }
     }
-
-    private ServiceHandler mOperationsHandler;
-    private OperationsServiceBinder mOperationsBinder;
-    
-    private SyncFolderHandler mSyncFolderHandler;
     
     /**
      * Service initialization
@@ -165,7 +161,6 @@ public class OperationsService extends Service {
         mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);
     }
 
-
     /**
      * Entry point to add a new operation to the queue of operations.
      * <p/>
@@ -709,7 +704,6 @@ public class OperationsService extends Service {
         }
     }
 
-
     /**
      * Notifies the currently subscribed listeners about the end of an operation.
      *

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

@@ -726,7 +726,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
         ListView mListView = (ListView) findViewById(android.R.id.list);
 
         String current_dir = mParents.peek();
-        if (current_dir.equals("")) {
+        if ("".equals(current_dir)) {
             actionBar.setTitle(getString(R.string.uploader_top_message));
         } else {
             actionBar.setTitle(current_dir);
@@ -953,7 +953,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
 
         String lastPath = PreferenceManager.getLastUploadPath(this);
         // "/" equals root-directory
-        if (lastPath.equals("/")) {
+        if ("/".equals(lastPath)) {
             mParents.add("");
         } else {
             String[] dir_names = lastPath.split("/");

+ 4 - 3
src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -67,11 +67,14 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 public class ExpandableUploadListAdapter extends BaseExpandableListAdapter implements Observer {
 
     private static final String TAG = ExpandableUploadListAdapter.class.getSimpleName();
+
+    public ProgressListener mProgressListener;
+
     private FileActivity mParentActivity;
 
     private UploadsStorageManager mUploadsStorageManager;
 
-    public ProgressListener mProgressListener;
+    private UploadGroup[] mUploadGroups = null;
 
     interface Refresh {
         public void refresh();
@@ -141,8 +144,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         abstract public int getGroupIcon();
     }
 
-    private UploadGroup[] mUploadGroups = null;
-
     public ExpandableUploadListAdapter(FileActivity parentActivity) {
         Log_OC.d(TAG, "ExpandableUploadListAdapter");
         mParentActivity = parentActivity;

+ 14 - 15
src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

@@ -48,6 +48,20 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
 
     private final String TAG = CopyAndUploadContentUrisTask.class.getSimpleName();
 
+    /**
+     * Listener in main thread to be notified when the task ends. Held in a WeakReference assuming that its
+     * lifespan is associated with an Activity context, that could be finished by the user before the AsyncTask
+     * ends.
+     */
+    private WeakReference<OnCopyTmpFilesTaskListener> mListener;
+
+    /**
+     * Reference to application context, used to access app resources. Holding it should not be a problem,
+     * since it needs to exist until the end of the AsyncTask although the caller Activity were finished
+     * before.
+     */
+    private final Context mAppContext;
+
     /**
      * Helper method building a correct array of parameters to be passed to {@link #execute(Object[])} )}
      *
@@ -93,21 +107,6 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
         };
     }
 
-    /**
-     * Listener in main thread to be notified when the task ends. Held in a WeakReference assuming that its
-     * lifespan is associated with an Activity context, that could be finished by the user before the AsyncTask
-     * ends.
-     */
-    private WeakReference<OnCopyTmpFilesTaskListener> mListener;
-
-    /**
-     * Reference to application context, used to access app resources. Holding it should not be a problem,
-     * since it needs to exist until the end of the AsyncTask although the caller Activity were finished
-     * before.
-     */
-    private final Context mAppContext;
-
-
     public CopyAndUploadContentUrisTask(
         OnCopyTmpFilesTaskListener listener,
         Context context

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

@@ -1020,7 +1020,8 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
     private void updateFooter() {
         if (!mJustFolders) {
-            int filesCount = 0, foldersCount = 0;
+            int filesCount = 0;
+            int foldersCount = 0;
             int count = mAdapter.getCount();
             OCFile file;
             for (int i = 0; i < count; i++) {

+ 3 - 8
src/main/java/org/nextcloud/providers/DocumentsStorageProvider.java

@@ -178,7 +178,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
 
     private void initiateStorageMap() {
 
-        mRootIdToStorageManager = new HashMap<Long, FileDataStorageManager>();
+        mRootIdToStorageManager = new HashMap<>();
 
         ContentResolver contentResolver = getContext().getContentResolver();
 
@@ -188,7 +188,6 @@ public class DocumentsStorageProvider extends DocumentsProvider {
             final OCFile rootDir = storageManager.getFileByPath("/");
             mRootIdToStorageManager.put(rootDir.getFileId(), storageManager);
         }
-
     }
 
     private boolean waitOrGetCancelled(CancellationSignal cancellationSignal) {
@@ -198,15 +197,11 @@ public class DocumentsStorageProvider extends DocumentsProvider {
             return false;
         }
 
-        if (cancellationSignal != null && cancellationSignal.isCanceled()) {
-            return false;
-        }
-
-        return true;
+        return !(cancellationSignal != null && cancellationSignal.isCanceled());
     }
 
     Vector<OCFile> findFiles(OCFile root, String query) {
-        Vector<OCFile> result = new Vector<OCFile>();
+        Vector<OCFile> result = new Vector<>();
         for (OCFile f : mCurrentStorageManager.getFolderContent(root, false)) {
             if (f.isFolder()) {
                 result.addAll(findFiles(f, query));