Skip to content

Commit

Permalink
Merge pull request #1613 from rhari991/file-list-actions
Browse files Browse the repository at this point in the history
Add options for operations on single files
  • Loading branch information
AndyScherzinger authored Oct 18, 2017
2 parents af57cbd + a2d182c commit 620f9db
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 70 deletions.
18 changes: 12 additions & 6 deletions src/main/java/com/owncloud/android/files/FileMenuFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class FileMenuFilter {
private ComponentsGetter mComponentsGetter;
private Account mAccount;
private Context mContext;
private boolean mOverflowMenu;

/**
* Constructor
Expand All @@ -61,14 +62,16 @@ public class FileMenuFilter {
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param overflowMenu true if the overflow menu items are being filtered
*/
public FileMenuFilter(int numberOfAllFiles, Collection<OCFile> targetFiles, Account account,
ComponentsGetter cg, Context context) {
ComponentsGetter cg, Context context, boolean overflowMenu) {
mNumberOfAllFiles = numberOfAllFiles;
mFiles = targetFiles;
mAccount = account;
mComponentsGetter = cg;
mContext = context;
mOverflowMenu = overflowMenu;
}

/**
Expand All @@ -78,9 +81,11 @@ public FileMenuFilter(int numberOfAllFiles, Collection<OCFile> targetFiles, Acco
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param overflowMenu true if the overflow menu items are being filtered
*/
public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context) {
this(1, Collections.singletonList(targetFile), account, cg, context);
public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context,
boolean overflowMenu) {
this(1, Collections.singletonList(targetFile), account, cg, context, overflowMenu);
}

