Merge pull request #1010 from nextcloud/codacy

Further codacy fixes
This commit is contained in:
Mario Đanić 2017-05-24 00:10:02 +02:00 committed by GitHub
commit 55f346a1ad
11 changed files with 94 additions and 86 deletions

View file

@ -208,7 +208,10 @@ public class AccountUtils {
if (currentAccountVersion == null) {
Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION);
Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());
String serverUrl, username, newAccountName, password;
String serverUrl;
String username;
String newAccountName;
String password;
Account newAccount;
for (Account account : ocAccounts) {
// build new account name

View file

@ -279,49 +279,18 @@ public class FileDataStorageManager {
Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size()
+ " children and " + filesToRemove.size() + " files to remove");
ArrayList<ContentProviderOperation> operations =
new ArrayList<ContentProviderOperation>(updatedFiles.size());
ArrayList<ContentProviderOperation> operations = new ArrayList<>(updatedFiles.size());
// prepare operations to insert or update files to save in the given folder
for (OCFile file : updatedFiles) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
file.getModificationTimestampAtLastSyncForData()
);
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
//cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
if (!file.isFolder()) {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
}
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isAvailableOffline() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
cv.put(ProviderTableMeta.FILE_FAVORITE, file.getIsFavorite());
ContentValues cv = createContentValueForFile(file, folder);
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
// updating an existing file
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
withSelection(ProviderTableMeta._ID + "=?",
new String[]{String.valueOf(file.getFileId())})
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI)
.withValues(cv)
.withSelection(ProviderTableMeta._ID + "=?", new String[]{String.valueOf(file.getFileId())})
.build());
} else {
@ -332,17 +301,14 @@ public class FileDataStorageManager {
}
// prepare operations to remove files in the given folder
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
ProviderTableMeta.FILE_PATH + "=?";
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
String [] whereArgs = null;
for (OCFile file : filesToRemove) {
if (file.getParentId() == folder.getFileId()) {
whereArgs = new String[]{mAccount.name, file.getRemotePath()};
if (file.isFolder()) {
operations.add(ContentProviderOperation.newDelete(
ContentUris.withAppendedId(
ProviderTableMeta.CONTENT_URI_DIR, file.getFileId()
)
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, file.getFileId())
).withSelection(where, whereArgs).build());
File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
@ -351,8 +317,7 @@ public class FileDataStorageManager {
}
} else {
operations.add(ContentProviderOperation.newDelete(
ContentUris.withAppendedId(
ProviderTableMeta.CONTENT_URI_FILE, file.getFileId()
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId()
)
).withSelection(where, whereArgs).build());
@ -366,29 +331,7 @@ public class FileDataStorageManager {
}
// update metadata of folder
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp());
cv.put(
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
folder.getModificationTimestampAtLastSyncForData()
);
cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName());
cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.isAvailableOffline() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
cv.put(ProviderTableMeta.FILE_FAVORITE, folder.getIsFavorite());
ContentValues cv = createContentValueForFile(folder);
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
@ -431,7 +374,67 @@ public class FileDataStorageManager {
}
}
}
}
private ContentValues createContentValueForFile(OCFile folder) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp());
cv.put(
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
folder.getModificationTimestampAtLastSyncForData()
);
cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName());
cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.isAvailableOffline() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
cv.put(ProviderTableMeta.FILE_FAVORITE, folder.getIsFavorite());
return cv;
}
private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
file.getModificationTimestampAtLastSyncForData()
);
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
//cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
if (!file.isFolder()) {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
}
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isAvailableOffline() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
cv.put(ProviderTableMeta.FILE_FAVORITE, file.getIsFavorite());
return cv;
}

View file

@ -425,12 +425,13 @@ public class ThumbnailsCacheManager {
thumbnail = doFileInBackground(mFile);
}
}
} // the app should never break due to a problem with thumbnails
catch (OutOfMemoryError t) {
Log_OC.e(TAG, "Generation of thumbnail for " + mFile.getAbsolutePath() + " failed", t);
System.gc();
} catch (Throwable t) {
// the app should never break due to a problem with thumbnails
Log_OC.e(TAG, "Generation of thumbnail for " + mFile.getAbsolutePath() + " failed", t);
if (t instanceof OutOfMemoryError) {
System.gc();
}
}
return thumbnail;

View file

@ -56,6 +56,13 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
// http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_VIDEO
private static final String NEW_VIDEO_ACTION = "android.hardware.action.NEW_VIDEO";
/**
* Because we support NEW_PHOTO_ACTION and NEW_PHOTO_ACTION_UNOFFICIAL it can happen that
* handleNewPictureAction is called twice for the same photo. Use this simple static variable to
* remember last uploaded photo to filter duplicates. Must not be null!
*/
static String lastUploadedPhotoPath = "";
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -75,13 +82,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
}
}
/**
* Because we support NEW_PHOTO_ACTION and NEW_PHOTO_ACTION_UNOFFICIAL it can happen that
* handleNewPictureAction is called twice for the same photo. Use this simple static variable to
* remember last uploaded photo to filter duplicates. Must not be null!
*/
static String lastUploadedPhotoPath = "";
private void handleNewPictureAction(Context context, Intent intent) {
Cursor c = null;
String file_path = null;

View file

@ -115,7 +115,8 @@ public class IndexedForest<V> {
String currentPath = remotePath;
String parentPath = null;
String parentKey = null;
Node<V> currentNode = valuedNode, parentNode = null;
Node<V> currentNode = valuedNode;
Node<V> parentNode = null;
boolean linked = false;
while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
parentPath = new File(currentPath).getParent();

View file

@ -508,7 +508,6 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
// nobody is bound
processStopRequest(true);
}
return;
}

View file

@ -136,7 +136,8 @@ public class CustomPopup {
LayoutParams.WRAP_CONTENT));
root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootW = root.getWidth(), rootH = root.getHeight();
int rootW = root.getWidth();
int rootH = root.getHeight();
int screenW = mWManager.getDefaultDisplay().getWidth();
int xpos = ((screenW - rootW) / 2) + x;

View file

@ -508,6 +508,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
case Menu.NONE:
// account clicked
accountClicked(menuItem.getTitle().toString());
break;
default:
Log_OC.i(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle());
}

View file

@ -757,7 +757,7 @@ public class FileDisplayActivity extends HookActivity
R.drawable.ic_view_list));
getListOfFilesFragment().setGridAsPreferred();
}
return true;
break;
}
default:
retval = super.onOptionsItemSelected(item);

View file

@ -49,6 +49,8 @@ public class CreateFolderDialogFragment
public static final String CREATE_FOLDER_FRAGMENT = "CREATE_FOLDER_FRAGMENT";
private OCFile mParentFolder;
/**
* Public factory method to create new CreateFolderDialogFragment instances.
*
@ -63,9 +65,6 @@ public class CreateFolderDialogFragment
return frag;
}
private OCFile mParentFolder;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

View file

@ -54,6 +54,8 @@ public class RenameFileDialogFragment
private static final String ARG_TARGET_FILE = "TARGET_FILE";
private OCFile mTargetFile;
/**
* Public factory method to create new RenameFileDialogFragment instances.
*
@ -69,8 +71,6 @@ public class RenameFileDialogFragment
}
private OCFile mTargetFile;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
mTargetFile = getArguments().getParcelable(ARG_TARGET_FILE);