Merge pull request #3588 from nextcloud/cleanup

Housekeeping: fix findbugs warnings
This commit is contained in:
Tobias Kaminsky 2019-02-12 08:28:51 +01:00 committed by GitHub
commit 5b558b13fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 103 additions and 260 deletions

View file

@ -1 +1 @@
526
484

View file

@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 69 warnings</span>
<span class="mdl-layout-title">Lint Report: 68 warnings</span>

View file

@ -31,11 +31,8 @@ import com.owncloud.android.operations.common.SyncOperation;
*/
public class CopyFileOperation extends SyncOperation {
//private static final String TAG = MoveFileOperation.class.getSimpleName();
private String mSrcPath;
private String mTargetParentPath;
private OCFile mFile;
private String srcPath;
private String targetParentPath;
/**
* Constructor
@ -44,13 +41,11 @@ public class CopyFileOperation extends SyncOperation {
* @param targetParentPath Path to the folder where the file will be copied into.
*/
public CopyFileOperation(String srcPath, String targetParentPath) {
mSrcPath = srcPath;
mTargetParentPath = targetParentPath;
if (!mTargetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
mTargetParentPath += OCFile.PATH_SEPARATOR;
this.srcPath = srcPath;
this.targetParentPath = targetParentPath;
if (!this.targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
this.targetParentPath += OCFile.PATH_SEPARATOR;
}
mFile = null;
}
/**
@ -61,24 +56,24 @@ public class CopyFileOperation extends SyncOperation {
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
/// 1. check copy validity
if (mTargetParentPath.startsWith(mSrcPath)) {
if (targetParentPath.startsWith(srcPath)) {
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
}
mFile = getStorageManager().getFileByPath(mSrcPath);
if (mFile == null) {
OCFile file = getStorageManager().getFileByPath(srcPath);
if (file == null) {
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
}
/// 2. remote copy
String targetPath = mTargetParentPath + mFile.getFileName();
if (mFile.isFolder()) {
String targetPath = targetParentPath + file.getFileName();
if (file.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR;
}
RemoteOperationResult result = new CopyFileRemoteOperation(mSrcPath, targetPath, false).execute(client);
RemoteOperationResult result = new CopyFileRemoteOperation(srcPath, targetPath, false).execute(client);
/// 3. local copy
if (result.isSuccess()) {
getStorageManager().copyLocalFile(mFile, targetPath);
getStorageManager().copyLocalFile(file, targetPath);
}
// TODO handle ResultCode.PARTIAL_COPY_DONE in client Activity, for the moment

View file

@ -28,15 +28,12 @@ import com.owncloud.android.operations.common.SyncOperation;
/**
* Operation mmoving an {@link OCFile} to a different folder.
* Operation moving an {@link OCFile} to a different folder.
*/
public class MoveFileOperation extends SyncOperation {
//private static final String TAG = MoveFileOperation.class.getSimpleName();
private String mSrcPath;
private String mTargetParentPath;
private OCFile mFile;
private String srcPath;
private String targetParentPath;
/**
* Constructor
@ -45,13 +42,11 @@ public class MoveFileOperation extends SyncOperation {
* @param targetParentPath Path to the folder where the file will be moved into.
*/
public MoveFileOperation(String srcPath, String targetParentPath) {
mSrcPath = srcPath;
mTargetParentPath = targetParentPath;
if (!mTargetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
mTargetParentPath += OCFile.PATH_SEPARATOR;
this.srcPath = srcPath;
this.targetParentPath = targetParentPath;
if (!this.targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
this.targetParentPath += OCFile.PATH_SEPARATOR;
}
mFile = null;
}
/**
@ -62,29 +57,27 @@ public class MoveFileOperation extends SyncOperation {
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
/// 1. check move validity
if (mTargetParentPath.startsWith(mSrcPath)) {
if (targetParentPath.startsWith(srcPath)) {
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
}
mFile = getStorageManager().getFileByPath(mSrcPath);
if (mFile == null) {
OCFile file = getStorageManager().getFileByPath(srcPath);
if (file == null) {
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
}
/// 2. remote move
String targetPath = mTargetParentPath + mFile.getFileName();
if (mFile.isFolder()) {
String targetPath = targetParentPath + file.getFileName();
if (file.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR;
}
RemoteOperationResult result = new MoveFileRemoteOperation(mSrcPath, targetPath, false).execute(client);
RemoteOperationResult result = new MoveFileRemoteOperation(srcPath, targetPath, false).execute(client);
/// 3. local move
if (result.isSuccess()) {
getStorageManager().moveLocalFile(mFile, targetPath, mTargetParentPath);
getStorageManager().moveLocalFile(file, targetPath, targetParentPath);
}
// TODO handle ResultCode.PARTIAL_MOVE_DONE in client Activity, for the moment
return result;
}
}

View file

@ -75,15 +75,15 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
private static final int RESULTS_PER_PAGE = 50;
private static final int REQUESTED_PAGE = 1;
public static String AUTHORITY;
static String AUTHORITY;
public static String ACTION_SHARE_WITH;
public static final String CONTENT = "content";
public static String DATA_USER;
public static String DATA_GROUP;
public static String DATA_ROOM;
public static String DATA_REMOTE;
static String DATA_USER;
static String DATA_GROUP;
static String DATA_ROOM;
static String DATA_REMOTE;
private UriMatcher mUriMatcher;

View file

@ -1,155 +0,0 @@
/**
* ownCloud Android client application
*
* @author Lorensius. W. T
* Copyright (C) 2011 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.PopupWindow;
/**
* Represents a custom PopupWindows
*/
public class CustomPopup {
protected final View mAnchor;
protected final PopupWindow mWindow;
private View root;
private Drawable background;
protected final WindowManager mWManager;
public CustomPopup(View anchor) {
mAnchor = anchor;
mWindow = new PopupWindow(anchor.getContext());
mWindow.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
CustomPopup.this.dismiss();
return true;
}
return false;
}
});
mWManager = (WindowManager) anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
onCreate();
}
public void onCreate() {
// not used at the moment
}
public void onShow() {
// not used at the moment
}
public void preShow() {
if (root == null) {
throw new IllegalStateException(
"setContentView called with a view to display");
}
onShow();
if (background == null) {
mWindow.setBackgroundDrawable(new BitmapDrawable());
} else {
mWindow.setBackgroundDrawable(background);
}
mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setOutsideTouchable(true);
mWindow.setContentView(root);
}
public void setBackgroundDrawable(Drawable background) {
this.background = background;
}
public void setContentView(View root) {
this.root = root;
mWindow.setContentView(root);
}
public void setContentView(int layoutResId) {
LayoutInflater inflater = (LayoutInflater) mAnchor.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setContentView(inflater.inflate(layoutResId, null));
}
public void showDropDown() {
showDropDown(0, 0);
}
public void showDropDown(int x, int y) {
preShow();
mWindow.setAnimationStyle(android.R.style.Animation_Dialog);
mWindow.showAsDropDown(mAnchor, x, y);
}
public void showLikeQuickAction() {
showLikeQuickAction(0, 0);
}
public void showLikeQuickAction(int x, int y) {
preShow();
mWindow.setAnimationStyle(android.R.style.Animation_Dialog);
int[] location = new int[2];
mAnchor.getLocationOnScreen(location);
Rect anchorRect = new Rect(location[0], location[1], location[0]
+ mAnchor.getWidth(), location[1] + mAnchor.getHeight());
root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootW = root.getWidth();
int rootH = root.getHeight();
int screenW = mWManager.getDefaultDisplay().getWidth();
int xpos = ((screenW - rootW) / 2) + x;
int ypos = anchorRect.top - rootH + y;
if (rootH > anchorRect.top) {
ypos = anchorRect.bottom + y;
}
mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos);
}
public void dismiss() {
mWindow.dismiss();
}
}

