|
|
@@ -0,0 +1,218 @@
|
|
|
+package com.uas.appworks.OA.platform.adapter;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.Editable;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.common.LogUtil;
|
|
|
+import com.common.data.CalendarUtil;
|
|
|
+import com.common.data.DateFormatUtil;
|
|
|
+import com.common.data.ListUtils;
|
|
|
+import com.common.data.StringUtil;
|
|
|
+import com.common.system.DisplayUtil;
|
|
|
+import com.core.utils.time.wheel.DateTimePicker;
|
|
|
+import com.core.widget.listener.EditChangeListener;
|
|
|
+import com.uas.appworks.OA.platform.model.Purchase;
|
|
|
+import com.uas.appworks.R;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Bitlike on 2018/1/16.
|
|
|
+ */
|
|
|
+
|
|
|
+public class PurchaseDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
+ private Context context;
|
|
|
+ private List<Purchase> purchases;
|
|
|
+ private LayoutInflater mInflater;
|
|
|
+ private String status;
|
|
|
+
|
|
|
+ public PurchaseDetailsAdapter(Context context, String status, List<Purchase> purchases) {
|
|
|
+ this.context = context;
|
|
|
+ this.purchases = purchases;
|
|
|
+ this.status = status;
|
|
|
+ mInflater = LayoutInflater.from(context);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemViewType(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
+ return viewType == (getItemCount() - 1) ? new BtnViewHolder(parent) : new ViewHolder(parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return ListUtils.getSize(purchases) + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ class BtnViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ Button replyBtn;
|
|
|
+
|
|
|
+ public BtnViewHolder(ViewGroup viewGroup) {
|
|
|
+ this(mInflater.inflate(R.layout.item_btn, viewGroup, false));
|
|
|
+ }
|
|
|
+
|
|
|
+ public BtnViewHolder(View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ replyBtn = itemView.findViewById(R.id.replyBtn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ TextView captionTV, valueTv;
|
|
|
+ EditText valueEt;
|
|
|
+ View line;
|
|
|
+
|
|
|
+ public ViewHolder(ViewGroup viewGroup) {
|
|
|
+ this(mInflater.inflate(R.layout.item_purchase, viewGroup, false));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ViewHolder(View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ captionTV = itemView.findViewById(R.id.captionTV);
|
|
|
+ valueTv = itemView.findViewById(R.id.valueTv);
|
|
|
+ valueEt = itemView.findViewById(R.id.valueEt);
|
|
|
+ line = itemView.findViewById(R.id.line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
+ if (holder instanceof ViewHolder && position < ListUtils.getSize(purchases)) {
|
|
|
+ onBindViewHolder((ViewHolder) holder, position);
|
|
|
+ } else if (holder instanceof BtnViewHolder) {
|
|
|
+ onBindViewHolder((BtnViewHolder) holder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onBindViewHolder(BtnViewHolder holder) {
|
|
|
+ boolean canReply = (status != null && !status.equals("已结案"));
|
|
|
+ holder.replyBtn.setFocusable(canReply);
|
|
|
+ holder.replyBtn.setClickable(canReply);
|
|
|
+ holder.replyBtn.setPressed(!canReply);
|
|
|
+ int padd = DisplayUtil.dip2px(context, 10);
|
|
|
+ if (canReply) {
|
|
|
+ holder.replyBtn.setBackgroundResource(R.drawable.bg_bule_btn);
|
|
|
+ holder.replyBtn.setOnClickListener(onClickListener);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ holder.replyBtn.setBackgroundResource(R.drawable.bg_orange_btn_pass);
|
|
|
+ }
|
|
|
+ holder.replyBtn.setPadding(padd, padd, padd, padd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
+ Purchase purchase = purchases.get(position);
|
|
|
+ holder.captionTV.setText(purchase.getCaption());
|
|
|
+
|
|
|
+ if (purchase.isNeedInput()) {
|
|
|
+ holder.valueEt.setBackgroundResource(R.drawable.edit_hint_right_angle);
|
|
|
+ holder.valueEt.setClickable(true);
|
|
|
+ if (purchase.getType().equals("date")) {
|
|
|
+ holder.valueTv.setText(purchase.getValues());
|
|
|
+ holder.valueTv.setBackgroundResource(R.drawable.edit_hint_right_angle);
|
|
|
+ holder.valueEt.setVisibility(View.GONE);
|
|
|
+ holder.valueTv.setVisibility(View.VISIBLE);
|
|
|
+ holder.valueTv.setTag(position);
|
|
|
+ holder.valueTv.setOnClickListener(onClickListener);
|
|
|
+ } else {
|
|
|
+ holder.valueEt.setText(purchase.getValues());
|
|
|
+ holder.valueTv.setVisibility(View.GONE);
|
|
|
+ holder.valueEt.setVisibility(View.VISIBLE);
|
|
|
+ holder.valueEt.setFocusable(true);
|
|
|
+ holder.valueEt.addTextChangedListener(new TextChangListener(holder, position));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ holder.valueTv.setText(StringUtil.isEmpty(purchase.getValues()) ? "无" : purchase.getValues());
|
|
|
+ holder.valueTv.setBackgroundDrawable(null);
|
|
|
+ holder.valueEt.setVisibility(View.GONE);
|
|
|
+ holder.valueTv.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ holder.line.setVisibility((position > 0 && purchases.get(position - 1).getId() != purchase.getId()) ? View.VISIBLE : View.GONE);
|
|
|
+// holder.line.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private View.OnClickListener onClickListener = new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.valueTv && v.getTag() != null && v.getTag() instanceof Integer) {
|
|
|
+ int position = (int) v.getTag();
|
|
|
+ showDateSelect(position);
|
|
|
+ } else if (v.getId() == R.id.replyBtn) {
|
|
|
+ if (onReplyLisenter != null) {
|
|
|
+ onReplyLisenter.reply(purchases);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void showDateSelect(final int position) {
|
|
|
+ DateTimePicker picker = new DateTimePicker((Activity) context, DateTimePicker.YEAR_MONTH_DAY);
|
|
|
+ picker.setRange(2000, 2030);
|
|
|
+ int year, month, day;
|
|
|
+ Date time = null;
|
|
|
+ if (ListUtils.getSize(purchases) > position && !StringUtil.isEmpty(purchases.get(position).getValues())) {
|
|
|
+ time = DateFormatUtil.str2date(purchases.get(position).getValues(), DateFormatUtil.YMD);
|
|
|
+ }
|
|
|
+ year = CalendarUtil.getYear(time);
|
|
|
+ month = CalendarUtil.getMonth(time);
|
|
|
+ day = CalendarUtil.getDay(time);
|
|
|
+ picker.setSelectedItem(year, month, day);
|
|
|
+ picker.setOnDateTimePickListener(new DateTimePicker.OnYearMonthDayTimePickListener() {
|
|
|
+ @Override
|
|
|
+ public void onDateTimePicked(String year, String month, String day, String hour, String minute) {
|
|
|
+ if (ListUtils.getSize(purchases) > position) {
|
|
|
+ purchases.get(position).setValues(year + "-" + month + "-" + day);
|
|
|
+ notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ picker.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private class TextChangListener extends EditChangeListener {
|
|
|
+ ViewHolder hodler;
|
|
|
+ private int position;
|
|
|
+
|
|
|
+ public TextChangListener(ViewHolder hodler, int position) {
|
|
|
+ this.hodler = hodler;
|
|
|
+ this.position = position;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+ if (this.position >= 0 && ListUtils.getSize(purchases) > this.position) {
|
|
|
+ if (this.hodler.valueEt != null && this.hodler.valueEt.getVisibility() == View.VISIBLE) {
|
|
|
+ LogUtil.i("s=" + s.toString());
|
|
|
+ LogUtil.i("position=" + this.position);
|
|
|
+ purchases.get(this.position).setValues(s == null ? "" : s.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private OnReplyLisenter onReplyLisenter;
|
|
|
+
|
|
|
+ public void setOnReplyLisenter(OnReplyLisenter onReplyLisenter) {
|
|
|
+ this.onReplyLisenter = onReplyLisenter;
|
|
|
+ }
|
|
|
+
|
|
|
+ public interface OnReplyLisenter {
|
|
|
+ void reply(List<Purchase> purchases);
|
|
|
+ }
|
|
|
+}
|