Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. package com.crystaldesigncenter.crystalreward.adapter;
  2.  
  3. import android.content.Context;
  4. import android.support.annotation.NonNull;
  5. import android.support.v7.widget.RecyclerView;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.Button;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12.  
  13. import com.afollestad.materialdialogs.DialogAction;
  14. import com.afollestad.materialdialogs.MaterialDialog;
  15. import com.crystaldesigncenter.crystalreward.R;
  16. import com.crystaldesigncenter.crystalreward.fragment.LuckyDrawInformationFragment;
  17. import com.crystaldesigncenter.crystalreward.manager.DialogCustomCountManager;
  18. import com.crystaldesigncenter.crystalreward.manager.DialogManager;
  19. import com.crystaldesigncenter.crystalreward.manager.bus.MainBus;
  20. import com.crystaldesigncenter.crystalreward.manager.bus.event.EventAddToBackStackFragment;
  21.  
  22. /**
  23. * Created by peem-jirayu on 23/9/2559.
  24. */
  25. public class LuckyDrawRecyclerAdapter extends RecyclerView.Adapter {
  26. private static DialogCustomCountManager dialogCount;
  27. private static DialogManager dialogPopup;
  28. private static Context mContext;
  29. int type;
  30. public LuckyDrawRecyclerAdapter(Context context, DialogCustomCountManager dialog, DialogManager dialogPopup){
  31. this.mContext = context;
  32. this.dialogCount = dialog;
  33. this.dialogPopup = dialogPopup;
  34. }
  35. private static class ContentLuckyDraw extends RecyclerView.ViewHolder implements View.OnClickListener {
  36. public ImageView imgProductLuckyDraw;
  37. public TextView tvNameProductLuckyDraw;
  38. public TextView tvTextDescriptionLuckyDraw;
  39. public TextView tvMyTicketLuckyDraw;
  40. public TextView tvDrawLuckyDraw;
  41. public Button btnDrawLuckyDraw;
  42. public ContentLuckyDraw(View itemView) {
  43. super(itemView);
  44. imgProductLuckyDraw = (ImageView) itemView.findViewById(R.id.imgProductLuckyDraw);
  45. tvNameProductLuckyDraw = (TextView) itemView.findViewById(R.id.tvNameProductLuckyDraw);
  46. tvTextDescriptionLuckyDraw = (TextView) itemView.findViewById(R.id.tvTextDescriptionLuckyDraw);
  47. tvMyTicketLuckyDraw = (TextView) itemView.findViewById(R.id.tvMyTicketLuckyDraw);
  48. tvDrawLuckyDraw = (TextView) itemView.findViewById(R.id.tvDrawLuckyDraw);
  49. btnDrawLuckyDraw = (Button) itemView.findViewById(R.id.btnDrawLuckyDraw);
  50. btnDrawLuckyDraw.setOnClickListener(this);
  51. }
  52.  
  53. @Override
  54. public void onClick(View view) {
  55. int position = getAdapterPosition();
  56. if (position != RecyclerView.NO_POSITION) {
  57. switch (position){
  58. case 1 : {
  59. dialogCount.showMsg(mContext, "", new MaterialDialog.SingleButtonCallback() {
  60. @Override
  61. public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
  62. dialogPopup.showMsg(mContext, "ยืนยัน", new MaterialDialog.SingleButtonCallback() {
  63. @Override
  64. public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
  65.  
  66.  
  67. }
  68. });
  69. }
  70. });
  71. }
  72. }
  73. }
  74. }
  75. }
  76. private static class HeaderLuckyDraw extends RecyclerView.ViewHolder {
  77. TextView tvDrawLuckyDrawHeader;
  78. public HeaderLuckyDraw(View itemView) {
  79. super(itemView);
  80. tvDrawLuckyDrawHeader = (TextView) itemView.findViewById(R.id.tvDrawLuckyDrawHeader);
  81. }
  82. }
  83.  
  84. @Override
  85. public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  86. LayoutInflater inflater = LayoutInflater.from(parent.getContext());
  87. switch (type) {
  88. case 0: default: {
  89. View view = inflater.inflate(R.layout.recycler_view_lucky_draw, parent, false);
  90. ContentLuckyDraw content = new ContentLuckyDraw(view);
  91. return content;
  92. }
  93. case 1: {
  94. View view = inflater.inflate(R.layout.recycler_view_lucky_draw_header,parent,false);
  95. HeaderLuckyDraw header = new HeaderLuckyDraw(view);
  96. return header;
  97. }
  98. }
  99.  
  100. }
  101.  
  102. @Override
  103. public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  104. //TODO : bind view holder with data from server
  105. }
  106.  
  107. @Override
  108. public int getItemCount() {
  109. return 20;
  110. }
  111.  
  112. @Override
  113. public int getItemViewType(int position) {
  114. //dummy data
  115. if (position == 0 || position == 2){
  116. type = 1;
  117. }else {
  118. type = 0;
  119. }
  120. return type;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement