Merge pull request #4681 from nextcloud/codacy

Codacy
This commit is contained in:
Tobias Kaminsky 2019-10-15 12:16:50 +02:00 committed by GitHub
commit 2286981dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 12 deletions

View file

@ -1 +1 @@
427
426

View file

@ -119,7 +119,7 @@ public final class MediaProvider {
MediaStore.MediaColumns.DATA));
// check if valid path and file exists
if (filePath != null && filePath.lastIndexOf('/') > 0 && new File(filePath).exists()) {
if (isValidAndExistingFilePath(filePath)) {
mediaFolder.filePaths.add(filePath);
mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf('/'));
}
@ -127,7 +127,7 @@ public final class MediaProvider {
cursorImages.close();
// only do further work if folder is not within the Nextcloud app itself
if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
if (isFolderOutsideOfAppPath(dataPath, mediaFolder)) {
// count images
Cursor count = contentResolver.query(
@ -152,6 +152,14 @@ public final class MediaProvider {
return mediaFolders;
}
private static boolean isFolderOutsideOfAppPath(String dataPath, MediaFolder mediaFolder) {
return mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath);
}
private static boolean isValidAndExistingFilePath(String filePath) {
return filePath != null && filePath.lastIndexOf('/') > 0 && new File(filePath).exists();
}
private static void checkPermissions(@Nullable Activity activity) {
if (activity != null &&
!PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
@ -229,7 +237,7 @@ public final class MediaProvider {
cursorVideos.close();
// only do further work if folder is not within the Nextcloud app itself
if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
if (isFolderOutsideOfAppPath(dataPath, mediaFolder)) {
// count images
Cursor count = contentResolver.query(

View file

@ -89,6 +89,7 @@ public class FileContentProvider extends ContentProvider {
private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
private static final int SINGLE_PATH_SEGMENT = 1;
public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;
private DataBaseHelper mDbHelper;
private Context mContext;
@ -186,7 +187,7 @@ public class FileContentProvider extends ContentProvider {
children.close();
}
if (uri.getPathSegments().size() > 1) {
if (uri.getPathSegments().size() > MINIMUM_PATH_SEGMENTS_SIZE) {
count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1)
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""), whereArgs);

View file

@ -170,7 +170,7 @@ public class SettingsActivity extends PreferenceActivity
setupDetailsCategory(accentColor, preferenceScreen);
// More
setupMoreCategory(accentColor, appVersion);
setupMoreCategory(accentColor);
// About
setupAboutCategory(accentColor, appVersion);
@ -308,7 +308,7 @@ public class SettingsActivity extends PreferenceActivity
}
}
private void setupMoreCategory(int accentColor, String appVersion) {
private void setupMoreCategory(int accentColor) {
PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
preferenceCategoryMore.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more),
accentColor));

View file

@ -81,10 +81,8 @@ public class PrintAsyncTask extends AsyncTask<Void, Void, Boolean> {
try {
int status = client.executeMethod(getMethod);
if (status == HttpStatus.SC_OK) {
if (file.exists()) {
if (!file.delete()) {
return false;
}
if (file.exists() && !file.delete()) {
return false;
}
file.getParentFile().mkdirs();

View file

@ -79,7 +79,6 @@ import javax.inject.Inject;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
/**
* This fragment shows a preview of a downloaded media file (audio or video).