Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings for OCFileListFragment #12112

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package com.owncloud.android.ui.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -200,7 +201,6 @@ public class OCFileListFragment extends ExtendedListFragment implements

private static final String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER";
private static final String DIALOG_CREATE_DOCUMENT = "DIALOG_CREATE_DOCUMENT";
private static final String DIALOG_BOTTOM_SHEET = "DIALOG_BOTTOM_SHEET";

private static final int SINGLE_SELECTION = 1;
private static final int NOT_ENOUGH_SPACE_FRAG_REQUEST_CODE = 2;
Expand Down Expand Up @@ -292,20 +292,23 @@ public void onResume() {
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);

Log_OC.i(TAG, "onAttach");

try {
mContainerActivity = (FileFragment.ContainerActivity) context;
setTitle();

} catch (ClassCastException e) {
throw new IllegalArgumentException(context.toString() + " must implement " +
throw new IllegalArgumentException(context + " must implement " +
FileFragment.ContainerActivity.class.getSimpleName(), e);
}

try {
setOnRefreshListener((OnEnforceableRefreshListener) context);

} catch (ClassCastException e) {
throw new IllegalArgumentException(context.toString() + " must implement " +
throw new IllegalArgumentException(context + " must implement " +
OnEnforceableRefreshListener.class.getSimpleName(), e);
}
}
Expand All @@ -316,6 +319,7 @@ public void onAttach(@NonNull Context context) {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.i(TAG, "onCreateView() start");

View v = super.onCreateView(inflater, container, savedInstanceState);


Expand Down Expand Up @@ -343,6 +347,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}

Log_OC.i(TAG, "onCreateView() end");

return v;
}

Expand All @@ -354,12 +359,14 @@ public void onDetach() {
if (remoteOperationAsyncTask != null) {
remoteOperationAsyncTask.cancel(true);
}

super.onDetach();
}

@Override
public void onPause() {
super.onPause();

if (mAdapter != null) {
mAdapter.cancelAllPendingTasks();
}
Expand All @@ -375,6 +382,7 @@ public void onPause() {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

Log_OC.i(TAG, "onActivityCreated() start");

if (savedInstanceState != null) {
Expand Down Expand Up @@ -405,6 +413,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
searchEvent = BundleExtensionsKt.getParcelableArgument(getArguments(), SEARCH_EVENT, SearchEvent.class);
}
}

prepareCurrentSearch(searchEvent);
setEmptyView(searchEvent);

Expand All @@ -427,8 +436,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
setTitle();

FragmentActivity fragmentActivity;
if ((fragmentActivity = getActivity()) != null && fragmentActivity instanceof FileDisplayActivity) {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) fragmentActivity;
if (getActivity() instanceof FileDisplayActivity fileDisplayActivity) {
fileDisplayActivity.updateActionBarTitleAndHomeButton(fileDisplayActivity.getCurrentDir());
}
listDirectory(MainApp.isOnlyOnDevice(), false);
Expand Down Expand Up @@ -456,27 +464,12 @@ protected void setAdapter(Bundle args) {

protected void prepareCurrentSearch(SearchEvent event) {
if (isSearchEventSet(event)) {

switch (event.getSearchType()) {
case FILE_SEARCH:
currentSearchType = FILE_SEARCH;
break;

case FAVORITE_SEARCH:
currentSearchType = FAVORITE_SEARCH;
break;

case RECENTLY_MODIFIED_SEARCH:
currentSearchType = RECENTLY_MODIFIED_SEARCH;
break;

case SHARED_FILTER:
currentSearchType = SHARED_FILTER;
break;

default:
// do nothing
break;
case FILE_SEARCH -> currentSearchType = FILE_SEARCH;
case FAVORITE_SEARCH -> currentSearchType = FAVORITE_SEARCH;
case RECENTLY_MODIFIED_SEARCH -> currentSearchType = RECENTLY_MODIFIED_SEARCH;
case SHARED_FILTER -> currentSearchType = SHARED_FILTER;
default -> {}
}

prepareActionBarItems(event);
Expand Down Expand Up @@ -514,7 +507,7 @@ public void registerFabListener() {
@Override
public void createFolder() {
CreateFolderDialogFragment.newInstance(mFile)
.show(getActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
.show(requireActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
}

@Override
Expand All @@ -523,10 +516,9 @@ public void uploadFromApp() {
action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

getActivity().startActivityForResult(
requireActivity().startActivityForResult(
Intent.createChooser(action, getString(R.string.upload_chooser_title)),
FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS
);
FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS);
}

@Override
Expand Down Expand Up @@ -556,8 +548,7 @@ public void scanDocUpload() {
", currentFile=" + currentFile);
Toast.makeText(getContext(),
getString(R.string.error_starting_doc_scan),
Toast.LENGTH_SHORT)
.show();
Toast.LENGTH_SHORT).show();
}
}

Expand Down Expand Up @@ -623,7 +614,6 @@ public void openActionsMenu(final int filesCount, final Set<OCFile> checkedFiles
onFileActionChosen(id, checkedFiles);
})
.show(childFragmentManager, "actions");
;
});
}