View file

@ -324,6 +324,11 @@ public class StorageMigration {
this.mResId = resId;
}
MigrationException(int resId, Throwable t) {
super(t);
this.mResId = resId;
}
private int getResId() { return mResId; }
}
@ -433,7 +438,7 @@ public class StorageMigration {
manager.migrateStoredFiles(mStorageSource, mStorageTarget);
} catch (Exception e) {
Log_OC.e(TAG,e.getMessage(),e);
throw new MigrationException(R.string.file_migration_failed_while_updating_index);
throw new MigrationException(R.string.file_migration_failed_while_updating_index, e);
}
}

View file

@ -93,8 +93,8 @@ import static com.owncloud.android.datamodel.SyncedFolderDisplayItem.UNPERSISTED
public class SyncedFoldersActivity extends FileActivity implements SyncedFolderAdapter.ClickListener,
SyncedFolderPreferencesDialogFragment.OnSyncedFolderPreferenceListener {
public static final String[] PRIORITIZED_FOLDERS = new String[]{"Camera", "Screenshots"};
public static final List<String> SPECIAL_MANUFACTURER = Arrays.asList("Samsung", "Huawei", "Xiaomi");
private static final String[] PRIORITIZED_FOLDERS = new String[]{"Camera", "Screenshots"};
private static final List<String> SPECIAL_MANUFACTURER = Arrays.asList("Samsung", "Huawei", "Xiaomi");
public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
private static final String TAG = SyncedFoldersActivity.class.getSimpleName();

View file

@ -584,17 +584,17 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
// early exit
if (objects.size() > 0 && mStorageManager != null) {
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
if (searchType == ExtendedListFragment.SearchType.SHARED_FILTER) {
parseShares(objects);
} else {
parseVirtuals(objects, searchType);
}
}
if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&
!searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) &&
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH) &&
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER)) {
if (searchType != ExtendedListFragment.SearchType.PHOTO_SEARCH &&
searchType != ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER &&
searchType != ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH &&
searchType != ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER) {
FileSortOrder sortOrder = PreferenceManager.getSortOrderByFolder(mContext, folder);
mFiles = sortOrder.sortCloudFiles(mFiles);
} else {

View file

@ -305,7 +305,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
// click on item
if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
if (UploadResult.CREDENTIAL_ERROR.equals(item.getLastResult())) {
if (UploadResult.CREDENTIAL_ERROR == item.getLastResult()) {
itemViewHolder.itemLayout.setOnClickListener(v ->
parentActivity.getFileOperationsHelper().checkCurrentCredentials(
item.getAccount(parentActivity)));
@ -714,8 +714,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
if (upload2 == null) {
return 1;
}
if (UploadStatus.UPLOAD_IN_PROGRESS.equals(upload1.getFixedUploadStatus())) {
if (!UploadStatus.UPLOAD_IN_PROGRESS.equals(upload2.getFixedUploadStatus())) {
if (UploadStatus.UPLOAD_IN_PROGRESS == upload1.getFixedUploadStatus()) {
if (UploadStatus.UPLOAD_IN_PROGRESS != upload2.getFixedUploadStatus()) {
return -1;
}
// both are in progress
@ -724,7 +724,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
} else if (upload2.isFixedUploadingNow()) {
return 1;
}
} else if (upload2.getFixedUploadStatus().equals(UploadStatus.UPLOAD_IN_PROGRESS)) {
} else if (upload2.getFixedUploadStatus() == UploadStatus.UPLOAD_IN_PROGRESS) {
return 1;
}
if (upload1.getFixedUploadEndTimeStamp() == 0 || upload2.getFixedUploadEndTimeStamp() == 0) {

View file

@ -92,8 +92,8 @@ public class SamlWebViewDialog extends DialogFragment {
mWebViewClient = new SsoWebViewClient(activity, mHandler, mSsoWebViewClientListener);
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement " +
SsoWebViewClientListener.class.getSimpleName());
throw new IllegalArgumentException(activity.toString() + " must implement " +
SsoWebViewClientListener.class.getSimpleName(), e);
}
}

View file

@ -104,8 +104,8 @@ public class FileFragment extends Fragment {
mContainerActivity = (ContainerActivity) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement " +
ContainerActivity.class.getSimpleName());
throw new IllegalArgumentException(activity.toString() + " must implement " +
ContainerActivity.class.getSimpleName(), e);
}
}

View file

@ -72,8 +72,8 @@ public class LocalFileListFragment extends ExtendedListFragment implements Local
try {
mContainerActivity = (ContainerActivity) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement " +
LocalFileListFragment.ContainerActivity.class.getSimpleName());
throw new IllegalArgumentException(activity.toString() + " must implement " +
LocalFileListFragment.ContainerActivity.class.getSimpleName(), e);
}
}

