Commit cde784ad authored by david's avatar david Committed by 杨秀秀

增加积分选择年的功能

parent bcbecad3
......@@ -24,7 +24,7 @@ public class CreditAdapter extends xxBaseRecyclerViewAdapter<ItemCreditBinding,
protected void covert(ItemCreditBinding dataBind, CreditRecordBean data, int position) {
// 将接口调出来的布局遍历上去
dataBind.setCreditRecordBean(data);
dataBind.tvDate.setText(data.getCreateTime());
dataBind.tvDate.setText(data.getVariableTime());
dataBind.tvCreditNum.setText(String.valueOf(data.getIntegralVariation()));
if ("1".equals(data.getIntegralType())) {
......
package com.xx.hbhconsumer.adapter;
import android.content.Context;
import android.view.View;
import com.xx.hbhconsumer.R;
import com.xx.hbhconsumer.data.http.respons.YearBean;
import com.xx.hbhconsumer.databinding.ItemYearBinding;
import com.xx.xxviewlibrary.base.xxBaseRecyclerViewAdapter;
public class YearAdapter extends xxBaseRecyclerViewAdapter<ItemYearBinding, YearBean> {
public YearAdapter(Context context) {
super(context);
mContext = context;
}
@Override
public int initLayout() {
return R.layout.item_year;
}
@Override
protected void covert(ItemYearBinding dataBind, YearBean data, int position) {
dataBind.tvYear.setText(data.getYear() + "年");
if (data.getChecked()) {
dataBind.ivCheckedIcon.setVisibility(View.VISIBLE);
dataBind.tvYear.setTextColor(mContext.getColor(R.color.text_foreground));
} else {
dataBind.ivCheckedIcon.setVisibility(View.GONE);
dataBind.tvYear.setTextColor(mContext.getColor(R.color.price_black));
}
}
}
......@@ -331,7 +331,7 @@ interface ApiService {
@Headers("Content-type:application/json")
@POST("app/myPoint/IntegralScheduleList")
fun getCreditRecordList(@Body requestBody: RequestBody): Observable<BasePageResponse<CreditRecordBean>>
fun getCreditRecordList(@Body requestBody: RequestBody, @Query("pageNum") num: Int): Observable<BasePageResponse<CreditRecordBean>>
@Headers("Content-type:application/json")
@GET("app/myPoint/getMyPoint")
......
......@@ -59,22 +59,20 @@ public class CreditRequest extends BaseRespons {
/**
* 低价好物商品列表
*/
public Observable<BasePageResponse<CreditRecordBean>> getCreditRecordList(String incomeType, String beginTime, String endTime) {
public Observable<BasePageResponse<CreditRecordBean>> getCreditRecordList(String incomeType, String beginTime, Integer pageNum) {
ApiParams<GetCreditRecordListRequestBody> apiParams = new ApiParams<>();
GetCreditRecordListRequestBody requestBody = new GetCreditRecordListRequestBody(incomeType,beginTime, endTime);
GetCreditRecordListRequestBody requestBody = new GetCreditRecordListRequestBody(incomeType, beginTime);
RequestBody body=apiParams.setParams(requestBody);
return getApiService().getCreditRecordList(body);
return getApiService().getCreditRecordList(body, pageNum);
}
public class GetCreditRecordListRequestBody {
public String incomeType;
public String beginTime;
public String endTime;
public GetCreditRecordListRequestBody(String incomeType, String beginTime, String endTime) {
public GetCreditRecordListRequestBody(String incomeType, String beginTime) {
this.incomeType = incomeType;
this.beginTime = beginTime;
this.endTime = endTime;
}
}
public class CreditExchangeRequestBody {
......
package com.xx.hbhconsumer.data.http.respons;
public class YearBean {
private Integer year;
private Boolean checked;
public Integer getYear() {
return year;
}
public void setYear(Integer year) {
this.year = year;
}
public Boolean getChecked() {
return checked;
}
public void setChecked(Boolean checked) {
this.checked = checked;
}
}
package com.xx.hbhconsumer.ui.credit;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import com.google.android.material.tabs.TabLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.xx.hbhconsumer.R;
import com.xx.hbhconsumer.adapter.CreditAdapter;
import com.xx.hbhconsumer.adapter.YearAdapter;
import com.xx.hbhconsumer.data.http.requst.CreditRequest;
import com.xx.hbhconsumer.databinding.ActivityCreditDetailBinding;
import me.goldze.mvvmhabit.base.BaseActivity;
import me.tatarka.bindingcollectionadapter2.BR;
public class CreditDetailActivity extends BaseActivity<ActivityCreditDetailBinding, CreditDetailViewModel> {
public class CreditDetailActivity extends BaseActivity<ActivityCreditDetailBinding, CreditDetailViewModel> implements OnRefreshListener, OnLoadMoreListener {
@Override
public void initData() {
......@@ -23,10 +30,14 @@ public class CreditDetailActivity extends BaseActivity<ActivityCreditDetailBindi
public void onTabSelected(TabLayout.Tab tab) {
switch (tab.getPosition()) {
case 0:
viewModel.loadCreditRecordList("1", "2022", "2024");
viewModel.page = 1;
viewModel.incomeType = "1";
viewModel.loadCreditRecordList();
break;
case 1:
viewModel.loadCreditRecordList("2", "2022", "2024");
viewModel.page = 1;
viewModel.incomeType = "2";
viewModel.loadCreditRecordList();
break;
}
}
......@@ -50,6 +61,24 @@ public class CreditDetailActivity extends BaseActivity<ActivityCreditDetailBindi
viewModel.credit.observe(this, credit -> {
binding.tvCreditNum.setText(String.valueOf(credit));
});
viewModel.checkYearFlag.observe(this, checkYearFlag -> {
if (checkYearFlag) {
binding.rlCheckYear.setVisibility(View.VISIBLE);
} else {
binding.rlCheckYear.setVisibility(View.GONE);
}
});
YearAdapter yearAdapter = new YearAdapter(this);
binding.rvYearList.setAdapter(yearAdapter);
yearAdapter.setOnItemClick((position, data) -> {
viewModel.checkYear(data);
});
viewModel.yearBeanList.observe(this, yearBeanList -> {
yearAdapter.mList = yearBeanList;
yearAdapter.notifyDataSetChanged();
});
}
@Override
......@@ -67,4 +96,17 @@ public class CreditDetailActivity extends BaseActivity<ActivityCreditDetailBindi
CreditRequest lm = new CreditRequest();
return new CreditDetailViewModel(getApplication(), lm);
}
@Override
public void onLoadMore(RefreshLayout refreshLayout) {
viewModel.page=1;
viewModel.loadCreditRecordList();
binding.refresh.setEnableLoadMore(true);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
viewModel.page++;
viewModel.loadCreditRecordList();
}
}
......@@ -8,19 +8,29 @@ import androidx.lifecycle.MutableLiveData;
import com.xx.hbhconsumer.data.http.requst.CreditRequest;
import com.xx.hbhconsumer.data.http.respons.CreditDetailBean;
import com.xx.hbhconsumer.data.http.respons.CreditRecordBean;
import com.xx.hbhconsumer.data.http.respons.YearBean;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.http.ApiDisposablePageObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
public int page = 1;
public int selectYear = 0;
public String incomeType = "1";
public MutableLiveData<Boolean> checkYearFlag = new MutableLiveData<>(false);
public MutableLiveData<List<YearBean>> yearBeanList = new MutableLiveData<>(new ArrayList<>());
public MutableLiveData<List<CreditRecordBean>> creditRecordBeanList = new MutableLiveData<>(new ArrayList<>());
public MutableLiveData<Integer> credit = new MutableLiveData<>(0);
......@@ -35,6 +45,8 @@ public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
@Override
public void onCreate() {
super.onCreate();
Calendar calendar = Calendar.getInstance();
selectYear = calendar.get(Calendar.YEAR);
}
@Override
......@@ -46,7 +58,7 @@ public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
public void onResume() {
super.onResume();
getMyPoint();
loadCreditRecordList("1", "2022", "2024");
loadCreditRecordList();
}
public void getMyPoint() {
......@@ -71,8 +83,8 @@ public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
});
}
public void loadCreditRecordList(String incomeType, String beginTime, String endTime) {
model.getCreditRecordList(incomeType, beginTime, endTime)
public void loadCreditRecordList() {
model.getCreditRecordList(incomeType, String.valueOf(selectYear), page)
.compose(RxUtils.schedulersTransformer()) //线程调度
.doOnSubscribe(CreditDetailViewModel.this)
.doOnSubscribe(new Consumer<Disposable>() {
......@@ -82,7 +94,13 @@ public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
}).subscribe(new ApiDisposablePageObserver<CreditRecordBean>() {
@Override
public void onSuccess(List<CreditRecordBean> resultBean) {
creditRecordBeanList.postValue(resultBean);
if (page == 1) {
creditRecordBeanList.postValue(resultBean);
} else {
List<CreditRecordBean> list = creditRecordBeanList.getValue();
list.addAll(resultBean);
creditRecordBeanList.postValue(list);
}
}
@Override
......@@ -97,4 +115,53 @@ public class CreditDetailViewModel extends BaseViewModel<CreditRequest> {
});
}
public void checkYear(YearBean data) {
List<YearBean> list = new ArrayList<>();
for (YearBean yearBean : yearBeanList.getValue()) {
if (data.getYear().equals(yearBean.getYear())) {
yearBean.setChecked(true);
selectYear = yearBean.getYear();
} else {
yearBean.setChecked(false);
}
list.add(yearBean);
}
yearBeanList.postValue(list);
checkYearFlag.postValue(false);
loadCreditRecordList();
}
public BindingCommand checkYear = new BindingCommand(new BindingAction() {
@Override
public void call() {
checkYearFlag.postValue(true);
yearBeanList.postValue(initYearList());
}
});
private List<YearBean> initYearList() {
List<YearBean> list = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Integer startYear = calendar.get(Calendar.YEAR);
for (int i = 0; i < 5; i++) {
YearBean yearBean = new YearBean();
yearBean.setYear(startYear - i);
if (selectYear == yearBean.getYear()) {
yearBean.setChecked(true);
} else {
yearBean.setChecked(false);
}
list.add(yearBean);
}
Collections.reverse(list);
return list;
}
public BindingCommand closeCheckYear = new BindingCommand(new BindingAction() {
@Override
public void call() {
checkYearFlag.postValue(false);
}
});
}
......@@ -53,7 +53,7 @@ public class MyCreditViewModel extends BaseViewModel<CreditRequest> {
}
private void loadCreditRecordList() {
model.getCreditRecordList(null, null, null)
model.getCreditRecordList(null, "2023", 1)
.compose(RxUtils.schedulersTransformer()) //线程调度
.doOnSubscribe(MyCreditViewModel.this)
.doOnSubscribe(new Consumer<Disposable>() {
......
......@@ -20,18 +20,44 @@
android:background="@color/white"
android:fitsSystemWindows="true">
<com.xx.xxviewlibrary.witget.XxBar
android:id="@+id/bar"
on_click="@{creditDetailViewModel.clickFinish}"
bar_title="@{@string/navigation_sea}"
<RelativeLayout
android:id="@+id/rl_bar"
android:layout_width="match_parent"
android:layout_height="55dp" />
android:layout_height="wrap_content">
<com.xx.xxviewlibrary.witget.XxBar
android:id="@+id/bar"
bar_title="@{@string/credit_detail}"
on_click="@{creditDetailViewModel.clickFinish}"
android:layout_width="match_parent"
android:layout_height="55dp" />
<ImageView
android:id="@+id/iv_calendar_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="17dp"
android:src="@mipmap/jifenzhangdan_icon_rili" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:layout_toLeftOf="@id/iv_calendar_icon"
android:text="2023年"
android:textColor="#FF333333"
android:textSize="16sp"
binding:onClickCommand="@{creditDetailViewModel.checkYear}" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_grey"
android:layout_below="@id/bar">
android:layout_below="@id/rl_bar"
android:background="@color/bg_grey">
<RelativeLayout
android:layout_width="match_parent"
......@@ -41,11 +67,11 @@
android:id="@+id/rl_credit_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#5971A4"
android:gravity="bottom|center_horizontal"
android:orientation="horizontal"
android:paddingTop="41dp"
android:paddingBottom="41dp"
android:background="#5971A4">
android:paddingBottom="41dp">
<TextView
......@@ -54,9 +80,10 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="1600"
android:textSize="30sp"
android:textColor="#FFFFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_credit_label"
android:layout_width="wrap_content"
......@@ -64,8 +91,8 @@
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:text="积分"
android:textSize="13sp"
android:textColor="#FFFFFFFF" />
android:textColor="#FFFFFFFF"
android:textSize="13sp" />
</LinearLayout>
......@@ -73,43 +100,102 @@
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/rl_credit_num"
android:background="@color/bg_grey"
app:tabBackground="@null"
app:tabGravity="fill"
app:tabIndicatorColor="#5971A4"
app:tabIndicatorHeight="2dp"
app:tabIndicatorFullWidth="false"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorHeight="2dp"
app:tabMaxWidth="0dp"
app:tabSelectedTextColor="#5971A4"
android:layout_below="@id/rl_credit_num"
app:tabTextColor="@color/black"
app:tabBackground="@null"
app:tabMode="fixed"
app:tabPaddingBottom="4dp"
app:tabRippleColor="@null"
app:tabPaddingBottom="4dp">
app:tabSelectedTextColor="#5971A4"
app:tabTextColor="@color/black">
<com.google.android.material.tabs.TabItem
android:id="@+id/tab_credit_income"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:text="积分收入"
android:id="@+id/tab_credit_income"/>
android:text="积分收入" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tab_credit_expenses"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:text="积分支出"
android:id="@+id/tab_credit_expenses"/>
android:text="积分支出" />
</com.google.android.material.tabs.TabLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_credit_record_list"
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="17dp"
android:layout_marginRight="17dp"
android:layout_marginTop="19dp"
android:background="@drawable/bg_white_radius_12"
android:layout_below="@id/tabLayout"
binding:layoutManager="@{LayoutManagers.linear(1,false)}"/>
android:background="@color/bg_grey">
<com.scwang.smart.refresh.header.BezierRadarHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_credit_record_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="17dp"
android:layout_marginTop="19dp"
android:layout_marginRight="17dp"
android:background="@drawable/bg_white_radius_12"
binding:layoutManager="@{LayoutManagers.linear(1,false)}" />
<!--暂无数据-->
<LinearLayout
android:id="@+id/ll_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="120dp"
android:layout_height="129dp"
android:src="@mipmap/zhanwei_img_wushuju" />
</LinearLayout>
</LinearLayout>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:id="@+id/rl_check_year"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/rl_bar"
android:background="#4D000000">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_year_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
binding:layoutManager="@{LayoutManagers.linear(1,false)}" />
<TextView
android:id="@+id/tv_black_area"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/rv_year_list"
binding:onClickCommand="@{creditDetailViewModel.closeCheckYear}" />
</RelativeLayout>
</RelativeLayout>
</layout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/rl_bg"
android:layout_width="match_parent"
android:layout_height="43dp"
android:background="@color/white">
<TextView
android:id="@+id/tv_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="21dp"
android:text="2021年"
android:textSize="16sp"
android:textColor="#FF333333"/>
<ImageView
android:id="@+id/iv_checked_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="17dp"
android:src="@mipmap/sousuo_icon_duigou"/>
</RelativeLayout>
</layout>
\ No newline at end of file
......@@ -13,6 +13,7 @@
<string name="navigation_home">首页</string>
<string name="news_detail">咨询详情</string>
<string name="recruit_detail">招聘详情</string>
<string name="credit_detail">积分明细</string>
<!--环渤海-->
<string name="navigation_sea">环渤海</string>
<string name="navigation_shop">店铺</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment