Kaynağa Gözat

Merge pull request #7127 from nextcloud/codacy

Codacy: Code Style Improvements
Andy Scherzinger 4 yıl önce
ebeveyn
işleme
af09ee9191
30 değiştirilmiş dosya ile 169 ekleme ve 138 silme
  1. 10 1
      scripts/analysis/analysis-wrapper.sh
  2. 1 1
      scripts/analysis/findbugs-results.txt
  3. 2 1
      src/main/java/com/owncloud/android/datamodel/DecryptedPushMessage.java
  4. 22 14
      src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java
  5. 1 0
      src/main/java/com/owncloud/android/datamodel/FileSystemDataSet.java
  6. 0 3
      src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.java
  7. 1 0
      src/main/java/com/owncloud/android/datamodel/PushConfigurationState.java
  8. 1 0
      src/main/java/com/owncloud/android/datamodel/SignatureVerification.java
  9. 25 25
      src/main/java/com/owncloud/android/datamodel/Template.java
  10. 1 1
      src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
  11. 6 5
      src/main/java/com/owncloud/android/datastorage/StoragePoint.java
  12. 2 4
      src/main/java/com/owncloud/android/media/MediaControlView.java
  13. 71 55
      src/main/java/com/owncloud/android/operations/CreateFolderOperation.java
  14. 6 10
      src/main/java/com/owncloud/android/operations/UploadFileOperation.java
  15. 2 2
      src/main/java/com/owncloud/android/ui/activity/ContactsPreferenceActivity.java
  16. 1 1
      src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java
  17. 2 2
      src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java
  18. 1 1
      src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java
  19. 1 0
      src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java
  20. 1 1
      src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java
  21. 2 2
      src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java
  22. 1 1
      src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java
  23. 2 2
      src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java
  24. 2 2
      src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java
  25. 1 0
      src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java
  26. 1 0
      src/main/java/com/owncloud/android/ui/events/SearchEvent.java
  27. 1 0
      src/main/java/com/owncloud/android/ui/events/SyncEventFinished.java
  28. 1 2
      src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java
  29. 0 2
      src/main/java/com/owncloud/android/utils/FileStorageUtils.java
  30. 1 0
      src/main/java/com/owncloud/android/utils/svg/SvgDecoder.java

+ 10 - 1
scripts/analysis/analysis-wrapper.sh

@@ -127,7 +127,12 @@ else
         gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
     fi
 