Expand Down Expand Up @@ -746,16 +736,17 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mIsActionModeNew = true;

// fake menu to be able to use bottom sheet instead
MenuInflater inflater = getActivity().getMenuInflater();
MenuInflater inflater = requireActivity().getMenuInflater();
inflater.inflate(R.menu.custom_menu_placeholder, menu);
final MenuItem item = menu.findItem(R.id.custom_menu_placeholder_item);
item.setIcon(viewThemeUtils.platform.colorDrawable(item.getIcon(), ContextCompat.getColor(requireContext(), R.color.white)));
int colorId = ContextCompat.getColor(requireContext(), R.color.white);
item.setIcon(viewThemeUtils.platform.colorDrawable(item.getIcon(), colorId));
mode.invalidate();

//set actionMode color
viewThemeUtils.platform.colorStatusBar(
getActivity(),
ContextCompat.getColor(getContext(), R.color.action_mode_background));
requireActivity(),
ContextCompat.getColor(requireContext(), R.color.action_mode_background));

// hide FAB in multi selection mode
setFabVisible(false);
Expand Down Expand Up @@ -868,24 +859,19 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {

private void updateSortAndGridMenuItems() {
switch (menuItemAddRemoveValue) {
case ADD_GRID_AND_SORT_WITH_SEARCH:
case ADD_GRID_AND_SORT_WITH_SEARCH -> {
mSwitchGridViewButton.setVisibility(View.VISIBLE);
mSortButton.setVisibility(View.VISIBLE);
break;

case REMOVE_SORT:
mSortButton.setVisibility(View.GONE);
break;

case REMOVE_GRID_AND_SORT:
}
case REMOVE_SORT -> mSortButton.setVisibility(View.GONE);
case REMOVE_GRID_AND_SORT -> {
mSortButton.setVisibility(View.GONE);
mSwitchGridViewButton.setVisibility(View.GONE);
break;

case DO_NOTHING:
default:
}
case DO_NOTHING -> {
Log_OC.v(TAG, "Kept the options menu default structure");
break;
}
default -> Log_OC.v(TAG, "Kept the options menu default structure");
}
}

Expand Down Expand Up @@ -1023,8 +1009,7 @@ public void onItemClicked(OCFile file) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());

