ee9ba85b85bdba443836f704e34e4c0dc88fa2a9.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package eVVM.apk.common;
  2. import android.content.Context;
  3. import android.support.annotation.ColorInt;
  4. import android.support.annotation.DrawableRes;
  5. import android.support.annotation.IdRes;
  6. import android.support.annotation.StringRes;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.CompoundButton;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import com.hjq.base.BaseRecyclerViewAdapter;
  13. import com.hjq.image.ImageLoader;
  14. import butterknife.ButterKnife;
  15. public abstract class MyRecyclerViewAdapter<T, VH extends MyRecyclerViewAdapter.ViewHolder>
  16. extends BaseRecyclerViewAdapter<T, VH> {
  17. // 当前列表的页码,默认为第一页,用于分页加载功能
  18. private int mPageNumber = 1;
  19. // 是否是最后一页,默认为false,用于分页加载功能
  20. private boolean mLastPage;
  21. // 标记对象
  22. private Object mTag;
  23. public MyRecyclerViewAdapter(Context context) {
  24. super(context);
  25. }
  26. /**
  27. * 获取当前的页码
  28. */
  29. public int getPageNumber() {
  30. return mPageNumber;
  31. }
  32. /**
  33. * 设置当前的页码
  34. */
  35. public void setPageNumber(int pageNumber) {
  36. mPageNumber = pageNumber;
  37. }
  38. /**
  39. * 当前是否为最后一页
  40. */
  41. public boolean isLastPage() {
  42. return mLastPage;
  43. }
  44. /**
  45. * 设置是否为最后一页
  46. */
  47. public void setLastPage(boolean lastPage) {
  48. mLastPage = lastPage;
  49. }
  50. /**
  51. * 获取标记
  52. */
  53. public Object getTag() {
  54. return mTag;
  55. }
  56. /**
  57. * 设置标记
  58. */
  59. public void setTag(Object tag) {
  60. mTag = tag;
  61. }
  62. public class ViewHolder extends BaseRecyclerViewAdapter.ViewHolder {
  63. public ViewHolder(ViewGroup parent, int layoutId) {
  64. super(parent, layoutId);
  65. ButterKnife.bind(this, itemView);
  66. }
  67. public ViewHolder(View itemView) {
  68. super(itemView);
  69. ButterKnife.bind(this, itemView);
  70. }
  71. public final ViewHolder setText(@IdRes int viewId, @StringRes int resId) {
  72. return setText(viewId, getItemView().getResources().getString(resId));
  73. }
  74. public final ViewHolder setText(@IdRes int viewId, String text) {
  75. if (text == null) text = "";
  76. View view = findViewById(viewId);
  77. if (view instanceof TextView) {
  78. ((TextView) view).setText(text);
  79. }
  80. return this;
  81. }
  82. public final ViewHolder setVisibility(@IdRes int viewId, int visibility) {
  83. View view = findViewById(viewId);
  84. if (view != null) {
  85. view.setVisibility(visibility);
  86. }
  87. return this;
  88. }
  89. public final ViewHolder setColor(@IdRes int viewId, @ColorInt int color) {
  90. View view = findViewById(viewId);
  91. if (view instanceof TextView) {
  92. ((TextView) view).setTextColor(color);
  93. }
  94. return this;
  95. }
  96. public final ViewHolder setImage(@IdRes int viewId, @DrawableRes int resId) {
  97. View view = findViewById(viewId);
  98. if (view instanceof ImageView) {
  99. ((ImageView) view).setImageResource(resId);
  100. }
  101. return this;
  102. }
  103. public final ViewHolder setImage(@IdRes int viewId, String url) {
  104. View view = findViewById(viewId);
  105. if (view instanceof ImageView) {
  106. ImageLoader.loadImage((ImageView) view, url);
  107. }
  108. return this;
  109. }
  110. public final ViewHolder setChecked(@IdRes int viewId, boolean checked) {
  111. View view = findViewById(viewId);
  112. if (view instanceof CompoundButton) {
  113. ((CompoundButton) view).setChecked(checked);
  114. }
  115. return this;
  116. }
  117. }
  118. }