use of com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao in project cuddly-octo-fortnight by prpr894.
the class MainActivity method initView.
private void initView() {
mToolbar = findViewById(R.id.toolbar_main);
mToolbar.setTitle("直播");
mCustomDrawerLayout = findViewById(R.id.drawer);
// 注意此段顺序
setSupportActionBar(mToolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
// 不能挪走,应在上面两行的下面
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mCustomDrawerLayout, mToolbar, 0, 0);
mCustomDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
mNavigationView = findViewById(R.id.navigation);
mNavigationView.setNavigationItemSelectedListener(this);
// 开启彩色图标
mNavigationView.setItemIconTintList(null);
// 初始化一些东西
mNavigationView.setCheckedItem(R.id.s_live);
switchPage(0);
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_settings:
AlertDialog.Builder builder;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
builder = new AlertDialog.Builder(MainActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(MainActivity.this);
}
builder.setCancelable(false);
builder.setTitle("警告");
builder.setMessage("清空数据不可恢复,确定清空收藏吗?");
builder.setPositiveButton("清空", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
LiveRoomItemDataBeanDao beanDao = MyApp.getInstance().getDaoSession().getLiveRoomItemDataBeanDao();
beanDao.deleteAll();
MyToast.successBig("清除成功");
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
break;
}
return true;
}
});
}
use of com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao 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();
}
use of com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao in project cuddly-octo-fortnight by prpr894.
the class SettingsActivity method saveCollectionDialog.
private void saveCollectionDialog() {
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.setMessage("确定备份当前收藏夹的全部内容到内置SD吗?");
builder.setNegativeButton("否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LiveRoomItemDataBeanDao dao = MyApp.getInstance().getDaoSession().getLiveRoomItemDataBeanDao();
CollectionBackupItemDataBean bean = new CollectionBackupItemDataBean();
bean.setBackupDate(DateUtils.getStrDate());
bean.setData(dao.loadAll());
List<CollectionBackupItemDataBean> data;
if (mCollectionBackupBean.getData() == null) {
data = new ArrayList<>();
} else {
data = mCollectionBackupBean.getData();
}
data.add(bean);
mCollectionBackupBean.setData(data);
Gson gson = new Gson();
saveCollectionFile(gson.toJson(mCollectionBackupBean));
dialog.dismiss();
}
});
builder.create().show();
}
Aggregations