daily pastebin goal
7%
SHARE
TWEET

onBindViewHolder

RafaelKowal Jan 4th, 2017 (edited) 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.     public int getItemViewType(int position) {
  3.         int viewType = 0;
  4.  
  5.         if (events.get(position).getTypeEvent().getName().equals("Causa") ) {
  6.             viewType = TYPE_CAUSA_HEADER;
  7.         }else if (events.get(position).getTypeEvent().getName().equals("Pequeno Grupo") ) {
  8.             viewType = TYPE_PG_HEADER;
  9.         }else if (events.get(position).getTypeEvent().getName().equals("Culto Jovem") ) {
  10.             viewType = TYPE_CULTO_HEADER;
  11.         } else {
  12.             viewType = TYPE_SABATINA_HEADER;
  13.         }
  14.  
  15.         return viewType;
  16.     }
  17.  
  18. @Override
  19.     public void onBindViewHolder(MyViewHolder myViewHolder, int position) {
  20.  
  21.         event = events.get(position);
  22.         String mDate = Utils.getShortTime(event.getUpdatedAt());
  23.         dataNew = Utils.getShortDateTime(event.getUpdatedAt());
  24.         Long date = System.currentTimeMillis();
  25.         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  26.         String dateNow = sdf.format(date);
  27.  
  28.         if (dateNow.equals(dataNew)) {
  29.             dateFull = "Hoje";
  30.         } else {
  31.             dateFull = Utils.getShortDateTimeDay(event.getUpdatedAt()) + " de " + Utils.getShortDateTimeMonth(event.getUpdatedAt());
  32.         }
  33.  
  34.         String nameFull = event.getUserName() + " " + event.getLastName();
  35.         myViewHolder.userName.setText(nameFull);
  36.         myViewHolder.hora.setText(mDate + "h");
  37.         myViewHolder.type.setText(event.getName());
  38.         myViewHolder.typeName.setText(event.getTypeEvent().getName());
  39.  
  40.         userId = event.getUserIdStr();
  41.         eventId = event.getEventId();
  42.  
  43.         boolean star = event.getLike();
  44.         if (star) {
  45.             myViewHolder.imgStar.setImageResource(R.drawable.like1);
  46.         } else {
  47.             myViewHolder.imgStar.setImageResource(R.drawable.like0);
  48.         }
  49.  
  50.         if (event.getUserThumb() != null) {
  51.             Uri imageUri = Uri.parse(event.getUserThumb());
  52.             Glide.with(myViewHolder.imgAvatar.getContext()).load(imageUri.toString())
  53.                     .thumbnail(0.5f)
  54.                     .override(150,150)
  55.                     .crossFade()
  56.                     .centerCrop()
  57.                     .transform(new GlideCircleTransform(myViewHolder.imgAvatar.getContext()))
  58.                     .diskCacheStrategy(DiskCacheStrategy.ALL)
  59.                     .into(myViewHolder.imgAvatar);
  60.         }
  61.  
  62.  
  63.         switch (myViewHolder.getItemViewType()) {
  64.             case TYPE_CAUSA_HEADER :
  65.                 myViewHolder.typeColor.setBackgroundColor(Color.parseColor("#80B0C9"));
  66.                 break;
  67.             case TYPE_PG_HEADER :
  68.                 myViewHolder.typeColor.setBackgroundColor(Color.parseColor("#DC7690"));
  69.                 break;
  70.             case TYPE_CULTO_HEADER :
  71.                 myViewHolder.typeColor.setBackgroundColor(Color.parseColor("#58D290"));
  72.                 break;
  73.             case TYPE_SABATINA_HEADER :
  74.                 myViewHolder.typeColor.setBackgroundColor(Color.parseColor("#E5EB42"));
  75.                 break;
  76.             default:
  77.         }
  78.         if (dataLast.equals(dataNew)) {
  79.             myViewHolder.header.setVisibility(View.GONE);
  80.         } else {
  81.             myViewHolder.header.setVisibility(View.VISIBLE);
  82.             myViewHolder.data.setText(dateFull);
  83.         }
  84.         dataLast = dataNew;
  85.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top