1. 说明
文件夹共享分为两种情况:
- 一种是在创建文件夹时选择文件夹类型为共享文件夹,另外别人共享给我的文件夹。
- 第一种情况是没有共享者的,根目录不能共享,相当于可以有多个访问成员的非共享文件夹;
第二种情况是有共享者的,在共享文件列表可以再共享给别人。
以第一种方式共享文件夹时,可以给访问者设置读、写和删权限;
以第二种方式共享文件夹,读、写和删的权限受制于共享者自己是否有对应的权限。
在设置权限时,如果用户去掉了读权限,那么写和删权限也会随之去掉;如果用户选择了写或删权限,那么会自动把读权限也选上。
1)主要代码实现
/**
* 共享文件夹
*/
public class ShareFolderActivity extends BaseMVPDBActivity<ActivityShareFolderBinding, ShareFolderContract.View, ShareFolderPresenter> implements ShareFolderContract.View {
...
/**
* 编辑成员弹窗
*/
private void initOperatePermissionDialog(){
operatePermissionDialog = OperatePermissionDialog.getInstance();
operatePermissionDialog.setConfirmListener(new OperatePermissionDialog.OnConfirmListener() {
@Override
public void onConfirm(int read, int write, int del) {
List<String> paths = new ArrayList<>();
for (FileBean fileBean : folders){ // 要共享的文件夹
paths.add(fileBean.getPath());
}
List<Integer> to_users = new ArrayList<>();
for (MemberBean.UsersBean usersBean : memberAdapter.getSelectedUsers()){ // 选择的成员
to_users.add(usersBean.getUser_id());
}
ShareRequest shareRequest = new ShareRequest(to_users, paths, read, write, del, Constant.userName);
mPresenter.share(Constant.scope_token, shareRequest);
}
});
}
...
public class OnClickHandler {
public void onClick(View view) {
int viewId = view.getId();
if (viewId == R.id.ivBack){ // 返回
...
}else if (viewId == R.id.tvAll){ // 全选
...
}else if (viewId == R.id.tvConfirm){ // 确定
Bundle bundle = new Bundle();
bundle.putInt("read", 1); // 读权限
bundle.putBoolean("originalWrite", originalWrite); // 写权限
bundle.putBoolean("originalDel", originalDel); // 删权限
bundle.putBoolean("checkSaveEnabled", true);
List<PermissionUserBean> users = new ArrayList<>();
for (MemberBean.UsersBean usersBean : memberAdapter.getSelectedUsers()) {
PermissionUserBean permissionUserBean = new PermissionUserBean(usersBean.getNickname(), "");
users.add(permissionUserBean);
}
bundle.putSerializable("users", (Serializable) users);
operatePermissionDialog.setArguments(bundle);
operatePermissionDialog.show(ShareFolderActivity.this);
}
}
}
}
/**
* 用户操作权限弹窗
*/
public class OperatePermissionDialog extends CommonBaseDialog {
...
@Override
protected void initArgs(Bundle arguments) {
read = arguments.getInt("read", 0);
write = arguments.getInt("write", 0);
del = arguments.getInt("del", 0);
originalWrite = arguments.getBoolean("originalWrite");
originalDel = arguments.getBoolean("originalDel");
checkSaveEnabled = arguments.getBoolean("checkSaveEnabled");
users = (List<PermissionUserBean>) arguments.getSerializable("users");
}
...
/**
* 初始化列表
*/
private void initRv(){
...
operatePermissionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
OperatePermissionBean operatePermissionBean = operatePermissionAdapter.getItem(position);
boolean selected = operatePermissionBean.isSelected();
operatePermissionBean.setSelected(!selected);
List<OperatePermissionBean> permissionData = operatePermissionAdapter.getData();
switch (position){
case 0:
read = selected ? 0 : 1;
if (read == 0){ // 如果没有读权限,也就没有写删权限
for (OperatePermissionBean opb : permissionData){
opb.setSelected(false);
}
write = 0;
del = 0;
}
break;
case 1:
write = selected ? 0 : 1;
if (write == 1){ // 如果选择了写权限,读权限也要一并选择
permissionData.get(0).setSelected(true);
read = 1;
}
break;
case 2:
del = selected ? 0 : 1;
if (del == 1){ // 如果选择了删权限,读权限也要一并选择
permissionData.get(0).setSelected(true);
read = 1;
}
break;
}
operatePermissionAdapter.notifyDataSetChanged();
setSaveStatus();
}
});
}
...
}
|