关于android:智汀云盘开发指南android端文件夹共享

47次阅读

共计 3229 个字符,预计需要花费 9 分钟才能阅读完成。

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();}
        });
    }

    ...
}

正文完
 0