/**
Expand Down Expand Up @@ -178,7 +183,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean inSingle
// SELECT ALL
if (!inSingleFileFragment) {
// Show only if at least one item isn't selected.
if (mFiles.size() >= mNumberOfAllFiles) {
if (mFiles.size() >= mNumberOfAllFiles || mOverflowMenu) {
toHide.add(R.id.action_select_all_action_menu);
} else {
toShow.add(R.id.action_select_all_action_menu);
Expand All @@ -191,7 +196,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean inSingle
// DESELECT ALL
if (!inSingleFileFragment) {
// Show only if at least one item is selected.
if (mFiles.isEmpty()) {
if (mFiles.isEmpty() || mOverflowMenu) {
toHide.add(R.id.action_deselect_all_action_menu);
} else {
toShow.add(R.id.action_deselect_all_action_menu);
Expand Down Expand Up @@ -235,7 +240,8 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean inSingle
(capability.getFilesSharingApiEnabled().isTrue() ||
capability.getFilesSharingApiEnabled().isUnknown()
);
if ((!shareViaLinkAllowed && !shareWithUsersAllowed) || !isSingleSelection() || !shareApiEnabled) {
if ((!shareViaLinkAllowed && !shareWithUsersAllowed) ||
!isSingleSelection() || !shareApiEnabled || mOverflowMenu) {
toHide.add(R.id.action_share_file);
} else {
toShow.add(R.id.action_share_file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.accounts.Account;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
Expand Down Expand Up @@ -62,8 +61,6 @@
import com.owncloud.android.operations.RemoteOperationFailedException;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
import com.owncloud.android.utils.DisplayUtils;
Expand Down Expand Up @@ -234,10 +231,6 @@ public View getView(int position, View convertView, ViewGroup parent) {

if (file != null) {
ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
if (file.isSharedWithSharee() || file.isSharedWithMe()) {
sharedIconV.setImageResource(R.drawable.shared_via_users);
}

fileIcon.setTag(file.getFileId());
TextView fileName;
Expand All @@ -258,21 +251,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
fileSizeV.setVisibility(View.VISIBLE);
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));

// Shared icon clickable
if (file.isSharedViaLink() || file.isSharedWithSharee()) {
final OCFile temp = file;
sharedIconV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(mContext, ShareActivity.class);
intent.putExtra(FileActivity.EXTRA_FILE, temp);
intent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
mContext.startActivity(intent);
}
});
}


case GRID_ITEM:
// filename
fileName = (TextView) view.findViewById(R.id.Filename);
Expand All @@ -284,16 +262,6 @@ public void onClick(View view) {
}

case GRID_IMAGE:
// sharedIcon
if (file.isSharedViaLink()) {
sharedIconV.setVisibility(View.VISIBLE);
sharedIconV.bringToFront();
} else if (file.isSharedWithSharee() || file.isSharedWithMe()) {
sharedIconV.setVisibility(View.VISIBLE);
sharedIconV.bringToFront();
} else {
sharedIconV.setVisibility(View.GONE);
}

// local state
ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator);
Expand Down Expand Up @@ -340,7 +308,6 @@ public void onClick(View view) {
}

ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
checkBoxV.setVisibility(View.GONE);
view.setBackgroundColor(Color.WHITE);

AbsListView parentList = (AbsListView) parent;
Expand All @@ -355,6 +322,12 @@ public void onClick(View view) {
checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
}
checkBoxV.setVisibility(View.VISIBLE);
hideShareIcon(view);
hideOverflowMenuIcon(view, viewType);
} else {
checkBoxV.setVisibility(View.GONE);
showShareIcon(view, file);
showOverflowMenuIcon(view, file, viewType);
}

// this if-else is needed even though kept-in-sync icon is visible by default
Expand Down Expand Up @@ -430,6 +403,48 @@ public void onClick(View view) {
return view;
}

private void showShareIcon(View view, OCFile file) {
ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
sharedIconV.setVisibility(View.VISIBLE);
if (file.isSharedWithSharee() || file.isSharedWithMe()) {
sharedIconV.setImageResource(R.drawable.shared_via_users);
} else if (file.isSharedViaLink()) {
sharedIconV.setImageResource(R.drawable.shared_via_link);
} else {
sharedIconV.setImageResource(R.drawable.ic_unshared);
}
sharedIconV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OCFileListFragmentInterface.onShareIconClick(file);
}
});
}

private void hideShareIcon(View view) {
view.findViewById(R.id.sharedIcon).setVisibility(View.GONE);
}

private void showOverflowMenuIcon(View view, OCFile file, ViewType viewType) {
if (ViewType.LIST_ITEM.equals(viewType)) {
ImageView overflowIndicatorV = (ImageView) view.findViewById(R.id.overflow_menu);
overflowIndicatorV.setVisibility(View.VISIBLE);
overflowIndicatorV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OCFileListFragmentInterface.onOverflowIconClick(v, file);
}
});
}
}

private void hideOverflowMenuIcon(View view, ViewType viewType) {
if (ViewType.LIST_ITEM.equals(viewType)) {
ImageView overflowIndicatorV = (ImageView) view.findViewById(R.id.overflow_menu);
overflowIndicatorV.setVisibility(View.GONE);
}
}

@Override
public int getViewTypeCount() {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
lastModV.setVisibility(View.VISIBLE);
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
view.findViewById(R.id.overflow_menu).setVisibility(View.GONE);
}

if (!file.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public void onPrepareOptionsMenu(Menu menu) {
getFile(),
mContainerActivity.getStorageManager().getAccount(),
mContainerActivity,
getActivity()
getActivity(),
false
);
mf.filter(menu, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -107,6 +108,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -513,6 +515,34 @@ public void finishedFiltering() {
updateFooter();
}

@Override
public void onShareIconClick(OCFile file) {
shareFile(file);
}

@Override
public void onOverflowIconClick(View view, OCFile file) {
PopupMenu popup = new PopupMenu(getActivity(), view);
popup.inflate(R.menu.file_actions_menu);
FileMenuFilter mf = new FileMenuFilter(
mAdapter.getFiles().size(),
Collections.singleton(file),
((FileActivity) getActivity()).getAccount(),
mContainerActivity,
getActivity(),
true
);
mf.filter(popup.getMenu(), true);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ArrayList<OCFile> checkedFiles = new ArrayList<>(Collections.singletonList(file));
return onFileActionChosen(item.getItemId(), checkedFiles);
}
});
popup.show();
}

/**
* Handler for multiple selection mode.
*
Expand Down Expand Up @@ -632,7 +662,8 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
checkedFiles,
((FileActivity) getActivity()).getAccount(),
mContainerActivity,
getActivity()
getActivity(),
false
);
mf.filter(menu, false);
return true;
Expand All @@ -643,7 +674,8 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
*/
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return onFileActionChosen(item.getItemId());
ArrayList<OCFile> checkedFiles = mAdapter.getCheckedItems(getListView());
return onFileActionChosen(item.getItemId(), checkedFiles);
}