-    curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$codacyResult $lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage $lintMessage $findbugsMessage $gplayLimitation \" }"
+    # check for NotNull
+    if [[ $(grep org.jetbrains.annotations src/main/* -ir -c) -gt 0 ]] ; then
+        notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
+    fi
+
+    curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$codacyResult $lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage $lintMessage $findbugsMessage $gplayLimitation $notNull\" }"
 
     if [ ! -z "$gplayLimitation" ]; then
         exit 1
@@ -141,6 +146,10 @@ else
         exit $lintValue
     fi
 
+    if [ $notNull -gt 0 ]; then
+        exit 1
+    fi
+
     if [ $findbugsValue -eq 2 ]; then
         exit 0
     else

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-319
+316

+ 2 - 1
src/main/java/com/owncloud/android/datamodel/DecryptedPushMessage.java

@@ -24,10 +24,10 @@ import com.google.gson.annotations.SerializedName;
 
 import org.parceler.Parcel;
 
-@Parcel
 /*
  * Push data from server, https://github.com/nextcloud/notifications/blob/master/docs/push-v2.md#encrypted-subject-data
  */
+@Parcel
 public class DecryptedPushMessage {
     public String app;
     public String type;
@@ -49,6 +49,7 @@ public class DecryptedPushMessage {
     }
 
     public DecryptedPushMessage() {
+        // empty constructor
     }
 
     public String getApp() {

+ 22 - 14
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1178,13 +1178,11 @@ public class FileDataStorageManager {
      */
     public List<OCShare> getSharesByPathAndType(String path, ShareType type, String shareWith) {
         Cursor cursor;
-        if (shareWith == null) {
-            shareWith = "";
-        }
 
         String selection = ProviderTableMeta.OCSHARES_PATH + AND
             + ProviderTableMeta.OCSHARES_SHARE_TYPE + AND
             + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?";
+
         if (!ShareType.PUBLIC_LINK.equals(type)) {
             selection += " AND " + ProviderTableMeta.OCSHARES_SHARE_WITH + " = ?";
         }
@@ -1197,12 +1195,21 @@ public class FileDataStorageManager {
                 account.name
             };
         } else {
-            selectionArgs = new String[]{
-                path,
-                Integer.toString(type.getValue()),
-                account.name,
-                shareWith
-            };
+            if (shareWith == null) {
+                selectionArgs = new String[]{
+                    path,
+                    Integer.toString(type.getValue()),
+                    account.name,
+                    ""
+                };
+            } else {
+                selectionArgs = new String[]{
+                    path,
+                    Integer.toString(type.getValue()),
+                    account.name,
+                    shareWith
+                };
+            }
         }
 
         if (getContentResolver() != null) {
@@ -1775,11 +1782,13 @@ public class FileDataStorageManager {
     }
 
     public void saveConflict(OCFile ocFile, String etagInConflict) {
+        ContentValues cv = new ContentValues();
         if (!ocFile.isDown()) {
-            etagInConflict = null;
+            cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, (String) null);
+        } else {
+            cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, etagInConflict);
         }
-        ContentValues cv = new ContentValues();
-        cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, etagInConflict);
+
         int updated = 0;
         if (getContentResolver() != null) {
             updated = getContentResolver().update(
@@ -1804,7 +1813,7 @@ public class FileDataStorageManager {
         Log_OC.d(TAG, "Number of files updated with CONFLICT: " + updated);
 
         if (updated > 0) {
-            if (etagInConflict != null) {
+            if (etagInConflict != null && ocFile.isDown()) {
                 /// set conflict in all ancestor folders
 
                 long parentId = ocFile.getParentId();
@@ -1922,7 +1931,6 @@ public class FileDataStorageManager {
                 }
             }
         }
-
     }
 
     public void saveCapabilities(OCCapability capability) {

+ 1 - 0
src/main/java/com/owncloud/android/datamodel/FileSystemDataSet.java

@@ -49,6 +49,7 @@ public class FileSystemDataSet {
     }
 
     public FileSystemDataSet() {
+        // empty constructor
     }
 
     public int getId() {

+ 0 - 3
src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.java

@@ -33,9 +33,6 @@ public class MediaFoldersModel {
         this.videoMediaFolders = videoMediaFolders;
     }
 
-    public MediaFoldersModel() {
-    }
-
     public List<String> getImageMediaFolders() {
         return this.imageMediaFolders;
     }

+ 1 - 0
src/main/java/com/owncloud/android/datamodel/PushConfigurationState.java

@@ -38,6 +38,7 @@ public class PushConfigurationState {
     }
 
     public PushConfigurationState() {
+        // empty constructor for JSON parser
     }
 
     public String getPushToken() {

+ 1 - 0
src/main/java/com/owncloud/android/datamodel/SignatureVerification.java

@@ -34,6 +34,7 @@ public class SignatureVerification {
     }
 
     public SignatureVerification() {
+        // empty constructor
     }
 
     public boolean isSignatureValid() {

+ 25 - 25
src/main/java/com/owncloud/android/datamodel/Template.java

@@ -27,9 +27,18 @@ import java.util.Locale;
 /**
  * Template for creating a file from it via RichDocuments app
  */
-
 @Parcel
 public class Template {
+    public int id;
+    public String name;
+    public String thumbnailLink;
+    public Type type;
+    public String extension;
+
+    public Template() {
+        // empty constructor
+    }
+
     public Template(int id, String name, String thumbnailLink, Type type, String extension) {
         this.id = id;
         this.name = name;
@@ -38,7 +47,21 @@ public class Template {
         this.extension = extension;
     }
 
-    public Template() {
+    public enum Type {
+        DOCUMENT, SPREADSHEET, PRESENTATION, UNKNOWN
+    }
+
+    public static Type parse(String type) {
+        switch (type.toLowerCase(Locale.US)) {
+            case "document":
+                return Type.DOCUMENT;
+            case "spreadsheet":
+                return Type.SPREADSHEET;
+            case "presentation":
+                return Type.PRESENTATION;
+            default:
+                return Type.UNKNOWN;
+        }
     }
 
     public int getId() {
@@ -80,27 +103,4 @@ public class Template {
     public void setExtension(String extension) {
         this.extension = extension;
     }
-
-    public enum Type {
-        DOCUMENT, SPREADSHEET, PRESENTATION, UNKNOWN
-    }
-
-    public static Type parse(String type) {
-        switch (type.toLowerCase(Locale.US)) {
-            case "document":
-                return Type.DOCUMENT;
-            case "spreadsheet":
-                return Type.SPREADSHEET;
-            case "presentation":
-                return Type.PRESENTATION;
-            default:
-                return Type.UNKNOWN;
-        }
-    }
-
-    public int id;
-    public String name;
-    public String thumbnailLink;
-    public Type type;
-    public String extension;
 }

+ 1 - 1
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -933,7 +933,7 @@ public final class ThumbnailsCacheManager {
             avatar = getBitmapFromDiskCache(avatarKey);
 
             // Download avatar from server, only if older than 60 min or avatar does not exist
-            if ((System.currentTimeMillis() - timestamp >= 60 * 60 * 1000 || avatar == null)) {
+            if (System.currentTimeMillis() - timestamp >= 60 * 60 * 1000 || avatar == null) {
                 GetMethod get = null;
                 try {
                     if (mAccount != null) {

+ 6 - 5
src/main/java/com/owncloud/android/datastorage/StoragePoint.java

@@ -25,6 +25,11 @@ package com.owncloud.android.datastorage;
  * @author Bartosz Przybylski
  */
 public class StoragePoint implements Comparable<StoragePoint> {
+    private String description;
+    private String path;
+    private StorageType storageType;
+    private PrivacyType privacyType;
+
     public StoragePoint(String description, String path, StorageType storageType, PrivacyType privacyType) {
         this.description = description;
         this.path = path;
@@ -33,6 +38,7 @@ public class StoragePoint implements Comparable<StoragePoint> {
     }
 
     public StoragePoint() {
+        // empty constructor
     }
 
     public String getDescription() {
@@ -75,11 +81,6 @@ public class StoragePoint implements Comparable<StoragePoint> {
         PRIVATE, PUBLIC
     }
 
-    private String description;
-    private String path;
-    private StorageType storageType;
-    private PrivacyType privacyType;
-
     @Override
     public int compareTo(StoragePoint another) {
         return path.compareTo(another.getPath());

+ 2 - 4
src/main/java/com/owncloud/android/media/MediaControlView.java

@@ -165,13 +165,11 @@ public class MediaControlView extends FrameLayout implements OnClickListener, On
     private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
-            int pos;
             if (msg.what == SHOW_PROGRESS) {
                 updatePausePlay();
-                pos = setProgress();
+                int pos = setProgress();
                 if (!isDragging) {
-                    msg = obtainMessage(SHOW_PROGRESS);
-                    sendMessageDelayed(msg, 1000 - (pos % 1000));
+                    sendMessageDelayed(obtainMessage(SHOW_PROGRESS), 1000 - (pos % 1000));
                 }
             }
         }

+ 71 - 55
src/main/java/com/owncloud/android/operations/CreateFolderOperation.java

@@ -46,13 +46,14 @@ import com.owncloud.android.utils.MimeType;
 import java.io.File;
 import java.util.UUID;
 
+import androidx.annotation.NonNull;
+
 import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
 import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
 
-
 /**
- * Access to remote operation performing the creation of a new folder in the ownCloud server. Save the new folder in
- * Database
+ * Access to remote operation performing the creation of a new folder in the ownCloud server.
+ * Save the new folder in Database.
  */
 public class CreateFolderOperation extends SyncOperation implements OnRemoteOperationListener {
 
@@ -75,8 +76,8 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
         String remoteParentPath = new File(getRemotePath()).getParent();
-        remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
-            remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
+        remoteParentPath = remoteParentPath.endsWith(PATH_SEPARATOR) ?
+            remoteParentPath : remoteParentPath + PATH_SEPARATOR;
 
         OCFile parent = getStorageManager().getFileByDecryptedRemotePath(remoteParentPath);
 
@@ -84,8 +85,8 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
         while (parent == null) {
             tempRemoteParentPath = new File(tempRemoteParentPath).getParent();
 
-            if (!tempRemoteParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
-                tempRemoteParentPath = tempRemoteParentPath + OCFile.PATH_SEPARATOR;
+            if (!tempRemoteParentPath.endsWith(PATH_SEPARATOR)) {
+                tempRemoteParentPath = tempRemoteParentPath + PATH_SEPARATOR;
             }
 
             parent = getStorageManager().getFileByDecryptedRemotePath(tempRemoteParentPath);
@@ -95,13 +96,13 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
         boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
 
         if (encryptedAncestor) {
-            return encryptedCreate(parent, remoteParentPath, client);
+            return encryptedCreate(parent, client);
         } else {
             return normalCreate(client);
         }
     }
 
-    private RemoteOperationResult encryptedCreate(OCFile parent, String remoteParentPath, OwnCloudClient client) {
+    private RemoteOperationResult encryptedCreate(OCFile parent, OwnCloudClient client) {
         ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
         String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY);
         String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY);
@@ -127,20 +128,12 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
             metadata = metadataPair.second;
 
             // check if filename already exists
-            for (String key : metadata.getFiles().keySet()) {
-                DecryptedFolderMetadata.DecryptedFile file = metadata.getFiles().get(key);
-
-                if (file != null && filename.equalsIgnoreCase(file.getEncrypted().getFilename())) {
-                    return new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS);
-                }
+            if (isFileExisting(metadata, filename)) {
+                return new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS);
             }
 
             // generate new random file name, check if it exists in metadata
-            String encryptedFileName = UUID.randomUUID().toString().replaceAll("-", "");
-
-            while (metadata.getFiles().get(encryptedFileName) != null) {
-                encryptedFileName = UUID.randomUUID().toString().replaceAll("-", "");
-            }
+            String encryptedFileName = createRandomFileName(metadata);
             encryptedRemotePath = parent.getRemotePath() + encryptedFileName;
 
             RemoteOperationResult result = new CreateFolderRemoteOperation(encryptedRemotePath,
@@ -149,23 +142,8 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
                 .execute(client);
 
             if (result.isSuccess()) {
-                // Key, always generate new one
-                byte[] key = EncryptionUtils.generateKey();
-
-                // IV, always generate new one
-                byte[] iv = EncryptionUtils.randomBytes(EncryptionUtils.ivLength);
-
                 // update metadata
-                DecryptedFolderMetadata.DecryptedFile decryptedFile = new DecryptedFolderMetadata.DecryptedFile();
-                DecryptedFolderMetadata.Data data = new DecryptedFolderMetadata.Data();
-                data.setFilename(filename);
-                data.setMimetype(MimeType.WEBDAV_FOLDER);
-                data.setKey(EncryptionUtils.encodeBytesToBase64String(key));
-
-                decryptedFile.setEncrypted(data);
-                decryptedFile.setInitializationVector(EncryptionUtils.encodeBytesToBase64String(iv));
-
-                metadata.getFiles().put(encryptedFileName, decryptedFile);
+                metadata.getFiles().put(encryptedFileName, createDecryptedFile(filename));
 
                 EncryptedFolderMetadata encryptedFolderMetadata = EncryptionUtils.encryptFolderMetadata(metadata,
                                                                                                         privateKey);
@@ -194,15 +172,7 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
                     .execute(client);
 
                 createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
-                OCFile newDir = new OCFile(createdRemoteFolder.getRemotePath());
-                newDir.setMimeType(MimeType.DIRECTORY);
-
-                newDir.setParentId(parent.getFileId());
-                newDir.setRemoteId(createdRemoteFolder.getRemoteId());
-                newDir.setModificationTimestamp(System.currentTimeMillis());
-                newDir.setEncrypted(true);
-                newDir.setPermissions(createdRemoteFolder.getPermissions());
-                newDir.setDecryptedRemotePath(parent.getDecryptedRemotePath() + filename + "/");
+                OCFile newDir = createRemoteFolderOcFile(parent, filename, createdRemoteFolder);
                 getStorageManager().saveFile(newDir);
 
                 RemoteOperationResult encryptionOperationResult = new ToggleEncryptionRemoteOperation(
@@ -221,16 +191,6 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
 
             return result;
         } catch (Exception e) {
-//            // revert to latest metadata
-//            try {
-//                Pair<Boolean, DecryptedFolderMetadata> metadataPair = EncryptionUtils.retrieveMetadata(parent,
-//                                                                                                       client,
-//                                                                                                       privateKey,
-//                                                                                                       publicKey);
-//            } catch (Exception metadataException) {
-//                throw new RuntimeException(metadataException);
-//            }
-
             if (!EncryptionUtils.unlockFolder(parent, client, token).isSuccess()) {
                 throw new RuntimeException("Could not clean up after failing folder creation!");
             }
@@ -263,6 +223,62 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
         }
     }
 
+    private boolean isFileExisting(DecryptedFolderMetadata metadata, String filename) {
+        for (String key : metadata.getFiles().keySet()) {
+            DecryptedFolderMetadata.DecryptedFile file = metadata.getFiles().get(key);
+
+            if (file != null && filename.equalsIgnoreCase(file.getEncrypted().getFilename())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @NonNull
+    private OCFile createRemoteFolderOcFile(OCFile parent, String filename, RemoteFile remoteFolder) {
+        OCFile newDir = new OCFile(remoteFolder.getRemotePath());
+
+        newDir.setMimeType(MimeType.DIRECTORY);
+        newDir.setParentId(parent.getFileId());
+        newDir.setRemoteId(remoteFolder.getRemoteId());
+        newDir.setModificationTimestamp(System.currentTimeMillis());
+        newDir.setEncrypted(true);
+        newDir.setPermissions(remoteFolder.getPermissions());
+        newDir.setDecryptedRemotePath(parent.getDecryptedRemotePath() + filename + "/");
+
+        return newDir;
+    }
+
+    @NonNull
+    private DecryptedFolderMetadata.DecryptedFile createDecryptedFile(String filename) {
+        // Key, always generate new one
+        byte[] key = EncryptionUtils.generateKey();
+
+        // IV, always generate new one
+        byte[] iv = EncryptionUtils.randomBytes(EncryptionUtils.ivLength);
+
+        DecryptedFolderMetadata.DecryptedFile decryptedFile = new DecryptedFolderMetadata.DecryptedFile();
+        DecryptedFolderMetadata.Data data = new DecryptedFolderMetadata.Data();
+        data.setFilename(filename);
+        data.setMimetype(MimeType.WEBDAV_FOLDER);
+        data.setKey(EncryptionUtils.encodeBytesToBase64String(key));
+
+        decryptedFile.setEncrypted(data);
+        decryptedFile.setInitializationVector(EncryptionUtils.encodeBytesToBase64String(iv));
+
+        return decryptedFile;
+    }
+
+    @NonNull
+    private String createRandomFileName(DecryptedFolderMetadata metadata) {
+        String encryptedFileName = UUID.randomUUID().toString().replaceAll("-", "");
+
+        while (metadata.getFiles().get(encryptedFileName) != null) {
+            encryptedFileName = UUID.randomUUID().toString().replaceAll("-", "");
+        }
+        return encryptedFileName;
+    }
+
     private RemoteOperationResult normalCreate(OwnCloudClient client) {
         RemoteOperationResult result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
 

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

@@ -25,7 +25,6 @@ import android.accounts.Account;
 import android.annotation.SuppressLint;
 import android.content.Context;
 import android.net.Uri;
-import android.os.Build;
 import android.text.TextUtils;
 import android.util.Log;
 import android.util.Pair;
@@ -87,7 +86,6 @@ import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import androidx.annotation.CheckResult;
-import androidx.annotation.RequiresApi;
 
 
 /**
@@ -150,12 +148,6 @@ public class UploadFileOperation extends SyncOperation {
     private boolean encryptedAncestor;
 
     public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
-
-        // MIME type
-        if (TextUtils.isEmpty(mimeType)) {
-            mimeType = MimeTypeUtil.getBestMimeTypeByFilename(localPath);
-        }
-
         OCFile newFile = new OCFile(remotePath);
         newFile.setStoragePath(localPath);
         newFile.setLastSyncDateForProperties(0);
@@ -169,8 +161,12 @@ public class UploadFileOperation extends SyncOperation {
         } // don't worry about not assigning size, the problems with localPath
         // are checked when the UploadFileOperation instance is created
 
-
-        newFile.setMimeType(mimeType);
+        // MIME type
+        if (TextUtils.isEmpty(mimeType)) {
+            newFile.setMimeType(MimeTypeUtil.getBestMimeTypeByFilename(localPath));
+        } else {
+            newFile.setMimeType(mimeType);
+        }
 
         return newFile;
     }

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

@@ -55,6 +55,8 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
     public static final String PREFERENCE_CONTACTS_LAST_BACKUP = "PREFERENCE_CONTACTS_LAST_BACKUP";
     public static final String BACKUP_TO_LIST = "BACKUP_TO_LIST";
 
+    @Inject BackgroundJobManager backgroundJobManager;
+
     public static void startActivity(Context context) {
         Intent intent = new Intent(context, ContactsPreferenceActivity.class);
         context.startActivity(intent);
@@ -73,8 +75,6 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
         context.startActivity(intent);
     }
 
-    @Inject BackgroundJobManager backgroundJobManager;
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

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

@@ -330,7 +330,7 @@ public abstract class DrawerActivity extends ToolbarActivity
 
         switch (menuItem.getItemId()) {
             case R.id.nav_all_files:
-                if ((this instanceof FileDisplayActivity) &&
+                if (this instanceof FileDisplayActivity &&
                     !(((FileDisplayActivity) this).getLeftFragment() instanceof PhotoFragment) &&
                     !(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment)) {
                     showFiles(false);

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

@@ -144,7 +144,6 @@ import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
 /**
  * Displays, what files the user has available in his ownCloud. This is the main view.
  */
-
 public class FileDisplayActivity extends FileActivity
         implements FileFragment.ContainerActivity,
         OnEnforceableRefreshListener, SortingOrderDialogFragment.OnSortingOrderListener,
@@ -153,6 +152,7 @@ public class FileDisplayActivity extends FileActivity
     public static final String RESTART = "RESTART";
     public static final String ALL_FILES = "ALL_FILES";
     public static final String PHOTO_SEARCH = "PHOTO_SEARCH";
+    public static final int SINGLE_USER_SIZE = 1;
 
     private FilesBinding binding;
 
@@ -2466,7 +2466,7 @@ public class FileDisplayActivity extends FileActivity
         } else if (match.getUsers().isEmpty()) {
             dismissLoadingDialog();
             DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
-        } else if (match.getUsers().size() == 1) {
+        } else if (match.getUsers().size() == SINGLE_USER_SIZE) {
             openFile(match.getUsers().get(0), match.getFileId());
         } else {
             selectUserAndOpenFile(match.getUsers(), match.getFileId());

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

@@ -475,7 +475,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
             PopupMenu popup = new PopupMenu(this, view);
             popup.getMenuInflater().inflate(R.menu.item_account, popup.getMenu());
 
-            if((accountManager.getUser()).equals(user)) {
+            if(accountManager.getUser().equals(user)) {
                 popup.getMenu().findItem(R.id.action_open_account).setVisible(false);
             }
             popup.setOnMenuItemClickListener(item -> {

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

@@ -230,6 +230,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
 
             @Override
             public void onNothingSelected(AdapterView<?> parent) {
+                // no action
             }
         });
 

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

@@ -154,7 +154,7 @@ public class UserInfoActivity extends DrawerActivity implements Injectable {
 
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
-        if ((accountManager.getUser()).equals(user)) {
+        if (accountManager.getUser().equals(user)) {
             menu.findItem(R.id.action_open_account).setVisible(false);
         }
         return super.onPrepareOptionsMenu(menu);

+ 2 - 2
src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -365,9 +365,9 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
             mFiles = mFilesAll;
         } else {
             List<File> result = new ArrayList<>();
-            text = text.toLowerCase(Locale.getDefault());
+            String filterText = text.toLowerCase(Locale.getDefault());
             for (File file : mFilesAll) {
-                if (file.getName().toLowerCase(Locale.getDefault()).contains(text)) {
+                if (file.getName().toLowerCase(Locale.getDefault()).contains(filterText)) {
                     result.add(file);
                 }
             }

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

@@ -144,7 +144,6 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
         int accentColor = ThemeUtils.primaryAccentColor(getContext());
 
         parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
-        Type type = Type.valueOf(arguments.getString(ARG_TYPE));
 
         // Inflate the layout for the dialog
         LayoutInflater inflater = activity.getLayoutInflater();
@@ -160,6 +159,7 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
             throw new RuntimeException(e); // we'll NPE without the client
         }
 
+        Type type = Type.valueOf(arguments.getString(ARG_TYPE));
         new FetchTemplateTask(this, client).execute(type);
 
         listView.setHasFixedSize(true);

+ 2 - 2
src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java

@@ -252,8 +252,6 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
                     return "";
                 }
 
-                OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
-
                 final ChooseTemplateDialogFragment fragment = chooseTemplateDialogFragmentWeakReference.get();
                 if (fragment == null) {
                     return "";
@@ -267,6 +265,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
 
                 FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
                                                                                    context.getContentResolver());
+
+                OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
                 storageManager.saveFile(temp);
                 file = storageManager.getFileByPath(path);
 

+ 2 - 2
src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -144,11 +144,11 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
         DrawableCompat.setTint(wrappedDrawable, primaryColor);
         passwordField.setBackgroundDrawable(wrappedDrawable);
 
-        return createDialog(primaryColor, v);
+        return createDialog(v);
     }
 
     @NonNull
-    private Dialog createDialog(int accentColor, View v) {
+    private Dialog createDialog(View v) {
         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
         builder.setView(v).setPositiveButton(R.string.common_ok, null)
                 .setNegativeButton(R.string.common_cancel, null)

+ 1 - 0
src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java

@@ -85,6 +85,7 @@ public class SyncedFolderParcelable implements Parcelable {
     }
 
     public SyncedFolderParcelable() {
+        // empty constructor
     }
 
     @Override

+ 1 - 0
src/main/java/com/owncloud/android/ui/events/SearchEvent.java

@@ -37,6 +37,7 @@ public class SearchEvent {
     }
 
     public SearchEvent() {
+        // empty constructor to create empty object
     }
 
     public String getSearchQuery() {

+ 1 - 0
src/main/java/com/owncloud/android/ui/events/SyncEventFinished.java

@@ -32,6 +32,7 @@ public class SyncEventFinished {
     }
 
     public SyncEventFinished() {
+        // empty constructor
     }
 
     public Intent getIntent() {

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

@@ -145,7 +145,6 @@ public class ContactListFragment extends FileFragment implements Injectable {
 
 
     private ContactListAdapter contactListAdapter;
-    private User user;
     private List<VCard> vCards = new ArrayList<>();
     private OCFile ocFile;
     @Inject UserAccountManager accountManager;
@@ -212,7 +211,7 @@ public class ContactListFragment extends FileFragment implements Injectable {
 
         ocFile = getArguments().getParcelable(FILE_NAME);
         setFile(ocFile);
-        user = getArguments().getParcelable(USER);
+        User user = getArguments().getParcelable(USER);
         fileDownloader = new TransferManagerConnection(getActivity(), user);
         fileDownloader.registerTransferListener(this::onDownloadUpdate);
         fileDownloader.bind();

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

@@ -21,7 +21,6 @@ package com.owncloud.android.utils;
 
 import android.Manifest;
 import android.accounts.Account;
-import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
@@ -64,7 +63,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 import static android.os.Build.VERSION.SDK_INT;
 
-
 /**
  * Static methods to help in access to local file system.
  */

+ 1 - 0
src/main/java/com/owncloud/android/utils/svg/SvgDecoder.java

@@ -34,6 +34,7 @@ public class SvgDecoder implements ResourceDecoder<InputStream, SVG> {
     }
 
     public SvgDecoder() {
+        // empty constructor
     }
 
     public Resource<SVG> decode(InputStream source, int w, int h) throws IOException {