|
|
@@ -14,6 +14,7 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.yunbao.common.Constants;
|
|
|
import com.yunbao.video.R;
|
|
|
+import com.yunbao.video.activity.VideoReportDescriptionActivity;
|
|
|
import com.yunbao.video.bean.VideoReportBean;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -24,10 +25,10 @@ import java.util.List;
|
|
|
|
|
|
public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
|
|
|
- private static final int HEAD = -1;
|
|
|
- private static final int FOOT = -2;
|
|
|
- private static final int NORMAL = 0;
|
|
|
- private static final int NORMAL_LAST = 1;
|
|
|
+// private static final int HEAD = -1;
|
|
|
+// private static final int FOOT = -2;
|
|
|
+// private static final int NORMAL = 0;
|
|
|
+// private static final int NORMAL_LAST = 1;
|
|
|
|
|
|
private List<VideoReportBean> mList;
|
|
|
private LayoutInflater mInflater;
|
|
|
@@ -35,7 +36,7 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
private int mCheckedPosition;
|
|
|
private View.OnClickListener mOnClickListener;
|
|
|
private View.OnClickListener mReportListener;
|
|
|
- private FootVh mFootVh;
|
|
|
+// private FootVh mFootVh;
|
|
|
private ActionListener mActionListener;
|
|
|
private VideoReportBean mCurVideoReportBean;
|
|
|
|
|
|
@@ -43,7 +44,7 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
mList = list;
|
|
|
mInflater = LayoutInflater.from(context);
|
|
|
mCheckedDrawable = ContextCompat.getDrawable(context, R.mipmap.icon_video_checked);
|
|
|
- mCheckedPosition = 1;
|
|
|
+ mCheckedPosition = 0;
|
|
|
mCurVideoReportBean = mList.get(0);
|
|
|
mOnClickListener = new View.OnClickListener() {
|
|
|
@Override
|
|
|
@@ -73,65 +74,70 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
return;
|
|
|
}
|
|
|
if (mCheckedPosition >= 0) {
|
|
|
- mList.get(mCheckedPosition - 1).setChecked(false);
|
|
|
+ mList.get(mCheckedPosition).setChecked(false);
|
|
|
notifyItemChanged(mCheckedPosition, Constants.PAYLOAD);
|
|
|
}
|
|
|
- VideoReportBean bean = mList.get(position - 1);
|
|
|
+ VideoReportBean bean = mList.get(position);
|
|
|
bean.setChecked(true);
|
|
|
notifyItemChanged(position, Constants.PAYLOAD);
|
|
|
mCheckedPosition = position;
|
|
|
mCurVideoReportBean = bean;
|
|
|
- if (bean.getId() == -1) {
|
|
|
- if (mFootVh != null) {
|
|
|
- mFootVh.showEdit(true);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (mFootVh != null) {
|
|
|
- mFootVh.showEdit(false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- mReportListener = new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (mFootVh != null) {
|
|
|
- mFootVh.submit();
|
|
|
+ if (mActionListener != null) {
|
|
|
+ mActionListener.onSelectionChanged(bean);
|
|
|
}
|
|
|
+// if (bean.getId() == -1) {
|
|
|
+// if (mFootVh != null) {
|
|
|
+// mFootVh.showEdit(true);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (mFootVh != null) {
|
|
|
+// mFootVh.showEdit(false);
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
};
|
|
|
+// mReportListener = new View.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(View v) {
|
|
|
+// if (mFootVh != null) {
|
|
|
+// mFootVh.submit();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// };
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int getItemViewType(int position) {
|
|
|
- if (position == 0) {
|
|
|
- return HEAD;
|
|
|
- } else if (position == mList.size() + 1) {
|
|
|
- return FOOT;
|
|
|
- } else {
|
|
|
- if (position == mList.size()) {
|
|
|
- return NORMAL_LAST;
|
|
|
- }
|
|
|
- return NORMAL;
|
|
|
- }
|
|
|
- }
|
|
|
+// @Override
|
|
|
+// public int getItemViewType(int position) {
|
|
|
+// if (position == 0) {
|
|
|
+// return HEAD;
|
|
|
+// } else if (position == mList.size() + 1) {
|
|
|
+// return FOOT;
|
|
|
+// } else {
|
|
|
+// if (position == mList.size()) {
|
|
|
+// return NORMAL_LAST;
|
|
|
+// }
|
|
|
+// return NORMAL;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
- if (viewType == HEAD) {
|
|
|
- return new HeadVh(mInflater.inflate(R.layout.item_video_report_head, parent, false));
|
|
|
- } else if (viewType == FOOT) {
|
|
|
- if (mFootVh == null) {
|
|
|
- mFootVh = new FootVh(mInflater.inflate(R.layout.item_video_report_foot, parent, false));
|
|
|
- }
|
|
|
- return mFootVh;
|
|
|
- } else {
|
|
|
- if (viewType == NORMAL_LAST) {
|
|
|
- return new Vh(mInflater.inflate(R.layout.item_video_report_2, parent, false));
|
|
|
- }
|
|
|
- return new Vh(mInflater.inflate(R.layout.item_video_report, parent, false));
|
|
|
- }
|
|
|
+// if (viewType == HEAD) {
|
|
|
+// return new HeadVh(mInflater.inflate(R.layout.item_video_report_head, parent, false));
|
|
|
+// } else if (viewType == FOOT) {
|
|
|
+// if (mFootVh == null) {
|
|
|
+// mFootVh = new FootVh(mInflater.inflate(R.layout.item_video_report_foot, parent, false));
|
|
|
+// }
|
|
|
+// return mFootVh;
|
|
|
+// } else {
|
|
|
+// if (viewType == NORMAL_LAST) {
|
|
|
+// return new Vh(mInflater.inflate(R.layout.item_video_report_2, parent, false));
|
|
|
+// }
|
|
|
+// return new Vh(mInflater.inflate(R.layout.item_video_report, parent, false));
|
|
|
+
|
|
|
+// }
|
|
|
+ return new Vh(mInflater.inflate(R.layout.item_video_report_new, parent, false));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -143,70 +149,73 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder vh, int position, @NonNull List payloads) {
|
|
|
Object payload = payloads.size() > 0 ? payloads.get(0) : null;
|
|
|
if (vh instanceof Vh) {
|
|
|
- ((Vh) vh).setData(mList.get(position - 1), position, payload);
|
|
|
+ // 修复:直接使用position,不再减1
|
|
|
+ ((Vh) vh).setData(mList.get(position), position, payload);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getItemCount() {
|
|
|
- return mList.size() + 2;
|
|
|
- }
|
|
|
-
|
|
|
- class HeadVh extends RecyclerView.ViewHolder {
|
|
|
-
|
|
|
- public HeadVh(View itemView) {
|
|
|
- super(itemView);
|
|
|
- }
|
|
|
+ // 修复:直接返回mList的大小,不再加2
|
|
|
+ return mList.size();
|
|
|
}
|
|
|
|
|
|
- class FootVh extends RecyclerView.ViewHolder {
|
|
|
-
|
|
|
- EditText mEditText;
|
|
|
-
|
|
|
- public FootVh(View itemView) {
|
|
|
- super(itemView);
|
|
|
- mEditText = itemView.findViewById(R.id.edit);
|
|
|
- itemView.findViewById(R.id.btn_report).setOnClickListener(mReportListener);
|
|
|
- }
|
|
|
-
|
|
|
- void submit() {
|
|
|
- String text = mEditText.getText().toString().trim();
|
|
|
- if (mActionListener != null) {
|
|
|
- mActionListener.onReportClick(mCurVideoReportBean, text);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void showEdit(boolean show) {
|
|
|
- if (mEditText != null) {
|
|
|
- if (show) {
|
|
|
- if (mEditText.getVisibility() != View.VISIBLE) {
|
|
|
- mEditText.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- if (mActionListener != null) {
|
|
|
- mActionListener.onEditShow(mEditText, show);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (mActionListener != null) {
|
|
|
- mActionListener.onEditShow(mEditText, show);
|
|
|
- }
|
|
|
- if (mEditText.getVisibility() == View.VISIBLE) {
|
|
|
- mEditText.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+// class HeadVh extends RecyclerView.ViewHolder {
|
|
|
+//
|
|
|
+// public HeadVh(View itemView) {
|
|
|
+// super(itemView);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// class FootVh extends RecyclerView.ViewHolder {
|
|
|
+//
|
|
|
+// EditText mEditText;
|
|
|
+//
|
|
|
+// public FootVh(View itemView) {
|
|
|
+// super(itemView);
|
|
|
+// mEditText = itemView.findViewById(R.id.edit);
|
|
|
+// itemView.findViewById(R.id.btn_report).setOnClickListener(mReportListener);
|
|
|
+// }
|
|
|
+//
|
|
|
+// void submit() {
|
|
|
+// String text = mEditText.getText().toString().trim();
|
|
|
+// if (mActionListener != null) {
|
|
|
+// mActionListener.onReportClick(mCurVideoReportBean, text);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// void showEdit(boolean show) {
|
|
|
+// if (mEditText != null) {
|
|
|
+// if (show) {
|
|
|
+// if (mEditText.getVisibility() != View.VISIBLE) {
|
|
|
+// mEditText.setVisibility(View.VISIBLE);
|
|
|
+// }
|
|
|
+// if (mActionListener != null) {
|
|
|
+// mActionListener.onEditShow(mEditText, show);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (mActionListener != null) {
|
|
|
+// mActionListener.onEditShow(mEditText, show);
|
|
|
+// }
|
|
|
+// if (mEditText.getVisibility() == View.VISIBLE) {
|
|
|
+// mEditText.setVisibility(View.GONE);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
class Vh extends RecyclerView.ViewHolder {
|
|
|
|
|
|
- ImageView mImg;
|
|
|
TextView mText;
|
|
|
+ TextView mSelectBtn;
|
|
|
+
|
|
|
|
|
|
public Vh(View itemView) {
|
|
|
super(itemView);
|
|
|
- mImg = itemView.findViewById(R.id.img);
|
|
|
mText = itemView.findViewById(R.id.text);
|
|
|
+ mSelectBtn = itemView.findViewById(R.id.bt_select);
|
|
|
itemView.setOnClickListener(mOnClickListener);
|
|
|
}
|
|
|
|
|
|
@@ -215,7 +224,12 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
itemView.setTag(position);
|
|
|
mText.setText(bean.getName());
|
|
|
}
|
|
|
- mImg.setImageDrawable(bean.isChecked() ? mCheckedDrawable : null);
|
|
|
+ itemView.setSelected(bean.isChecked());
|
|
|
+ mSelectBtn.setSelected(bean.isChecked());
|
|
|
+ // 根据选中状态改变文字颜色
|
|
|
+ mText.setTextColor(bean.isChecked() ?
|
|
|
+ 0xff00B760 : 0xff000000);
|
|
|
+ mSelectBtn.setVisibility(bean.isChecked() ? View.VISIBLE : View.GONE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -223,6 +237,8 @@ public class VideoReportAdapter extends RecyclerView.Adapter {
|
|
|
void onReportClick(VideoReportBean bean, String text);
|
|
|
|
|
|
void onEditShow(EditText editText, boolean isShow);
|
|
|
+
|
|
|
+ void onSelectionChanged(VideoReportBean selectedBean);
|
|
|
}
|
|
|
|
|
|
public void setActionListener(ActionListener actionListener) {
|