| | |
| | | import android.view.View; |
| | | import android.widget.AdapterView; |
| | | |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | |
| | | import com.dayu.recharge.adapter.NewCardAdapter; |
| | | import com.dayu.recharge.adapter.ReplacementAdapter; |
| | | import com.dayu.recharge.databinding.ActivityReplacementBinding; |
| | | import com.dayu.recharge.dbBean.UserCardBean; |
| | | import com.dayu.recharge.utils.TipUtil; |
| | | import com.dayu.recharge.view.EdtDialog; |
| | | import com.scwang.smart.refresh.footer.ClassicsFooter; |
| | | import com.scwang.smart.refresh.layout.api.RefreshLayout; |
| | | import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; |
| | | import io.reactivex.rxjava3.core.Observable; |
| | | import io.reactivex.rxjava3.schedulers.Schedulers; |
| | | |
| | | /** |
| | | * Created by Android Studio. |
| | |
| | | * 备注: 补卡界面 |
| | | */ |
| | | public class ReplacementActivity extends BaseActivity { |
| | | ActivityReplacementBinding binding; |
| | | List<UserCardBean> userCardBeanList; |
| | | NewCardAdapter adapter; |
| | | ActivityReplacementBinding newcardListBinding; |
| | | List<UserCardBean> userCardBeanList = new ArrayList<>(); |
| | | ReplacementAdapter adapter; |
| | | long beginTime; |
| | | long endTime; |
| | | int page = 0; |
| | | |
| | | //每页数据条数 |
| | | int limit = 30; |
| | | RefreshLayout myRefreshLayout; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | binding = ActivityReplacementBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(binding.getRoot()); |
| | | newcardListBinding = ActivityReplacementBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(newcardListBinding.getRoot()); |
| | | setRightButton(); |
| | | setData(); |
| | | initView(); |
| | | initList(); |
| | | getList(); |
| | | } |
| | | |
| | | private void initView() { |
| | | binding.newCardListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| | | |
| | | public void itemClick(View view) { |
| | | UserCardBean userCardBean = userCardBeanList.get((int) view.getTag()); |
| | | Intent intent = new Intent(ReplacementActivity.this, NFCWreatActivity.class); |
| | | intent.putExtra("dbUserCard", userCardBean); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | private void initList() { |
| | | myRefreshLayout = (RefreshLayout) newcardListBinding.refreshLayout; |
| | | myRefreshLayout.setEnableRefresh(false); |
| | | myRefreshLayout.setRefreshFooter(new ClassicsFooter(this)); |
| | | myRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { |
| | | @Override |
| | | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| | | UserCardBean userCardBean = userCardBeanList.get(position); |
| | | Intent intent = new Intent(ReplacementActivity.this, NFCWreatActivity.class); |
| | | intent.putExtra("dbUserCard", userCardBean); |
| | | startActivity(intent); |
| | | public void onLoadMore(RefreshLayout refreshlayout) { |
| | | page = page + 1; |
| | | getList(); |
| | | } |
| | | }); |
| | | adapter = new ReplacementAdapter(this, userCardBeanList); |
| | | LinearLayoutManager layoutManager = new LinearLayoutManager(this); |
| | | newcardListBinding.recyclerView.setLayoutManager(layoutManager); |
| | | newcardListBinding.recyclerView.setAdapter(adapter); |
| | | } |
| | | |
| | | private void setData() { |
| | | try { |
| | | userCardBeanList = baseDao.userCardDao().findAll(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | adapter = new NewCardAdapter(this, userCardBeanList); |
| | | binding.newCardListView.setAdapter(adapter); |
| | | |
| | | private void getList() { |
| | | // 创建一个 Observable |
| | | Observable<List<UserCardBean>> observable = Observable.create(emitter -> { |
| | | // 在这里执行异步操作 |
| | | List<UserCardBean> beanList; |
| | | if (beginTime == 0 && endTime == 0) { |
| | | beanList = asynchBaseDao.userCardDao().findAll(page * limit, limit); |
| | | } else { |
| | | beanList = asynchBaseDao.userCardDao().findByTime(beginTime, endTime); |
| | | } |
| | | // 将结果发送给观察者 |
| | | emitter.onNext(beanList); |
| | | emitter.onComplete(); |
| | | }); |
| | | // 订阅观察者 |
| | | observable.subscribeOn(Schedulers.io()) // 指定在 IO 线程执行 |
| | | .observeOn(AndroidSchedulers.mainThread()) // 指定在单一线程观察结果 |
| | | .subscribe( |
| | | result -> { |
| | | // 在这里处理结果,这里是在主线程中 |
| | | // System.out.println("Result: " + result); |
| | | if (result.size() < limit) { |
| | | myRefreshLayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | if (result != null && result.size() > 0) { |
| | | userCardBeanList.addAll(result); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | }, |
| | | error -> { |
| | | // 处理错误 |
| | | System.err.println("Error: " + error.getMessage()); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | |
| | | EdtDialog edtDialog; |
| | | |
| | | private void setRightButton() { |
| | | titleBar.setOnItemclickListner(ClickType_RIGHT_TEXT, new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | EdtDialog edtDialog = new EdtDialog(ReplacementActivity.this, new EdtDialog.DialogBack() { |
| | | edtDialog = new EdtDialog(ReplacementActivity.this, new EdtDialog.DialogBack() { |
| | | @Override |
| | | public void onOk(String data) { |
| | | List<UserCardBean> beans = baseDao.userCardDao().findByData(data); |
| | |
| | | } else { |
| | | TipUtil.show("未找到该用户"); |
| | | } |
| | | edtDialog.dismiss(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | |
| | | edtDialog.dismiss(); |
| | | } |
| | | }); |
| | | edtDialog.show(); |
| | | } |
| | | }); |
| | | } |