New file |
| | |
| | | package com.dayu.qihealonelibrary.activity; |
| | | |
| | | |
| | | import static com.dayu.baselibrary.view.TitleBar.ClickType_RIGHT_TEXT; |
| | | |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | |
| | | import com.dayu.baselibrary.utils.ArithUtil; |
| | | import com.dayu.baselibrary.utils.TipUtil; |
| | | import com.dayu.baselibrary.view.datepicker.CustomDatePicker; |
| | | import com.dayu.baselibrary.view.datepicker.DateFormatUtils; |
| | | import com.dayu.qihealonelibrary.adapter.RechargeAdapter; |
| | | import com.dayu.qihealonelibrary.databinding.ActivityRechargeListQhaBinding; |
| | | import com.dayu.qihealonelibrary.dbBean.RechargeBean; |
| | | 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; |
| | | |
| | | /** |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | | * Date: 2023-11-5 09:52 |
| | | * Description: 充值记录 |
| | | */ |
| | | public class RechargeListActivityQHAlone extends QHAloneBaseActivity { |
| | | |
| | | ActivityRechargeListQhaBinding rechargeListBinding; |
| | | RechargeAdapter adapter; |
| | | List<RechargeBean> rechargeList = new ArrayList<>(); |
| | | |
| | | private CustomDatePicker beginDatePicker; |
| | | private CustomDatePicker endDatePicker; |
| | | long beginTime; |
| | | long endTime; |
| | | |
| | | int page = 0; |
| | | |
| | | //每页数据条数 |
| | | int limit = 30; |
| | | RefreshLayout myRefreshLayout; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | rechargeListBinding = ActivityRechargeListQhaBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(rechargeListBinding.getRoot()); |
| | | setRightButton(); |
| | | initDatePicker(); |
| | | initList(); |
| | | getList(); |
| | | } |
| | | |
| | | private void initList() { |
| | | myRefreshLayout = (RefreshLayout) rechargeListBinding.refreshLayout; |
| | | myRefreshLayout.setEnableRefresh(false); |
| | | myRefreshLayout.setRefreshFooter(new ClassicsFooter(this)); |
| | | myRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { |
| | | @Override |
| | | public void onLoadMore(RefreshLayout refreshlayout) { |
| | | page = page + 1; |
| | | getList(); |
| | | } |
| | | }); |
| | | adapter = new RechargeAdapter(this, rechargeList); |
| | | LinearLayoutManager layoutManager = new LinearLayoutManager(this); |
| | | rechargeListBinding.recyclerView.setLayoutManager(layoutManager); |
| | | rechargeListBinding.recyclerView.setAdapter(adapter); |
| | | } |
| | | |
| | | private void getTotal() { |
| | | if (rechargeList != null) { |
| | | double total = 0; |
| | | for (int i = 0; i < rechargeList.size(); i++) { |
| | | double b = Double.parseDouble(rechargeList.get(i).getMorny()); |
| | | total = ArithUtil.add(total, b); |
| | | } |
| | | rechargeListBinding.rechargeTotal.setText("已加载数据累计充值:" + String.valueOf(total) + "元"); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void getList() { |
| | | // 创建一个 Observable |
| | | Observable<List<RechargeBean>> observable = Observable.create(emitter -> { |
| | | // 在这里执行异步操作 |
| | | List<RechargeBean> beanList; |
| | | if (beginTime == 0 && endTime == 0) { |
| | | beanList = asynchBaseDao.rechargeDao().findAll(page * limit, limit); |
| | | } else { |
| | | beanList = asynchBaseDao.rechargeDao().ansyFindByTime(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) { |
| | | rechargeList.addAll(result); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | getTotal(); |
| | | }, |
| | | error -> { |
| | | // 处理错误 |
| | | System.err.println("Error: " + error.getMessage()); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | |
| | | private void setRightButton() { |
| | | titleBar.setOnItemclickListner(ClickType_RIGHT_TEXT, new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | beginDatePicker.show(System.currentTimeMillis()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initDatePicker() { |
| | | long beginTimestamp = DateFormatUtils.str2Long("2009-05-01", false); |
| | | final long endTimestamp = System.currentTimeMillis(); |
| | | |
| | | // 通过时间戳初始化日期,毫秒级别 |
| | | beginDatePicker = new CustomDatePicker(this, "选择开始时间", new CustomDatePicker.Callback() { |
| | | @Override |
| | | public void onTimeSelected(long timestamp) { |
| | | beginTime = timestamp; |
| | | endDatePicker.show(timestamp); |
| | | } |
| | | }, beginTimestamp, endTimestamp); |
| | | // 不允许点击屏幕或物理返回键关闭 |
| | | beginDatePicker.setCancelable(false); |
| | | // 不显示时和分 |
| | | beginDatePicker.setCanShowPreciseTime(false); |
| | | // 不允许循环滚动 |
| | | beginDatePicker.setScrollLoop(false); |
| | | // 不允许滚动动画 |
| | | beginDatePicker.setCanShowAnim(false); |
| | | |
| | | endDatePicker = new CustomDatePicker(this, "选择结束时间", new CustomDatePicker.Callback() { |
| | | @Override |
| | | public void onTimeSelected(long timestamp) { |
| | | endTime = timestamp; |
| | | if ((endTime < beginTime) && endTime != beginTime) { |
| | | TipUtil.show(RechargeListActivityQHAlone.this, "结束时间不能晚于开始时间"); |
| | | } else { |
| | | endTime = endTime + (1000 * 60 * 60 * 24) - 1; |
| | | rechargeList.clear(); |
| | | getList(); |
| | | } |
| | | } |
| | | }, beginTimestamp, endTimestamp); |
| | | // 不允许点击屏幕或物理返回键关闭 |
| | | endDatePicker.setCancelable(false); |
| | | // 不显示时和分 |
| | | endDatePicker.setCanShowPreciseTime(false); |
| | | // 不允许循环滚动 |
| | | endDatePicker.setScrollLoop(false); |
| | | // 不允许滚动动画 |
| | | endDatePicker.setCanShowAnim(false); |
| | | } |
| | | |
| | | |
| | | } |