添加记录待提交的 删除 全选功能

This commit is contained in:
md 2021-06-18 20:45:01 +08:00
parent 6b17e85f27
commit 5eedfa91a1
6 changed files with 121 additions and 20 deletions

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
//ndkVersion '23.0.7123448'
ndkVersion '23.0.7123448'
defaultConfig {
applicationId "com.navinfo.outdoor"

View File

@ -1,10 +1,13 @@
package com.navinfo.outdoor.adapter;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -13,26 +16,64 @@ import androidx.recyclerview.widget.RecyclerView;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.bean.CapacityMeasureBean;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static com.tencent.mapsdk.internal.aaa.getContext;
public class StaySubmitAdapter extends RecyclerView.Adapter<StaySubmitAdapter.ViewHolder> {
private List<PoiEntity> allRoad = new ArrayList<>();
private Context context;
public StaySubmitAdapter(Context context) {
this.context = context;
}
public void setAllRoad(List<PoiEntity> allRoad) {
this.allRoad.addAll(allRoad);
if (this.allRoad!=null) {
this.allRoad.clear();
this.allRoad.addAll(allRoad);
}
notifyDataSetChanged();
}
public void setAllDataChecked(boolean isChecked) {
if (this.allRoad!=null) {
for (PoiEntity entity: this.allRoad) {
entity.setChecked(isChecked);
}
}
}
public void setAllCheckedDelete(){
new Thread(new Runnable() {
@Override
public void run() {
Iterator iterator = allRoad.iterator();
while (iterator.hasNext()) {
PoiEntity poiEntity = (PoiEntity) iterator.next();
if (poiEntity.isChecked()) {
PoiDatabase.getInstance(context).getPoiDao().deletePoiEntity(poiEntity);
iterator.remove();
}
}
handler.sendEmptyMessage(0x105);
}
}).start();
}
@NonNull
@NotNull
@Override
@ -46,7 +87,13 @@ public class StaySubmitAdapter extends RecyclerView.Adapter<StaySubmitAdapter.Vi
PoiEntity poiEntity = allRoad.get(position);
holder.tvName.setText(poiEntity.getName());
holder.tvDay.setText(poiEntity.getCreateTime());
holder.cbUnSubmit.setChecked(allRoad.get(position).isChecked());
holder.cbUnSubmit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
allRoad.get(position).setChecked(isChecked);
}
});
}
@Override
@ -55,16 +102,27 @@ public class StaySubmitAdapter extends RecyclerView.Adapter<StaySubmitAdapter.Vi
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tvName;
private TextView tvDay;
private CheckBox cbAll;
private CheckBox cbUnSubmit;
public ViewHolder(@NonNull @NotNull View itemView) {
super(itemView);
tvName = itemView.findViewById(R.id.tv_road_name);
tvDay = itemView.findViewById(R.id.tv_road_day);
cbAll = itemView.findViewById(R.id.cb_all);
cbUnSubmit = itemView.findViewById(R.id.cb_unSubmit);
}
}
Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull @NotNull Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0x105:
notifyDataSetChanged();
break;
}
}
};
}

View File

@ -29,7 +29,10 @@ import com.navinfo.outdoor.room.PoiDao;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/**
@ -71,7 +74,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
tvPictures.setOnClickListener(this::onClick);
etRoadName = (EditText) findViewById(R.id.et_road_name);
ivRoadPicture = (ImageView) findViewById(R.id.iv_road_picture);
Glide.with(getContext()).load(getLocalVideoBitmap(String.valueOf(R.drawable.bg_01))).into(ivRoadPicture);
// Glide.with(getContext()).load(getLocalVideoBitmap(String.valueOf(R.drawable.bg_01))).into(ivRoadPicture);
rbCar = (RadioButton) findViewById(R.id.rb_car);
rbBicycle = (RadioButton) findViewById(R.id.rb_bicycle);
rbWalking = (RadioButton) findViewById(R.id.rb_walking);
@ -157,6 +160,11 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
} else {
poiEntity.setDescribe(desc);
}
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
String format = formatter.format(calendar.getTime());
poiEntity.setCreateTime(format);
new Thread(new Runnable() {
@Override
public void run() {

View File

@ -1,12 +1,19 @@
package com.navinfo.outdoor.fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.DividerItemDecoration;
@ -25,8 +32,12 @@ import com.navinfo.outdoor.room.PoiDao;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import org.jetbrains.annotations.NotNull;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
@ -42,13 +53,15 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
private PoiDao poiDao;
private TextView tvStayType;
private TextView tvStayResult;
private ArrayList<Object> poiEntities;
private List<PoiEntity> poiEntities;
public static StaySubmitFragment newInstance(Bundle bundle) {
StaySubmitFragment fragment = new StaySubmitFragment();
fragment.setArguments(bundle);
return fragment;
}
@Override
protected int getLayout() {
return R.layout.fragment_stay_submit;
@ -66,7 +79,9 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
tvStayResult.setOnClickListener(this::onClick);
stayXrv = (XRecyclerView) findViewById(R.id.stay_xrv);
cbSelect = (CheckBox) findViewById(R.id.cb_select);
cbSelect.setOnClickListener(this::onClick);
tvDelete = (TextView) findViewById(R.id.tv_delete);
tvDelete.setOnClickListener(this::onClick);
btnStaySubmit = (Button) findViewById(R.id.btn_stay_submit);
stayXrv.setLayoutManager(new LinearLayoutManager(getActivity()));
stayXrv.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
@ -77,6 +92,13 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
stayXrv.setLoadingMoreEnabled(false);
staySubmitAdapter = new StaySubmitAdapter(getContext());
stayXrv.setAdapter(staySubmitAdapter);
cbSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
staySubmitAdapter.setAllDataChecked(isChecked);
staySubmitAdapter.notifyDataSetChanged();
}
});
stayXrv.getDefaultFootView().setNoMoreHint("加载完毕");
stayXrv.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
@ -91,6 +113,7 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
});
}
@Override
protected void initData() {
super.initData();
@ -100,21 +123,19 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
new Thread(new Runnable() {
@Override
public void run() {
List<PoiEntity> allRoad = poiDao.getAllPoi();
poiEntities = poiDao.getAllPoi();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d("TAG", "run: " + allRoad.toString());
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm ");
// Date curDate = new Date(System.currentTimeMillis());//获取当前时间
// String str = formatter.format(curDate);
//
poiEntities.addAll(allRoad);
staySubmitAdapter.setAllRoad(allRoad);
Log.d("TAG", "run: " + poiEntities.toString());
staySubmitAdapter.setAllRoad(poiEntities);
staySubmitAdapter.notifyDataSetChanged();
}
});
}
}).start();
}
@Override
@ -128,10 +149,14 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList
@Override
public void onClick(String text, int index) {
tvStayType.setText(text);
}
});
break;
case R.id.tv_delete:
staySubmitAdapter.setAllCheckedDelete();
break;
}
}
}

View File

@ -27,6 +27,16 @@ public class PoiEntity {
private double precision;//金额
private String photo;//照片信息
private String extend;//添加字段
private boolean checked;
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public String getExtend() {
return extend;
}

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="90dp"
android:layout_margin="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -34,7 +34,7 @@
app:layout_constraintTop_toBottomOf="@id/tv_road_name"/>
</LinearLayout>
<CheckBox
android:id="@+id/cb_all"
android:id="@+id/cb_unSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"