use of com.prpr894.cplayer.adapters.recycleradapters.CollectionBackupListRecyclerAdapter in project cuddly-octo-fortnight by prpr894.
the class SettingsActivity method readCollectionDialog.
private void readCollectionDialog() {
AlertDialog.Builder builder;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(this);
}
builder.setCancelable(false);
builder.setTitle("恢复备份");
builder.setIcon(R.drawable.ic_backup);
if (mCollectionBackupBean.getData() == null || mCollectionBackupBean.getData().size() <= 0) {
builder.setMessage("提示:暂无备份。");
} else {
builder.setMessage("提示:点击条目然后选择恢复或删除。");
}
View view = LayoutInflater.from(this).inflate(R.layout.dialogl_collection_read, null, false);
RecyclerView recyclerView = view.findViewById(R.id.recycler_view_read_collection);
final List<CollectionBackupItemDataBean> list = mCollectionBackupBean.getData();
final CollectionBackupListRecyclerAdapter adapter = new CollectionBackupListRecyclerAdapter(list, SettingsActivity.this);
RecyclerView.ItemDecoration decoration = new RecyclerView.ItemDecoration() {
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int position = parent.getChildAdapterPosition(view);
if (position != list.size() - 1) {
outRect.set(0, 0, 0, 10);
}
}
};
recyclerView.addItemDecoration(decoration);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(SettingsActivity.this));
builder.setView(view);
builder.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNeutralButton("清空备份", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialogPa, int which) {
if (mCollectionBackupBean.getData() == null || mCollectionBackupBean.getData().size() <= 0) {
MyToast.errorBig("当前没有备份!");
return;
}
AlertDialog.Builder builder;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
builder = new AlertDialog.Builder(SettingsActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(SettingsActivity.this);
}
builder.setCancelable(false);
builder.setTitle("警告");
builder.setMessage("清空数据不可恢复,确定清空收藏备份吗?");
builder.setPositiveButton("清空", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (file.delete()) {
mCollectionBackupBean.getData().clear();
MyToast.successBig("清除成功");
} else {
MyToast.errorBig("清除失败");
}
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
});
final AlertDialog dialog = builder.create();
adapter.setOnRecyclerItemClickListener(new CollectionBackupListRecyclerAdapter.OnRecyclerItemClickListener() {
@Override
public void onRecyclerItemClick(final int position, CollectionBackupItemDataBean data, View view) {
dialog.dismiss();
AlertDialog.Builder builder;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
builder = new AlertDialog.Builder(SettingsActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(SettingsActivity.this);
}
builder.setCancelable(false);
builder.setTitle("提示");
// builder.setMessage("对于备份 " + data.getBackupDate() + "\n请选择你想执行的操作:");
builder.setMessage(Html.fromHtml("对于备份 <font color='#47C4FC'>" + data.getBackupDate() + "</font><br>请选择你想执行的操作:"));
builder.setPositiveButton("恢复备份", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LiveRoomItemDataBeanDao dao = MyApp.getInstance().getDaoSession().getLiveRoomItemDataBeanDao();
dao.deleteAll();
dao.insertInTx(mCollectionBackupBean.getData().get(position).getData());
dialog.dismiss();
MyToast.successBig("恢复成功");
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNeutralButton("删除", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
adapter.remove(position);
Gson gson = new Gson();
saveCollectionFile(gson.toJson(mCollectionBackupBean));
dialog.dismiss();
MyToast.successBig("删除成功");
}
});
builder.create().show();
}
});
dialog.show();
}
Aggregations