1. 阐明
存储池是存储池分区及文件操作的根基,只有存储池存在,能力操作存储池分区和文件夹,是数据存储的中央。
只有有闲置的存储池(硬盘),咱们就能够把它增加到现有的存储池或者是新的存储池,而后回到存储池列表就能够看到刷新的数据。
除了增加和查看存储池之外,咱们还能够批改存储池的名称、删除存储和增加存储池分区、查看存储池分区、辑存储池分区及删除存储池分区(存储池分区的操作将会在下一章节进行阐明)。
因为删除存储池须要肯定的工夫,所以存在存储池删除中的状态;删除存储池不肯定能删除胜利,所以存在删除存储池失败的状态。
注:只有家庭的拥有者能力操作存储池
1.1 次要代码实现
1.2 存储池列表和存储详情的 model 类
/**
* 存储池列表
*/
public class StoragePoolListBean {
private List<StoragePoolDetailBean> list; // tem 为 object, 存储池
private PagerBean pager; // 分页数据
...
}
/**
* 存储池详情
*/
public class StoragePoolDetailBean implements MultiItemEntity, Serializable {
public static final int POOL = 1; // 本人定义字段增加存储池时是存储
public static final int ADD = 2; // 本人定义字段增加存储池时是最初的加号图片
private int itemType; // 本人定义字段,用于辨别增加存储池时是存储还是最初的加号图片
private boolean selected; // 本人定义字段,用于示意存储增加存储池时是否抉择
private String id;
private String name; // 名称
private double capacity; // 容量
private double use_capacity; // 已用容量
/**
* // 异步工作状态, 为空则没有异步工作,
* TaskDelPool_0 删除存储池失败,TaskDelPool_1 删除存储池中,
* TaskAddPool_0 增加存储池失败,TaskAddPool_1 增加存储池中,
* TaskUpdatePool_0 批改存储池失败,TaskUpdatePool_1 批改存储池中,
*/
private String status;
private String task_id; // 异步工作 ID
private List<DiskBean> pv; // 物理分区:就是所谓硬盘
private List<DiskBean> lv; // 逻辑分区:理论存储池分区
...
}
/**
* 硬盘和存储池分区
*/
public class DiskBean implements Serializable {
/**
* id : 4255
* name : 安但风张义
* capacity : 91.2
*/
private String id;
private String name;
private long capacity;
private long use_capacity; // 已用容量
private boolean selected;
/**
* 为空则没有工作状态,
* TaskAddPartition_1 增加存储池分区中,TaskAddPartition_0 增加存储池分区失败,
* TaskUpdatePartition_1 批改存储池分区中,TaskUpdatePartition_0 批改存储池分区失败,
* TaskDelPartition_1 删除存储池分区中,TaskDelPartition_0 删除存储池分区失败
*/
private String status;
private String task_id; // 异步工作 id
...
}
2.2 存储池列表及闲置硬盘
/**
* 存储管理(存储池列表)*/
public class StoragePoolListActivity extends BaseMVPDBActivity<ActivityStoragePoolListBinding, StoragePoolListContract.View, StoragePoolListPresenter> implements StoragePoolListContract.View {
...
/**
* 闲置硬盘
*/
private void initRvDisk(){LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.HORIZONTAL);
binding.rvDisk.setLayoutManager(layoutManager);
diskAdapter = new DiskAdapter();
binding.rvDisk.setAdapter(diskAdapter);
diskAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {DiskBean diskBean = diskAdapter.getItem(position);
if (view.getId() == R.id.tvAdd){Bundle bundle = new Bundle();
bundle.putString("diskName", diskBean.getName());
bundle.putLong("capacity", diskBean.getCapacity());
switchToActivity(AddToStoragePoolActivity.class, bundle);
}
}
});
}
/**
* 存储池
*/
private void initRvPool(){
...
storagePoolAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {StoragePoolDetailBean storagePoolDetailBean = storagePoolAdapter.getItem(position);
if (TextUtils.isEmpty(storagePoolDetailBean.getStatus())) { // 没有异步状态才可跳转
Bundle bundle = new Bundle();
bundle.putString("name", storagePoolDetailBean.getName());
switchToActivity(StoragePoolDetailActivity.class, bundle);
}
}
});
storagePoolAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {StoragePoolDetailBean storagePoolDetailBean = storagePoolAdapter.getItem(position);
int viewId = view.getId();
if (viewId == R.id.ivDot){ // 显示物理硬盘个数
showHardDiskDialog(storagePoolAdapter.getItem(position).getPv());
}else if (viewId == R.id.tvRetry){ // 重试
String status = storagePoolDetailBean.getStatus();
if (status!=null){if (status.equals(Constant.STORAGE_POOL_DELETE_FAIL)){ // 删除失败
mPresenter.restartTask(Constant.scope_token, storagePoolDetailBean.getTask_id());
}
}
}
}
});
}
...
}
public class StoragePoolListPresenter extends BasePresenter<StoragePoolListModel, StoragePoolListContract.View> implements StoragePoolListContract.Presenter {
...
/**
* 获取存储池列表
* @param scopeToken
* @param map
* @param showLoading
*/
@Override
public void getStoragePools(String scopeToken, Map<String, String> map, boolean showLoading) {executeObservable(mModel.getStoragePools(scopeToken, map), new RequestDataCallback<StoragePoolListBean>(showLoading) {
@Override
public void onSuccess(StoragePoolListBean response) {super.onSuccess(response);
if (mView!=null){mView.getStoragePoolsSuccess(response);
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.getStoragePoolsFail(errorCode, errorMessage);
}
}
});
}
/**
* 闲置硬盘列表
* @param scopeToken
*/
@Override
public void getDisks(String scopeToken) {executeObservable(mModel.getDisks(scopeToken), new RequestDataCallback<DiskListBean>(false) {
@Override
public void onSuccess(DiskListBean response) {super.onSuccess(response);
if (mView!=null){mView.getDisksSuccess(response);
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.getDisksFail(errorCode, errorMessage);
}
}
});
}
...
}
2.4 增加到存储池
...
/**
* 创立存储池
* @param scopeToken
* @param createStoragePoolRequest
*/
@Override
public void createStoragePool(String scopeToken, CreateStoragePoolRequest createStoragePoolRequest) {executeObservable(mModel.createStoragePool(scopeToken, createStoragePoolRequest), new RequestDataCallback<Object>() {
@Override
public void onSuccess(Object response) {super.onSuccess(response);
if (mView!=null){mView.createStoragePoolSuccess();
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.createStoragePoolFail(errorCode, errorMessage);
}
}
});
}
/**
* 增加硬盘到存储池
* @param scopeToken
* @param addStoragePoolRequest
*/
@Override
public void addToStoragePool(String scopeToken, AddStoragePoolRequest addStoragePoolRequest) {executeObservable(mModel.addToStoragePool(scopeToken, addStoragePoolRequest), new RequestDataCallback<Object>() {
@Override
public void onSuccess(Object response) {super.onSuccess(response);
if (mView!=null){mView.addToStoragePoolSuccess();
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.addToStoragePoolFail(errorCode, errorMessage);
}
}
});
}
}
public class AddToStoragePoolPresenter extends BasePresenter<AddToStoragePoolModel, AddToStoragePoolContract.View> implements AddToStoragePoolContract.Presenter {
...
/**
* 创立存储池
* @param scopeToken
* @param createStoragePoolRequest
*/
@Override
public void createStoragePool(String scopeToken, CreateStoragePoolRequest createStoragePoolRequest) {executeObservable(mModel.createStoragePool(scopeToken, createStoragePoolRequest), new RequestDataCallback<Object>() {
@Override
public void onSuccess(Object response) {super.onSuccess(response);
if (mView!=null){mView.createStoragePoolSuccess();
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.createStoragePoolFail(errorCode, errorMessage);
}
}
});
}
/**
* 增加硬盘到存储池
* @param scopeToken
* @param addStoragePoolRequest
*/
@Override
public void addToStoragePool(String scopeToken, AddStoragePoolRequest addStoragePoolRequest) {executeObservable(mModel.addToStoragePool(scopeToken, addStoragePoolRequest), new RequestDataCallback<Object>() {
@Override
public void onSuccess(Object response) {super.onSuccess(response);
if (mView!=null){mView.addToStoragePoolSuccess();
}
}
@Override
public void onFailed(int errorCode, String errorMessage) {super.onFailed(errorCode, errorMessage);
if (mView!=null){mView.addToStoragePoolFail(errorCode, errorMessage);
}
}
});
}
}
2.5 存储池详情
/**
* 存储池详情
*/
public class StoragePoolDetailActivity extends BaseMVPDBActivity<ActivityStoragePoolDetailBinding, StoragePoolDetailContract.View, StoragePoolDetailPresenter> implements StoragePoolDetailContract.View {
...
/**
* 获取存储池详情胜利
* @param storagePoolDetailBean
*/
@Override
public void getStoragePoolDetailSuccess(StoragePoolDetailBean storagePoolDetailBean) {binding.refreshLayout.finishRefresh();
if (storagePoolDetailBean!=null){
mStoragePoolDetailBean = storagePoolDetailBean;
poolId = storagePoolDetailBean.getId();
binding.tvName.setText(storagePoolDetailBean.getName());
double usedCapacity = storagePoolDetailBean.getUse_capacity();
double allCapacity = storagePoolDetailBean.getCapacity();
double availableCapacity = allCapacity - usedCapacity;
binding.tvSeparable.setText(FileUtil.getReadableFileSize(availableCapacity)+UiUtil.getString(R.string.mine_separable_capacity));
binding.tvAll.setText(FileUtil.getReadableFileSize(allCapacity)+UiUtil.getString(R.string.mine_all_capacity));
List<DiskBean> hardDisk = storagePoolDetailBean.getPv(); // 硬盘列表
int hardDiskCount = CollectionUtil.isNotEmpty(hardDisk) ? hardDisk.size() : 0; // 硬盘个数
binding.tvCount.setText(StringUtil.getStringFormat(UiUtil.getString(R.string.mine_hard_disk_count), hardDiskCount));
int progress = (int) ((usedCapacity/allCapacity)*100); // 容量进度百分比
isSystemPool = storagePoolDetailBean.getName().equals(Constant.SYSTEM_POOL); // 是否是零碎存储池
binding.tvDel.setVisibility(isSystemPool ? View.GONE : View.VISIBLE); // 是零碎存储池可删除
binding.tvName.setCompoundDrawablesWithIntrinsicBounds(0, 0, isSystemPool ? 0 : R.drawable.icon_white_edit, 0); // 是零碎存储池不可编辑
binding.tvCount.setCompoundDrawablesWithIntrinsicBounds(0, 0, isSystemPool ? 0 : R.drawable.icon_white_right_arrow, 0); // 是零碎存储池查看磁盘不可操作
binding.tvCount.setEnabled(!isSystemPool);// 是零碎存储池查看磁盘不可操作
binding.ivAdd.setVisibility(isSystemPool ? View.GONE : View.VISIBLE); // 是零碎存储池不可增加存储分区
binding.rb.setProgress(progress);
storagePoolDetailAdapter.setNewData(storagePoolDetailBean.getLv());
setNullView(CollectionUtil.isEmpty(storagePoolDetailBean.getLv()));
binding.coordinatorLayout.setVisibility(View.VISIBLE);
}
}
...
}