/**
Expand Down Expand Up @@ -902,10 +934,10 @@ public void onItemClick(AdapterView<?> l, View v, int position, long id) {
* Start the appropriate action(s) on the currently selected files given menu selected by the user.
*
* @param menuId Identifier of the action menu selected by the user
* @param checkedFiles List of files selected by the user on which the action should be performed
* @return 'true' if the menu selection started any action, 'false' otherwise.
*/
public boolean onFileActionChosen(int menuId) {
final ArrayList<OCFile> checkedFiles = mAdapter.getCheckedItems(getListView());
public boolean onFileActionChosen(int menuId, ArrayList<OCFile> checkedFiles) {
if (checkedFiles.size() <= 0) {
return false;
}
Expand All @@ -915,11 +947,7 @@ public boolean onFileActionChosen(int menuId) {
OCFile singleFile = checkedFiles.get(0);
switch (menuId) {
case R.id.action_share_file: {
if(singleFile.isSharedWithMe() && !singleFile.canReshare()){
Snackbar.make(getView(), R.string.resharing_is_not_allowed, Snackbar.LENGTH_LONG).show();
} else {
mContainerActivity.getFileOperationsHelper().showShareFile(singleFile);
}
shareFile(singleFile);
return true;
}
case R.id.action_open_file_with: {
Expand Down Expand Up @@ -1019,6 +1047,14 @@ public boolean onFileActionChosen(int menuId) {
}
}

private void shareFile(OCFile file) {
if(file.isSharedWithMe() && !file.canReshare()){
Snackbar.make(getView(), R.string.resharing_is_not_allowed, Snackbar.LENGTH_LONG).show();
} else {
mContainerActivity.getFileOperationsHelper().showShareFile(file);
}
}

/**
* Use this to query the {@link OCFile} that is currently
* being displayed by this fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
*/
package com.owncloud.android.ui.interfaces;

import android.view.View;

import com.owncloud.android.datamodel.OCFile;

/**
* Interface for signaling filter finish
* Interface for communication between {@link com.owncloud.android.ui.fragment.OCFileListFragment}
* and {@link com.owncloud.android.ui.adapter.FileListListAdapter}
*/

public interface OCFileListFragmentInterface {
void finishedFiltering();

int getColumnSize();

void onShareIconClick(OCFile file);

void onOverflowIconClick(View view, OCFile file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ public void onPrepareOptionsMenu(Menu menu) {
getFile(),
mContainerActivity.getStorageManager().getAccount(),
mContainerActivity,
getActivity()
getActivity(),
false
);
mf.filter(menu, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ public void onPrepareOptionsMenu(Menu menu) {
getFile(),
mContainerActivity.getStorageManager().getAccount(),
mContainerActivity,
getActivity()
getActivity(),
false
);
mf.filter(menu, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public void onPrepareOptionsMenu(Menu menu) {
getFile(),
mContainerActivity.getStorageManager().getAccount(),
mContainerActivity,
getActivity()
getActivity(),
false
);
mf.filter(menu, true);
}
Expand Down
File renamed without changes
Binary file removed src/main/res/drawable-hdpi/shared_via_link.png
Binary file not shown.
File renamed without changes
Binary file removed src/main/res/drawable-mdpi/shared_via_link.png
Binary file not shown.
Binary file removed src/main/res/drawable-xhdpi/shared_via_link.png
Binary file not shown.
Binary file removed src/main/res/drawable-xxhdpi/shared_via_link.png
Binary file not shown.
Binary file removed src/main/res/drawable-xxxhdpi/shared_via_link.png
Binary file not shown.
Loading

0 comments on commit 620f9db

Please sign in to comment.