5_4-手机开播场景-文档管理
1 Feature Overview
The document management module includes features such as selecting PPT documents, uploading & deleting PPT documents, and viewing details of each PPT page. Document management is a popup page, and the entire interface is encapsulated within PLVLSPptListLayout.
2 Usage Demo
Document management is a popup page. Unlike layouts directly written into XML, using a popup page only requires creating a popup object and calling the open() method to display the popup.
// PLVLSStatusBarLayout.java
private void initView() {
// 创建了文档管理弹层页面
pptListLayout = new PLVLSPptListLayout(getContext());
}
private void processSelectDocument() {
if (pptListLayout != null) {
// 点击状态栏上面的文档图标时,调用open打开文档管理弹层
pptListLayout.open();
}
}
3 Implementation Details
3.1 Document Display Section
Document display includes two types of lists: the document list showing all PPT covers PLVLSPptViewType.COVER, and the document detail list showing details of each PPT page PLVLSPptViewType.PAGE. Both lists use the same RecyclerView and Adapter, distinguished by setting different viewTypes for the Adapter.
The following code demonstrates how to obtain data for all PPT document lists and set it to the Adapter for list display.
// PLVLSPptListLayout.java
public void open() {
// 打开弹层时,初始化弹层视图
initViewByShowType();
}
private void initViewByShowType() {
// 请求更新数据
requestUpdateData();
}
/**
* 根据显示样式,向Presenter请求更新列表数据
*/
private void requestUpdateData() {
if (showViewType == PLVLSPptViewType.COVER) {
// 向Presenter请求更新PPT文档列表数据
PLVDocumentPresenter.getInstance().requestGetPptCoverList();
} else if (showViewType == PLVLSPptViewType.PAGE) {
PLVDocumentPresenter.getInstance().requestGetPptPageList(currentAutoId);
}
}
After asynchronously requesting and obtaining the document list data, the Presenter will call back the document list data to the view.
// PLVLSPptListLayout.java
// MVP - View 回调实现
mvpView = new PLVAbsDocumentView() {
@Override
public void onPptCoverList(@Nullable PLVSPPTInfo pptInfo) {
processPptCoverList(pptInfo);
}
}
In the method processPptCoverList(), the document data is parsed and converted into view objects PLVLSPptVO. The list of view objects is then passed to the Adapter to display the document list.
3.2 Document Upload and Deletion Section
Document deletion is implemented by calling the Presenter's deleteDocument() method.
// PLVLSPptListLayout.java
// 设置列表项长按点击监听
pptListAdapter.setOnPptItemLongClickListener(new PLVLSPptListViewHolder.OnPptItemLongClickListener() {
@Override
public void onLongClick(View view, final int id, final String fileId) {
if (pptListAdapter.getRealViewType() != PLVLSPptViewType.COVER) {
return;
}
if (documentDeleteArrow != null) {
// 设置删除确认箭头的点击回调
documentDeleteArrow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 点击删除箭头后 弹窗提示是否删除
documentDeleteConfirmDialog
.setRightBtnListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 点击确认后,调用Presenter删除文档
PLVDocumentPresenter.getInstance().deleteDocument(fileId);
documentDeleteConfirmDialog.hide();
}
})
.show();
}
});
// 显示删除确认箭头
documentDeleteArrow.showAtLocation(view);
}
}
});
The document upload section is more complex, involving monitoring 9 document upload states (see enum PLVPptUploadStatus), caching local document upload states, and handling document upload failure states. For specific implementation details of document upload, refer to the code block Initialization Method - Document Upload State Related Callback Settings in the PLVLSPptListLayout class.
