147 lines
7.4 KiB
Java
147 lines
7.4 KiB
Java
package com.ubt.jimu.diy.view.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.text.Editable;
|
|
import android.text.TextWatcher;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.bumptech.glide.Glide;
|
|
import com.recyclelib.adapter.BaseRecyclerAdapter;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.event.BaseEvent;
|
|
import com.ubt.jimu.diy.model.DiyPartModel;
|
|
import com.ubt.jimu.diy.view.DiyFanActivity;
|
|
import com.ubt.jimu.diy.view.DiyPartListActivity;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import com.ubt.jimu.utils.SPUtils;
|
|
import com.ubt.jimu.widgets.screenAdaptive.XLinearLayout;
|
|
import com.ubtech.utils.StringUtils;
|
|
import java.util.List;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ConnectionAdapter extends BaseRecyclerAdapter<DiyPartModel> {
|
|
private boolean isEnable;
|
|
private boolean isRefresh;
|
|
private ImageView mImvAdd;
|
|
private ImageView mImvPart;
|
|
private ImageView mImvReduce;
|
|
private EditText mTvNum;
|
|
private TextView mTvPartName;
|
|
private XLinearLayout mXlAdd;
|
|
private RecyclerView recyclerView;
|
|
private String type;
|
|
|
|
public ConnectionAdapter(Context context, List<DiyPartModel> list, String str, boolean z, RecyclerView recyclerView) {
|
|
super(context, list);
|
|
this.isRefresh = true;
|
|
this.type = str;
|
|
this.recyclerView = recyclerView;
|
|
this.isEnable = z;
|
|
}
|
|
|
|
@Override // com.recyclelib.adapter.BaseRecyclerAdapter
|
|
public int layoutId() {
|
|
return R.layout.item_part_connection;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onBindViewHolder(BaseRecyclerAdapter.BaseViewHolder baseViewHolder, final int i) {
|
|
final DiyPartModel diyPartModel = (DiyPartModel) this.mList.get(i);
|
|
this.mXlAdd = (XLinearLayout) baseViewHolder.getView(R.id.xl_add);
|
|
this.mImvReduce = (ImageView) baseViewHolder.getView(R.id.imv_reduce);
|
|
this.mTvNum = (EditText) baseViewHolder.getView(R.id.tv_num);
|
|
this.mTvNum.setText(String.valueOf(diyPartModel.getCount()));
|
|
this.mImvAdd = (ImageView) baseViewHolder.getView(R.id.imv_add);
|
|
this.mImvPart = (ImageView) baseViewHolder.getView(R.id.imv_part);
|
|
this.mTvPartName = (TextView) baseViewHolder.getView(R.id.tv_part_name);
|
|
Glide.e(this.mContext).a(diyPartModel.getImageUrl()).a(this.mImvPart);
|
|
baseViewHolder.itemView.setEnabled(this.isEnable);
|
|
this.mTvPartName.setText(diyPartModel.getPartName());
|
|
this.mImvReduce.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.diy.view.adapter.ConnectionAdapter.1
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
if (diyPartModel.getCount() == 0) {
|
|
return;
|
|
}
|
|
diyPartModel.setCount(r4.getCount() - 1);
|
|
if (((BaseRecyclerAdapter) ConnectionAdapter.this).mContext instanceof DiyPartListActivity) {
|
|
DiyPartListActivity diyPartListActivity = (DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext;
|
|
DiyPartListActivity diyPartListActivity2 = (DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext;
|
|
int i2 = diyPartListActivity2.partCount;
|
|
diyPartListActivity2.partCount = i2 - 1;
|
|
diyPartListActivity.notifyPartCount(i2);
|
|
} else {
|
|
EventBus.b().b(new BaseEvent(3, String.valueOf(-1)));
|
|
}
|
|
SPUtils.a(StringUtils.a(DiyFanActivity.uuid, ConnectionAdapter.this.type), ((BaseRecyclerAdapter) ConnectionAdapter.this).mList);
|
|
ConnectionAdapter.this.notifyItemChanged(i);
|
|
}
|
|
});
|
|
this.mImvAdd.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.diy.view.adapter.ConnectionAdapter.2
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
DiyPartModel diyPartModel2 = diyPartModel;
|
|
diyPartModel2.setCount(diyPartModel2.getCount() + 1);
|
|
if (((BaseRecyclerAdapter) ConnectionAdapter.this).mContext instanceof DiyPartListActivity) {
|
|
DiyPartListActivity diyPartListActivity = (DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext;
|
|
DiyPartListActivity diyPartListActivity2 = (DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext;
|
|
int i2 = diyPartListActivity2.partCount;
|
|
diyPartListActivity2.partCount = i2 + 1;
|
|
diyPartListActivity.notifyPartCount(i2);
|
|
} else {
|
|
EventBus.b().b(new BaseEvent(3, String.valueOf(1)));
|
|
}
|
|
SPUtils.a(StringUtils.a(DiyFanActivity.uuid, ConnectionAdapter.this.type), ((BaseRecyclerAdapter) ConnectionAdapter.this).mList);
|
|
ConnectionAdapter.this.notifyItemChanged(i);
|
|
}
|
|
});
|
|
this.mTvNum.addTextChangedListener(new TextWatcher() { // from class: com.ubt.jimu.diy.view.adapter.ConnectionAdapter.3
|
|
private int after;
|
|
private int before;
|
|
|
|
@Override // android.text.TextWatcher
|
|
public void afterTextChanged(Editable editable) {
|
|
if (ConnectionAdapter.this.recyclerView.getScrollState() != 0) {
|
|
return;
|
|
}
|
|
LogUtils.c("CharSequence==" + ((Object) editable));
|
|
if (StringUtils.e(editable.toString())) {
|
|
this.after = 0;
|
|
} else {
|
|
this.after = Integer.parseInt(editable.toString());
|
|
}
|
|
if (Math.abs(this.after - this.before) == 2) {
|
|
return;
|
|
}
|
|
int count = diyPartModel.getCount();
|
|
if (editable == null || editable.toString().equals("")) {
|
|
diyPartModel.setCount(0);
|
|
} else {
|
|
diyPartModel.setCount(Integer.parseInt(editable.toString()));
|
|
}
|
|
if (((BaseRecyclerAdapter) ConnectionAdapter.this).mContext instanceof DiyPartListActivity) {
|
|
((DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext).notifyPartCount(((DiyPartListActivity) ((BaseRecyclerAdapter) ConnectionAdapter.this).mContext).partCount + (diyPartModel.getCount() - count));
|
|
} else {
|
|
EventBus.b().b(new BaseEvent(3, String.valueOf(diyPartModel.getCount() - count)));
|
|
}
|
|
SPUtils.a(StringUtils.a(DiyFanActivity.uuid, ConnectionAdapter.this.type), ((BaseRecyclerAdapter) ConnectionAdapter.this).mList);
|
|
}
|
|
|
|
@Override // android.text.TextWatcher
|
|
public void beforeTextChanged(CharSequence charSequence, int i2, int i3, int i4) {
|
|
if (ConnectionAdapter.this.recyclerView.getScrollState() == 0 && !StringUtils.e(charSequence.toString())) {
|
|
this.before = Integer.parseInt(charSequence.toString());
|
|
}
|
|
}
|
|
|
|
@Override // android.text.TextWatcher
|
|
public void onTextChanged(CharSequence charSequence, int i2, int i3, int i4) {
|
|
}
|
|
});
|
|
}
|
|
}
|