| | |
| | | package com.application.zhangshi_app_android.adapter; |
| | | |
| | | import android.content.Context; |
| | | import android.text.Editable; |
| | | import android.text.TextWatcher; |
| | | import android.view.View; |
| | | |
| | | import androidx.lifecycle.LifecycleOwner; |
| | | import androidx.lifecycle.Observer; |
| | | |
| | | import com.android.app_base.base.adapter.BaseRVAdapter; |
| | | import com.android.app_base.base.dialog.BaseDialog; |
| | | import com.android.app_base.base.dialog.UIDialog; |
| | | import com.android.app_base.utils.rxbus.MessageEvent; |
| | | import com.android.app_base.utils.rxbus.RxBus; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.ConsumeRecordBean; |
| | | import com.application.zhangshi_app_android.databinding.ItemConsumeRecordBinding; |
| | | import com.application.zhangshi_app_android.ui.function.TourismDetailActivityViewModel; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author Ljj |
| | |
| | | * @desc 消费记录适配器 |
| | | */ |
| | | public class ConsumeRecordRvAdapter extends BaseRVAdapter<ConsumeRecordBean, ItemConsumeRecordBinding,BaseRVAdapter.BaseViewHolder<ItemConsumeRecordBinding>> { |
| | | public ConsumeRecordRvAdapter(Context context) { |
| | | private TourismDetailActivityViewModel viewModel; |
| | | |
| | | public ConsumeRecordRvAdapter(Context context,TourismDetailActivityViewModel viewModel) { |
| | | super(context); |
| | | this.viewModel = viewModel; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | protected void onBind(BaseViewHolder<ItemConsumeRecordBinding> holder, int position) { |
| | | ConsumeRecordBean item = getItem(position); |
| | | holder.getBinding().setLifecycleOwner((LifecycleOwner) mContext); |
| | | holder.getBinding().setBean(getItem(position)); |
| | | holder.getBinding().setViewModel(viewModel); |
| | | holder.getBinding().ivDelete.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | new UIDialog.Builder(mContext) |
| | | .setTitle("您确定要删除该条消费记录吗") |
| | | .setContent("删除后将无法恢复") |
| | | .setConfirm("确定") |
| | | .setCancel("取消") |
| | | .setListener(new UIDialog.OnListener() { |
| | | @Override |
| | | public void onConfirm(BaseDialog dialog) { |
| | | removeItem(position); |
| | | RxBus.getInstance().post(new MessageEvent(MessageEvent.EVENT_TOURISM_CONSUME_CHANGE)); |
| | | } |
| | | }) |
| | | .show(); |
| | | } |
| | | }); |
| | | TextWatcher textWatcher = new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | BigDecimal decimal = BigDecimal.valueOf(item.getEat()+item.getStay()+item.getShopping()+item.getTraffic()+item.getEntrance()); |
| | | holder.getBinding().etTotalCost.setText(decimal.stripTrailingZeros().toPlainString()); |
| | | RxBus.getInstance().post(new MessageEvent(MessageEvent.EVENT_TOURISM_CONSUME_CHANGE)); |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | |
| | | } |
| | | }; |
| | | holder.getBinding().etEat.addTextChangedListener(textWatcher); |
| | | holder.getBinding().etStay.addTextChangedListener(textWatcher); |
| | | holder.getBinding().etShopping.addTextChangedListener(textWatcher); |
| | | holder.getBinding().etTraffic.addTextChangedListener(textWatcher); |
| | | holder.getBinding().etEntrance.addTextChangedListener(textWatcher); |
| | | } |
| | | |
| | | @Override |