Merge pull request #3867 from nextcloud/codacy

Codacy improvements
This commit is contained in:
Andy Scherzinger 2019-04-10 12:26:50 +02:00 committed by GitHub
commit 58702f0ce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 72 additions and 57 deletions

View file

@ -1,11 +1,30 @@
/*
* Nextcloud Android client application
*
* @author David Luhmer
* @author Tobias Kaminsky
* @author Edvard Holst
* Copyright (C) 2019 David Luhmer
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Edvard Holst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.android.sso;
public class Constants {
private Constants() {
// No instance
}
public final class Constants {
// Authenticator related constants
public static final String SSO_USERNAME = "username";
public static final String SSO_TOKEN = "token";
@ -16,7 +35,6 @@ public class Constants {
public static final String NEXTCLOUD_FILES_ACCOUNT = "NextcloudFilesAccount";
public static final String DELIMITER = "_";
// Custom Exceptions
public static final String EXCEPTION_INVALID_TOKEN = "CE_1";
public static final String EXCEPTION_ACCOUNT_NOT_FOUND = "CE_2";
@ -24,4 +42,8 @@ public class Constants {
public static final String EXCEPTION_INVALID_REQUEST_URL = "CE_4";
public static final String EXCEPTION_HTTP_REQUEST_FAILED = "CE_5";
public static final String EXCEPTION_ACCOUNT_ACCESS_DECLINED = "CE_6";
private Constants() {
// No instance
}
}

View file

@ -2,6 +2,7 @@
* Nextcloud SingleSignOn
*
* @author David Luhmer
* Copyright (C) 2019 David Luhmer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View file

@ -1,4 +1,4 @@
/**
/*
* ownCloud Android client application
*
* @author David A. Velasco
@ -25,13 +25,7 @@ package com.owncloud.android.authentication;
*
* Includes required and optional parameter NAMES used in the 'authorization code' grant type.
*/
public class OAuth2Constants {
private OAuth2Constants() {
// No instance
}
public final class OAuth2Constants {
/// Parameters to send to the Authorization Endpoint
public static final String KEY_RESPONSE_TYPE = "response_type";
public static final String KEY_REDIRECT_URI = "redirect_uri";
@ -54,5 +48,8 @@ public class OAuth2Constants {
public static final String KEY_ERROR_DESCRIPTION = "error_description";
public static final String KEY_ERROR_URI = "error_uri";
public static final String VALUE_ERROR_ACCESS_DENIED = "access_denied";
private OAuth2Constants() {
// No instance
}
}

View file

@ -996,7 +996,7 @@ public class FileDataStorageManager {
// Methods for Shares
public boolean saveShare(OCShare share) {
boolean overriden = false;
boolean overridden = false;
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
@ -1017,7 +1017,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, share.isHideFileDownload());
if (shareExistsForRemoteId(share.getRemoteId())) {// for renamed files; no more delete and create
overriden = true;
overridden = true;
if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
@ -1048,7 +1048,7 @@ public class FileDataStorageManager {
}
}
return overriden;
return overridden;
}
/**
@ -2140,10 +2140,10 @@ public class FileDataStorageManager {
public void saveVirtuals(VirtualFolderType type, List<ContentValues> values) {
if (getContentResolver() != null) {
getContentResolver().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
getContentResolver().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[0]));
} else {
try {
getContentProviderClient().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
getContentProviderClient().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[0]));
} catch (RemoteException e) {
Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
}

View file

@ -270,7 +270,7 @@ public final class ThumbnailsCacheManager {
private Bitmap doResizedImageInBackground() {
Bitmap thumbnail;
String imageKey = PREFIX_RESIZED_IMAGE + String.valueOf(file.getRemoteId());
String imageKey = PREFIX_RESIZED_IMAGE + file.getRemoteId();
// Check disk cache in background thread
thumbnail = getBitmapFromDiskCache(imageKey);
@ -509,7 +509,7 @@ public final class ThumbnailsCacheManager {
private Bitmap doThumbnailFromOCFileInBackground() {
Bitmap thumbnail;
ServerFileInterface file = (ServerFileInterface) mFile;
String imageKey = PREFIX_THUMBNAIL + String.valueOf(file.getRemoteId());
String imageKey = PREFIX_THUMBNAIL + file.getRemoteId();
// Check disk cache in background thread
thumbnail = getBitmapFromDiskCache(imageKey);

View file

@ -62,7 +62,7 @@ public class DataStorageProvider {
public StoragePoint[] getAvailableStoragePoints() {
if (mCachedStoragePoints.size() != 0) {
return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
return mCachedStoragePoints.toArray(new StoragePoint[0]);
}
List<String> paths = new ArrayList<>();
@ -126,7 +126,7 @@ public class DataStorageProvider {
}
}
return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
return mCachedStoragePoints.toArray(new StoragePoint[0]);
}
public String getStorageDescriptionByPath(String path) {

View file

@ -30,7 +30,6 @@ import com.owncloud.android.MainApp;
* Meta-Class that holds various static field information
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 44;
@ -39,11 +38,6 @@ public class ProviderMeta {
}
static public class ProviderTableMeta implements BaseColumns {
private ProviderTableMeta() {
// No instance
}
public static final String FILE_TABLE_NAME = "filelist";
public static final String OCSHARES_TABLE_NAME = "ocshares";
public static final String CAPABILITIES_TABLE_NAME = "capabilities";
@ -250,5 +244,9 @@ public class ProviderMeta {
public static final String FILESYSTEM_FILE_SENT_FOR_UPLOAD = "upload_triggered";
public static final String FILESYSTEM_SYNCED_FOLDER_ID = "syncedfolder_id";
public static final String FILESYSTEM_CRC32 = "crc32";
private ProviderTableMeta() {
// No instance
}
}
}

View file

@ -439,10 +439,6 @@ public class FileMenuFilter {
return isSingleSelection() && (MimeTypeUtil.isVideo(file) || MimeTypeUtil.isAudio(file));
}
private boolean allFiles() {
return mFiles != null && !containsFolder();
}
private boolean containsEncryptedFile() {
for (OCFile file : mFiles) {
if (!file.isFolder() && file.isEncrypted()) {

View file

@ -160,8 +160,6 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
}
private Cursor searchForUsersOrGroups(Uri uri) {
MatrixCursor response = null;
String lastPathSegment = uri.getLastPathSegment();
if (lastPathSegment == null) {
@ -192,20 +190,15 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
showErrorMessage(result);
}
MatrixCursor response = null;
// convert the responses from the OC server to the expected format
if (names.size() > 0) {
response = new MatrixCursor(COLUMNS);
Iterator<JSONObject> namesIt = names.iterator();
JSONObject item;
String displayName;
int icon = 0;
Uri dataUri;
int count = 0;
if (getContext() == null) {
throw new IllegalArgumentException("Context may not be null!");
}
response = new MatrixCursor(COLUMNS);
Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_USER).build();
Uri groupBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_GROUP).build();
Uri roomBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_ROOM).build();
@ -217,6 +210,12 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
.isTrue();
try {
Iterator<JSONObject> namesIt = names.iterator();
JSONObject item;
String displayName;
int icon = 0;
Uri dataUri;
int count = 0;
while (namesIt.hasNext()) {
item = namesIt.next();
dataUri = null;

View file

@ -128,7 +128,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
Log_OC.d(TAG, "Returning " + result.size() + " selected files");
return result.toArray(new String[result.size()]);
return result.toArray(new String[0]);
}
@Override

View file

@ -121,8 +121,8 @@ public class UriUploader {
if (!contentUris.isEmpty()) {
/// content: uris will be copied to temporary files before calling {@link FileUploader}
copyThenUpload(contentUris.toArray(new Uri[contentUris.size()]),
contentRemotePaths.toArray(new String[contentRemotePaths.size()]));
copyThenUpload(contentUris.toArray(new Uri[0]),
contentRemotePaths.toArray(new String[0]));
} else if (schemeFileCounter == 0) {
mCode = UriUploaderResultCode.ERROR_NO_FILE_TO_UPLOAD;

View file

@ -1,4 +1,4 @@
/**
/*
* Nextcloud Android client application
*
* Copyright (C) 2016 Nextcloud
@ -20,14 +20,13 @@ package com.owncloud.android.utils;
/**
* Class containing the mime types.
*/
public class MimeType {
private MimeType() {
// No instance
}
public final class MimeType {
public static final String DIRECTORY = "DIR";
public static final String JPEG = "image/jpeg";
public static final String TIFF = "image/tiff";
public static final String TEXT_PLAIN = "text/plain";
private MimeType() {
// No instance
}
}

View file

@ -78,6 +78,7 @@ public final class ThemeUtils {
private static final int INDEX_LUMINATION = 2;
private static final double MAX_LIGHTNESS = 0.92;
public static final double LUMINATION_THRESHOLD = 0.8;
private ThemeUtils() {
// utility class -> private constructor
@ -157,7 +158,7 @@ public final class ThemeUtils {
float[] hsl = colorToHSL(primaryColor);
if (hsl[INDEX_LUMINATION] > 0.8) {
if (hsl[INDEX_LUMINATION] > LUMINATION_THRESHOLD) {
return context.getResources().getColor(R.color.elementFallbackColor);
} else {
return primaryColor;
@ -421,7 +422,9 @@ public final class ThemeUtils {
}
public static void themeDialogActionButton(MaterialButton button) {
if (button == null ) return;
if (button == null ) {
return;
}
Context context = button.getContext();
int accentColor = ThemeUtils.primaryAccentColor(button.getContext());