Skip to content

Commit

Permalink
Changes due to CR
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Nov 3, 2020
1 parent 1699760 commit 77751da
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 34 deletions.
26 changes: 11 additions & 15 deletions src/main/java/com/owncloud/android/files/FileMenuFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,20 @@ public FileMenuFilter(OCFile file,
}

/**
* Filters out the file actions available in the passed {@link Menu} taken into account
* the state of the {@link OCFile} held by the filter.
* Filters out the file actions available in the passed {@link Menu} taken into account the state of the {@link
* OCFile} held by the filter.
*
* @param menu Options or context menu to filter.
* @param inSingleFileFragment True if this is not listing, but single file fragment, like preview or details.
* @param isMediaSupported True is media playback is supported for this user
* @param menu Options or context menu to filter.
* @param inSingleFileFragment True if this is not listing, but single file fragment, like preview or details.
*/
public void filter(Menu menu, boolean inSingleFileFragment, boolean isMediaSupported) {
public void filter(Menu menu, boolean inSingleFileFragment) {
if (files == null || files.isEmpty()) {
hideAll(menu);
} else {
List<Integer> toShow = new ArrayList<>();
List<Integer> toHide = new ArrayList<>();

filter(toShow, toHide, inSingleFileFragment, isMediaSupported);
filter(toShow, toHide, inSingleFileFragment);

for (int i : toShow) {
showMenuItem(menu.findItem(i));
Expand Down Expand Up @@ -179,16 +178,13 @@ public static void hideMenuItems(MenuItem... items) {

/**
* Decides what actions must be shown and hidden implementing the different rule sets.
*
* @param toShow List to save the options that must be shown in the menu.
* @param toShow List to save the options that must be shown in the menu.
* @param toHide List to save the options that must be shown in the menu.
* @param inSingleFileFragment True if this is not listing, but single file fragment, like preview or details.
* @param isMediaSupported True is media playback is supported for this user
*/
private void filter(List<Integer> toShow,
List<Integer> toHide,
boolean inSingleFileFragment,
boolean isMediaSupported) {
boolean inSingleFileFragment) {
boolean synchronizing = anyFileSynchronizing();
OCCapability capability = componentsGetter.getStorageManager().getCapability(user.getAccountName());
boolean endToEndEncryptionEnabled = capability.getEndToEndEncryption().isTrue();
Expand All @@ -211,7 +207,7 @@ private void filter(List<Integer> toShow,
filterEncrypt(toShow, toHide, endToEndEncryptionEnabled);
filterUnsetEncrypted(toShow, toHide, endToEndEncryptionEnabled);
filterSetPictureAs(toShow, toHide);
filterStream(toShow, toHide, isMediaSupported);
filterStream(toShow, toHide);
}

private void filterShareFile(List<Integer> toShow, List<Integer> toHide, OCCapability capability) {
Expand Down Expand Up @@ -429,8 +425,8 @@ private void filterDownload(List<Integer> toShow, List<Integer> toHide, boolean
}
}

private void filterStream(List<Integer> toShow, List<Integer> toHide, boolean isMediaSupported) {
if (files.isEmpty() || !isSingleFile() || !isSingleMedia() || !isMediaSupported) {
private void filterStream(List<Integer> toShow, List<Integer> toHide) {
if (files.isEmpty() || !isSingleFile() || !isSingleMedia()) {
toHide.add(R.id.action_stream_media);
} else {
toShow.add(R.id.action_stream_media);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,7 @@ private void prepareOptionsMenu(Menu menu) {
currentUser
);

mf.filter(menu,
true,
true);
mf.filter(menu, true);
}

if (getFile().isFolder()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ public void prepareUserOptionsMenu(Menu menu, OCShare share) {
MenuItem allowDeletingItem = menu.findItem(R.id.allow_deleting);
MenuItem expirationDateItem = menu.findItem(R.id.action_expiration_date);
MenuItem reshareItem = menu.findItem(R.id.allow_resharing);
MenuItem sendNoteItem = menu.findItem(R.id.action_share_send_note);

allowEditingItem.setChecked(canEdit(share));

Expand All @@ -350,8 +349,6 @@ public void prepareUserOptionsMenu(Menu menu, OCShare share) {
SharingMenuHelper.setupExpirationDateMenuItem(menu.findItem(R.id.action_expiration_date),
share.getExpirationDate(),
getResources());

sendNoteItem.setVisible(true);
}

public void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink) {
Expand Down Expand Up @@ -407,8 +404,6 @@ public void prepareLinkOptionsMenu(Menu menu, OCShare publicShare) {
SharingMenuHelper.setupExpirationDateMenuItem(menu.findItem(R.id.action_share_expiration_date),
publicShare.getExpirationDate(),
res);

menu.findItem(R.id.action_share_send_note).setVisible(true);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,13 @@ public void showActivityDetailView(OCFile file) {
public void onOverflowIconClicked(OCFile file, View view) {
PopupMenu popup = new PopupMenu(getActivity(), view);
popup.inflate(R.menu.item_file);
User currentUser = ((FileActivity) getActivity()).getUser().orElseThrow(IllegalStateException::new);
FileMenuFilter mf = new FileMenuFilter(mAdapter.getFiles().size(),
Collections.singleton(file),
mContainerActivity, getActivity(),
true,
deviceInfo,
accountManager.getUser());
mf.filter(popup.getMenu(),
true,
true);
mf.filter(popup.getMenu(), true);
popup.setOnMenuItemClickListener(item -> {
Set<OCFile> checkedFiles = new HashSet<>();
checkedFiles.add(file);
Expand Down Expand Up @@ -682,7 +679,6 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Set<OCFile> checkedFiles = mAdapter.getCheckedItems();
String title = getResources().getQuantityString(R.plurals.items_selected_count, checkedCount, checkedCount);
mode.setTitle(title);
User currentUser = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(
mAdapter.getFiles().size(),
checkedFiles,
Expand All @@ -693,7 +689,7 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
accountManager.getUser()
);

mf.filter(menu, false, true);
mf.filter(menu, false);

// Determine if we need to finish the action mode because there are no items selected
if (checkedCount == 0 && !mIsActionModeNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {
currentUser
);

mf.filter(menu,
true,
true);
mf.filter(menu, true);
}

// additional restriction for this fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void onPrepareOptionsMenu(Menu menu) {
currentUser
);

mf.filter(menu, true, true);
mf.filter(menu, true);
}

// additional restriction for this fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {
deviceInfo,
user
);
mf.filter(menu, true, true);
mf.filter(menu, true);
}

// additional restriction for this fragment
Expand Down

0 comments on commit 77751da

Please sign in to comment.