FragmentManager fragmentManager = getParentFragmentManager();
if (fragmentManager != null &&
fragmentManager.findFragmentByTag(SETUP_ENCRYPTION_DIALOG_TAG) == null) {
if (fragmentManager.findFragmentByTag(SETUP_ENCRYPTION_DIALOG_TAG) == null) {
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user,
position);
dialog.setTargetFragment(this, SETUP_ENCRYPTION_REQUEST_CODE);
Expand All @@ -1048,18 +1033,11 @@ public void onItemClicked(OCFile file) {
if (PreviewImageFragment.canBePreviewed(file)) {
// preview image - it handles the download, if needed
if (searchFragment) {
VirtualFolderType type;
switch (currentSearchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
break;
default:
type = VirtualFolderType.NONE;
break;
}
VirtualFolderType type = switch (currentSearchType) {
case FAVORITE_SEARCH -> VirtualFolderType.FAVORITE;
case GALLERY_SEARCH -> VirtualFolderType.GALLERY;
default -> VirtualFolderType.NONE;
};
((FileDisplayActivity) mContainerActivity).startImagePreview(file, type, !file.isDown());
} else {
((FileDisplayActivity) mContainerActivity).startImagePreview(file, !file.isDown());
Expand Down Expand Up @@ -1387,12 +1365,7 @@ private void updateLayout() {
setGridSwitchButton();
}

if (mHideFab) {
setFabVisible(false);
} else {
setFabVisible(true);
// registerFabListener();
}
setFabVisible(!mHideFab);

// FAB
setFabEnabled(mFile != null && mFile.canWrite());
Expand Down Expand Up @@ -1444,6 +1417,7 @@ public void switchToGridView() {
}
}

@SuppressLint("NotifyDataSetChanged")
public void switchLayoutManager(boolean grid) {
int position = 0;

Expand Down Expand Up @@ -1491,21 +1465,11 @@ protected void setTitle() {

if (getActivity() instanceof FileDisplayActivity && currentSearchType != null) {
switch (currentSearchType) {
case FAVORITE_SEARCH:
setTitle(R.string.drawer_item_favorites);
break;
case GALLERY_SEARCH:
setTitle(R.string.drawer_item_gallery);
break;
case RECENTLY_MODIFIED_SEARCH:
setTitle(R.string.drawer_item_recently_modified);
break;
case SHARED_FILTER:
setTitle(R.string.drawer_item_shared);
break;
default:
setTitle(themeUtils.getDefaultDisplayNameForRootFolder(getContext()), false);
break;
case FAVORITE_SEARCH -> setTitle(R.string.drawer_item_favorites);
case GALLERY_SEARCH -> setTitle(R.string.drawer_item_gallery);
case RECENTLY_MODIFIED_SEARCH -> setTitle(R.string.drawer_item_recently_modified);
case SHARED_FILTER -> setTitle(R.string.drawer_item_shared);
default -> setTitle(themeUtils.getDefaultDisplayNameForRootFolder(getContext()), false);
}
}

Expand All @@ -1514,14 +1478,9 @@ protected void setTitle() {
protected void prepareActionBarItems(SearchEvent event) {
if (event != null) {
switch (event.getSearchType()) {
case FAVORITE_SEARCH:
case RECENTLY_MODIFIED_SEARCH:
case FAVORITE_SEARCH, RECENTLY_MODIFIED_SEARCH ->
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
break;

default:
// do nothing
break;
default -> {}
}
}

Expand All @@ -1533,25 +1492,11 @@ protected void prepareActionBarItems(SearchEvent event) {
protected void setEmptyView(SearchEvent event) {
if (event != null) {
switch (event.getSearchType()) {
case FILE_SEARCH:
setEmptyListMessage(SearchType.FILE_SEARCH);
break;

case FAVORITE_SEARCH:
setEmptyListMessage(SearchType.FAVORITE_SEARCH);
break;

case RECENTLY_MODIFIED_SEARCH:
setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
break;

case SHARED_FILTER:
setEmptyListMessage(SearchType.SHARED_FILTER);
break;

default:
setEmptyListMessage(SearchType.NO_SEARCH);
break;
case FILE_SEARCH -> setEmptyListMessage(SearchType.FILE_SEARCH);
case FAVORITE_SEARCH -> setEmptyListMessage(SearchType.FAVORITE_SEARCH);
case RECENTLY_MODIFIED_SEARCH -> setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
case SHARED_FILTER -> setEmptyListMessage(SearchType.SHARED_FILTER);
default -> setEmptyListMessage(SearchType.NO_SEARCH);
}
} else {
setEmptyListMessage(SearchType.NO_SEARCH);
Expand Down Expand Up @@ -1800,6 +1745,7 @@ private void encryptFolder(OCFile folder,
}
}

// Do not delete this function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Do not delete this function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE will always show as unused function better to keep that comment

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FileLockEvent event) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like mentioned in the other PR, I expect the event bus to make use of them, so this should actually be a false-positive, best to check with @tobiasKaminsky

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is still used.
You can check where FileLockEvent is being used:
Within FileOperationsHelper there is: EventBus.getDefault().post(new FileLockEvent(file.getRemotePath(), shouldBeLocked));

This is to send the event, and the other function receives it.

In long term I would like to get rid of it…

final User user = accountManager.getUser();
Expand Down Expand Up @@ -1898,10 +1844,12 @@ public boolean isSearchFragment() {
public void selectAllFiles(boolean select) {
OCFileListAdapter ocFileListAdapter = (OCFileListAdapter) getRecyclerView().getAdapter();

if (select) {
ocFileListAdapter.addAllFilesToCheckedFiles();
} else {
ocFileListAdapter.clearCheckedItems();
if (ocFileListAdapter != null) {
if (select) {
ocFileListAdapter.addAllFilesToCheckedFiles();
} else {
ocFileListAdapter.clearCheckedItems();
}
}

for (int i = 0; i < mAdapter.getItemCount(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 3 errors and 69 warnings</span>
<span class="mdl-layout-title">Lint Report: 3 errors and 68 warnings</span>