Search in sources :

Example 1 with CollectionBackupItemDataBean

use of com.prpr894.cplayer.bean.CollectionBackupItemDataBean 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();
}
Also used : AlertDialog(android.app.AlertDialog) Rect(android.graphics.Rect) DialogInterface(android.content.DialogInterface) Canvas(android.graphics.Canvas) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) CollectionBackupListRecyclerAdapter(com.prpr894.cplayer.adapters.recycleradapters.CollectionBackupListRecyclerAdapter) LiveRoomItemDataBeanDao(com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao) RecyclerView(android.support.v7.widget.RecyclerView) CollectionBackupItemDataBean(com.prpr894.cplayer.bean.CollectionBackupItemDataBean)

Example 2 with CollectionBackupItemDataBean

use of com.prpr894.cplayer.bean.CollectionBackupItemDataBean 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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) CollectionBackupItemDataBean(com.prpr894.cplayer.bean.CollectionBackupItemDataBean) LiveRoomItemDataBeanDao(com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao)

Aggregations

AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Gson (com.google.gson.Gson)2 CollectionBackupItemDataBean (com.prpr894.cplayer.bean.CollectionBackupItemDataBean)2 LiveRoomItemDataBeanDao (com.prpr894.cplayer.greendao.gen.LiveRoomItemDataBeanDao)2 Canvas (android.graphics.Canvas)1 Rect (android.graphics.Rect)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 CollectionBackupListRecyclerAdapter (com.prpr894.cplayer.adapters.recycleradapters.CollectionBackupListRecyclerAdapter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1