View file

@ -240,15 +240,15 @@ public class OCFileListFragment extends ExtendedListFragment implements
mContainerActivity = (FileFragment.ContainerActivity) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement " +
FileFragment.ContainerActivity.class.getSimpleName());
throw new IllegalArgumentException(context.toString() + " must implement " +
FileFragment.ContainerActivity.class.getSimpleName(), e);
}
try {
setOnRefreshListener((OnEnforceableRefreshListener) context);
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement " +
SwipeRefreshLayout.OnRefreshListener.class.getSimpleName());
throw new IllegalArgumentException(context.toString() + " must implement " +
SwipeRefreshLayout.OnRefreshListener.class.getSimpleName(), e);
}
}
@ -703,14 +703,14 @@ public class OCFileListFragment extends ExtendedListFragment implements
MenuItem menuItemOrig;
if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_SORT)) {
if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_SORT) {
if (menu.findItem(R.id.action_sort) == null) {
menuItemOrig = mOriginalMenuItems.get(1);
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle());
}
} else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_GRID_AND_SORT)) {
} else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT) {
if (menu.findItem(R.id.action_switch_view) == null) {
menuItemOrig = mOriginalMenuItems.get(0);
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
@ -722,9 +722,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle());
}
} else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_SEARCH)) {
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SEARCH) {
menu.removeItem(R.id.action_search);
} else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH)) {
} else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH) {
if (menu.findItem(R.id.action_switch_view) == null) {
menuItemOrig = mOriginalMenuItems.get(0);
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
@ -742,23 +742,22 @@ public class OCFileListFragment extends ExtendedListFragment implements
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle());
}
} else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_SORT)) {
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SORT) {
menu.removeItem(R.id.action_sort);
menu.removeItem(R.id.action_search);
} else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_GRID_AND_SORT)) {
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_GRID_AND_SORT) {
menu.removeItem(R.id.action_sort);
menu.removeItem(R.id.action_switch_view);
menu.removeItem(R.id.action_search);
}
}
/**
* Call this, when the user presses the up button.
* <p>
*
* Tries to move up the current folder one level. If the parent folder was removed from the
* database, it continues browsing up until finding an existing folders.
* <p/>
*
* return Count of folder levels browsed up.
*/
public int onBrowseUp() {
@ -1345,7 +1344,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
}
}
if (currentSearchType != null && !currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {
if (SearchType.FILE_SEARCH != currentSearchType && getActivity() != null) {
getActivity().invalidateOptionsMenu();
}
}
@ -1353,21 +1352,21 @@ public class OCFileListFragment extends ExtendedListFragment implements
private void setEmptyView(SearchEvent event) {
if (event != null) {
if (SearchRemoteOperation.SearchType.FILE_SEARCH.equals(event.getSearchType())) {
if (SearchRemoteOperation.SearchType.FILE_SEARCH == event.getSearchType()) {
setEmptyListMessage(SearchType.FILE_SEARCH);
} else if (event.getSearchType().equals(SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH)) {
} else if (event.getSearchType() == SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH) {
if ("image/%".equals(event.getSearchQuery())) {
setEmptyListMessage(SearchType.PHOTO_SEARCH);
} else if ("video/%".equals(event.getSearchQuery())) {
setEmptyListMessage(SearchType.VIDEO_SEARCH);
}
} else if (SearchRemoteOperation.SearchType.FAVORITE_SEARCH.equals(event.getSearchType())) {
} else if (SearchRemoteOperation.SearchType.FAVORITE_SEARCH == event.getSearchType()) {
setEmptyListMessage(SearchType.FAVORITE_SEARCH);
} else if (SearchRemoteOperation.SearchType.RECENTLY_ADDED_SEARCH.equals(event.getSearchType())) {
} else if (SearchRemoteOperation.SearchType.RECENTLY_ADDED_SEARCH == event.getSearchType()) {
setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH);
} else if (SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH.equals(event.getSearchType())) {
} else if (SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH == event.getSearchType()) {
setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
} else if (SearchRemoteOperation.SearchType.SHARED_SEARCH.equals(event.getSearchType())) {
} else if (SearchRemoteOperation.SearchType.SHARED_SEARCH == event.getSearchType()) {
setEmptyListMessage(SearchType.SHARED_FILTER);
}
}
@ -1438,9 +1437,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
setFabVisible(false);
if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR)) {
if (event.getUnsetType() == SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR) {
unsetAllMenuItems(false);
} else if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_DRAWER)) {
} else if (event.getUnsetType() == SearchEvent.UnsetType.UNSET_DRAWER) {
unsetAllMenuItems(true);
}
@ -1471,7 +1470,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
}
};
if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) {
if (currentSearchType == SearchType.PHOTO_SEARCH) {
new Handler(Looper.getMainLooper()).post(this::switchToGridView);
} else {
new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
@ -1480,7 +1479,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
final RemoteOperation remoteOperation;
if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
if (currentSearchType != SearchType.SHARED_FILTER) {
boolean searchOnlyFolders = false;
if (getArguments() != null && getArguments().getBoolean(ARG_SEARCH_ONLY_FOLDER, false)) {
searchOnlyFolders = true;

View file

@ -195,8 +195,8 @@ public class SearchShareesFragment extends Fragment implements ShareUserListAdap
try {
mListener = (ShareFragmentListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
throw new IllegalArgumentException(activity.toString()
+ " must implement OnFragmentInteractionListener", e);
}
}

View file

@ -576,7 +576,8 @@ public class ShareFileFragment extends Fragment implements ShareUserListAdapter.
try {
mListener = (ShareFragmentListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnShareFragmentInteractionListener");
throw new IllegalArgumentException(
activity.toString() + " must implement OnShareFragmentInteractionListener", e);
}
}

View file

@ -154,10 +154,9 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
} else if (file.isDown()) {
fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), false);
} else {
if (mDownloadErrors.contains(i)) {
if (mDownloadErrors.remove(i)) {
fragment = FileDownloadFragment.newInstance(file, mAccount, true);
((FileDownloadFragment) fragment).setError(true);
mDownloadErrors.remove(i);
} else {
if (file.isEncrypted()) {
fragment = FileDownloadFragment.newInstance(file, mAccount, mObsoletePositions.contains(i));
@ -212,8 +211,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
@Override
public int getItemPosition(@NonNull Object object) {
if (mObsoleteFragments.contains(object)) {
mObsoleteFragments.remove(object);
if (mObsoleteFragments.remove(object)) {
return POSITION_NONE;
}
return super.getItemPosition(object);

View file

@ -45,6 +45,13 @@ import androidx.exifinterface.media.ExifInterface;
public final class BitmapUtils {
public static final String TAG = BitmapUtils.class.getSimpleName();
private static final int INDEX_RED = 0;
private static final int INDEX_GREEN = 1;
private static final int INDEX_BLUE = 2;
private static final int INDEX_HUE = 0;
private static final int INDEX_SATURATION = 1;
private static final int INDEX_LUMINATION = 2;
private BitmapUtils() {
// utility class -> private constructor
}
@ -300,22 +307,22 @@ public final class BitmapUtils {
}
// Reduce values bigger than rgb requirements
rgb[0] = rgb[0] % 255;
rgb[1] = rgb[1] % 255;
rgb[2] = rgb[2] % 255;
rgb[INDEX_RED] = rgb[INDEX_RED] % 255;
rgb[INDEX_GREEN] = rgb[INDEX_GREEN] % 255;
rgb[INDEX_BLUE] = rgb[INDEX_BLUE] % 255;
double[] hsl = rgbToHsl(rgb[0], rgb[1], rgb[2]);
double[] hsl = rgbToHsl(rgb[INDEX_RED], rgb[INDEX_GREEN], rgb[INDEX_BLUE]);
// Classic formula to check the brightness for our eye
// If too bright, lower the sat
double bright = Math.sqrt(0.299 * Math.pow(rgb[0], 2) + 0.587 * Math.pow(rgb[1], 2) + 0.114
* Math.pow(rgb[2], 2));
double bright = Math.sqrt(0.299 * Math.pow(rgb[INDEX_RED], 2) + 0.587 * Math.pow(rgb[INDEX_GREEN], 2) + 0.114
* Math.pow(rgb[INDEX_BLUE], 2));
if (bright >= 200) {
sat = 60;
}
return new int[]{(int) (hsl[0] * 360), sat, lum};
return new int[]{(int) (hsl[INDEX_HUE] * 360), sat, lum};
}
private static double[] rgbToHsl(double rUntrimmed, double gUntrimmed, double bUntrimmed) {
@ -346,9 +353,9 @@ public final class BitmapUtils {
}
double[] hsl = new double[]{0.0, 0.0, 0.0};
hsl[0] = h;
hsl[1] = s;
hsl[2] = l;
hsl[INDEX_HUE] = h;
hsl[INDEX_SATURATION] = s;
hsl[INDEX_LUMINATION] = l;
return hsl;
}