package com.android.dailyplanning.adapter;
import com.android.dailyplanning.R;
import com.android.dailyplanning.entity.Plan;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;
import androidx.annotation.Nullable;
public class PlanAdapter extends BaseQuickAdapter {
public PlanAdapter() {
super(R.layout.item_plan);
}
public PlanAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, Plan item) {
helper.setText(R.id.tv_day, item.getDay());
helper.setText(R.id.tv_label, item.getLabel());
helper.setText(R.id.tv_start_time, "开始时间:"+item.getStartTime());
helper.setText(R.id.tv_end_time, "结束时间:"+item.getEndTime());
helper.setText(R.id.tv_duration, "时长:"+item.getDuration());
helper.setText(R.id.tv_keyword,"任务关键词:"+item.getKeyword());
helper.setText(R.id.tv_content, "规划内容:"+item.getContent());
helper.setText(R.id.tv_status, item.isSignIn() ? "状态:已签到" : "状态:未签到");
}
}
public class DailyFragment extends Fragment {
@BindView(R.id.plan_list)
RecyclerView planList; //当价于RecyclerView planList = (RecyclerView) findViewById(R.id.plan_list)
/* @BindView(R.id.bt_revise)
Button btRevise;
@BindView(R.id.bt_delete)
Button btDelete;*/
@BindView(R.id.btn_add_plan)
FloatingActionButton btnAddPlan;
Unbinder unbinder; //
@BindView(R.id.btn_pdf)
FloatingActionButton btnPdf;
private PlanAdapter planAdapter;
private float BORDER_WIDTH = MyUtils.dip2Dimension(1, App.app);
List<Plan> plans;
boolean S1;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_daily, null);
unbinder = ButterKnife.bind(this, view); //注解框架ButterKnife
planList.setLayoutManager(new LinearLayoutManager(getActivity()));
planList.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
// planAdapter = new PlanAdapter();
planAdapter = new PlanAdapter(R.layout.item_plan,plans);
planList.setAdapter(planAdapter);
//item长按删除
planAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(BaseQuickAdapter adapter, View view, final int position) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 设置Title的图标
builder.setIcon(R.drawable.ic_wc);
// 设置Title的内容
builder.setTitle("弹出警告框");
// 设置Content来显示一个信息
builder.setMessage("确定删除吗?");
// 设置一个PositiveButton
builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Plan plan1 = new Plan();
plan1.setObjectId(plans.get(position).getObjectId());
plan1.delete(new UpdateListener() {
@Override
public void done(BmobException e) {
if(e==null){
S1 = true;
}else{
S1 = false;
}
}
});
}
});
// 设置一个NegativeButton
builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
return;
}
});
return S1;
}
});