@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder vh;
    if (convertView == null) {
      // inflate the layout
      LayoutInflater inflater = ((Activity) context).getLayoutInflater();
      convertView = inflater.inflate(R.layout.item_message, parent, false);
      vh = new ViewHolder();
      vh.username = (TextView) convertView.findViewById(R.id.msg_user);
      vh.message = (TextView) convertView.findViewById(R.id.msg_message);
      vh.date = (TextView) convertView.findViewById(R.id.msg_date);
      convertView.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    vh.username.setText(getItem(position).getUsername());
    vh.message.setText(Html.fromHtml(getItem(position).getMsg()));
    try {
      vh.date.setText(DateHelper.getFormattedDate(getItem(position).getDate()));
    } catch (ParseException e) {
      Log.e(Constants.TAG, "error parsing date", e);
    }

    return convertView;
  }
 public View getView(final int position, View convertView, ViewGroup parent) {
   final ViewHolder holder;
   if (convertView == null) {
     convertView = mInflater.inflate(R.layout.facebook_entries, null);
     holder = new ViewHolder();
     holder.message = (TextView) convertView.findViewById(R.id.message);
     holder.status_ic = (ImageView) convertView.findViewById(R.id.status_ic);
     convertView.setTag(holder);
   } else {
     holder = (ViewHolder) convertView.getTag();
   }
   message = selectionList.get(position).split(":")[0];
   DBAdapter db = new DBAdapter(ctx);
   db.open();
   Cursor c = db.getAllFEntries();
   try {
     while (c.moveToNext()) {
       if (c.getString(c.getColumnIndex("message")).equals(message)) {
         active = Boolean.parseBoolean(c.getString(c.getColumnIndex("active")));
         break;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   c.close();
   db.close();
   if (active) {
     holder.status_ic.setImageResource(R.drawable.status_active);
   } else {
     holder.status_ic.setImageResource(R.drawable.status_inactive);
   }
   holder.message.setText(message);
   return convertView;
 }
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewHolder holder = new ViewHolder();
    View v = null;

    if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("1"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("1")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityright_low, parent, false);

    } else if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("1"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("2")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityright_medium, parent, false);

    } else if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("1"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("3")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityright_high, parent, false);

    } else if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("0"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("1")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityleft_low, parent, false);

    } else if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("0"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("2")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityleft_medium, parent, false);

    } else if ((cursor.getString(cursor.getColumnIndex(DatabaseConstants.KEY_ISMINE)).equals("0"))
        && (cursor.getInt(cursor.getColumnIndex(DatabaseConstants.KEY_PRIORITY)) + "")
            .equals("3")) {
      v = mInflater.inflate(R.layout.message_priorityasline_gravityleft_high, parent, false);
    }

    holder.message = (TextView) v.findViewById(R.id.row_message);
    holder.name = (TextView) v.findViewById(R.id.row_name);
    holder.priorityGONE = (TextView) v.findViewById(R.id.row_priorityGONE);
    holder.rowid = (TextView) v.findViewById(R.id.row_rowid);
    holder.timestamp = (TextView) v.findViewById(R.id.row_timestamp);

    v.setTag(holder);
    return v;
  }
Beispiel #4
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.recent_item, null);
      holder = new ViewHolder();
      holder.userName = (TextView) convertView.findViewById(R.id.recent_name);
      holder.sendTime = (TextView) convertView.findViewById(R.id.recent_time);
      holder.message = (TextView) convertView.findViewById(R.id.recent_msg);
      holder.unread_num = (TextView) convertView.findViewById(R.id.recent_unread_num);
      holder.avatar = (ImageView) convertView.findViewById(R.id.img_avatar);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    final RecentEntity entity = listRecentMsg.get(position);
    holder.userName.setText(
        (entity.getNick() != null && !entity.getNick().trim().equals(""))
            ? entity.getNick()
            : entity.getName());
    holder.sendTime.setText(DateHelper.GetStringFormat(entity.getMessage().timestamp()));
    holder.message.setText(getMsgContent(entity.getMessage()));
    if (entity.getCount() > 0) {
      holder.unread_num.setVisibility(View.VISIBLE);
      if (entity.getCount() > 99) {
        holder.unread_num.setText("99+");
      } else {
        holder.unread_num.setText(entity.getCount() + "");
      }
      holder.unread_num.setTextColor(Color.BLACK);
    } else {
      holder.unread_num.setVisibility(View.INVISIBLE);
    }
    if (entity.getIsGroupMsg()) {
      holder.avatar.setImageResource(R.drawable.icon_group);
    } else {
      holder.avatar.setImageResource(R.drawable.chat_default_avatar);
    }
    return convertView;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    // Si la vue n'est pas recyclée
    if (convertView == null) {

      // On récupère le layout
      convertView = inflater.inflate(R.layout.item_notification, null);

      holder = new ViewHolder();
      // On place les widgets de notre layout dans le holder
      holder.username = (TextView) convertView.findViewById(R.id.username);
      holder.message = (TextView) convertView.findViewById(R.id.message);
      holder.type = (ImageView) convertView.findViewById(R.id.type);

      // puis on insère le holder en tant que tag dans le layout
      convertView.setTag(holder);

    } else {

      // Si on recycle la vue, on récupère son holder en tag
      holder = (ViewHolder) convertView.getTag();
    }

    // Dans tous les cas, on récupère la notification concerné.
    Notification notification = (Notification) getItem(position);
    // Si cet élément existe vraiment…
    if (notification != null) {
      // On place dans le holder les informations sur la notification.
      holder.username.setText(notification.getUserFrom());
      holder.message.setText(adaptString(notification.getMessage()));
      if (notification.getType().equals(TYPE.INFO)) {
        holder.type.setImageResource(R.drawable.info);
      } else if (notification.getType().equals(TYPE.FUEL)) {
        holder.type.setImageResource(R.drawable.fuel);
      } else if (notification.getType().equals(TYPE.INVITATION)) {
        holder.type.setImageResource(R.drawable.invitation);
      }
    }
    return convertView;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.row_chat_history, parent, false);
    }
    ViewHolder holder = (ViewHolder) convertView.getTag();
    if (holder == null) {
      holder = new ViewHolder();
      holder.name = (TextView) convertView.findViewById(R.id.name);
      holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number);
      holder.message = (TextView) convertView.findViewById(R.id.message);
      holder.time = (TextView) convertView.findViewById(R.id.time);
      holder.avatar = (ImageView) convertView.findViewById(R.id.avatar);
      holder.msgState = convertView.findViewById(R.id.msg_state);
      holder.list_item_layout = (RelativeLayout) convertView.findViewById(R.id.list_item_layout);
      convertView.setTag(holder);
    }
    if (position % 2 == 0) {
      holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem);
    } else {
      holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem_grey);
    }

    // 获取与此用户/群组的会话
    EMConversation conversation = getItem(position);
    // 获取用户username或者群组groupid
    String username = conversation.getUserName();
    if (conversation.getType() == EMConversationType.GroupChat) {
      // 群聊消息,显示群聊头像
      holder.avatar.setImageResource(R.drawable.group_icon);
      EMGroup group = EMGroupManager.getInstance().getGroup(username);
      holder.name.setText(group != null ? group.getGroupName() : username);
    } else if (conversation.getType() == EMConversationType.ChatRoom) {
      holder.avatar.setImageResource(R.drawable.group_icon);
      EMChatRoom room = EMChatManager.getInstance().getChatRoom(username);
      holder.name.setText(
          room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username);
    } else {
      UserUtils.setUserAvatar(getContext(), username, holder.avatar);
      if (username.equals(Constant.GROUP_USERNAME)) {
        holder.name.setText("群聊");

      } else if (username.equals(Constant.NEW_FRIENDS_USERNAME)) {
        holder.name.setText("申请与通知");
      }
      Map<String, RobotUser> robotMap =
          ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
      if (robotMap != null && robotMap.containsKey(username)) {
        String nick = robotMap.get(username).getNick();
        if (!TextUtils.isEmpty(nick)) {
          holder.name.setText(nick);
        } else {
          holder.name.setText(username);
        }
      } else {
        UserUtils.setUserNick(username, holder.name);
      }
    }

    if (conversation.getUnreadMsgCount() > 0) {
      // 显示与此用户的消息未读数
      holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount()));
      holder.unreadLabel.setVisibility(View.VISIBLE);
    } else {
      holder.unreadLabel.setVisibility(View.INVISIBLE);
    }

    if (conversation.getMsgCount() != 0) {
      // 把最后一条消息的内容作为item的message内容
      EMMessage lastMessage = conversation.getLastMessage();
      holder.message.setText(
          SmileUtils.getSmiledText(
              getContext(), getMessageDigest(lastMessage, (this.getContext()))),
          BufferType.SPANNABLE);

      holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
      if (lastMessage.direct == EMMessage.Direct.SEND
          && lastMessage.status == EMMessage.Status.FAIL) {
        holder.msgState.setVisibility(View.VISIBLE);
      } else {
        holder.msgState.setVisibility(View.GONE);
      }
    }

    return convertView;
  }
    @SuppressWarnings("deprecation")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      Message message1 = (Message) this.getItem(position);

      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
        holder.message = (EmojiconTextView) convertView.findViewById(R.id.message_text);
        holder.thumb = (FetchableImageView) convertView.findViewById(R.id.thumb);
        holder.message.setPadding(10, 10, 10, 10);
        convertView.setTag(holder);
      } else holder = (ViewHolder) convertView.getTag();
      if (message1.getMsgtype().equalsIgnoreCase("text")) {
        holder.message.setVisibility(View.VISIBLE);
        holder.thumb.setVisibility(View.GONE);

        holder.message.setText(message1.getMessage());
        LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
        if (message1.getIsmine().equals("yes")) {
          holder.message.setBackgroundResource(R.drawable.message_you);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.RIGHT;
          lp.leftMargin = 50;
          lp.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.message.setBackgroundResource(R.drawable.message_from);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.LEFT;
          lp.rightMargin = 50;
          lp.leftMargin = 20;
        }
        holder.message.setLayoutParams(lp);
        holder.message.setTextColor(mContext.getResources().getColor(R.color.Black));
      } else {
        LayoutParams lp1 = (LayoutParams) holder.thumb.getLayoutParams();
        holder.message.setVisibility(View.GONE);
        holder.thumb.setVisibility(View.VISIBLE);
        holder.thumb.setPadding(15, 15, 15, 15);
        if (message1.getMsgtype().equals("video")) {

          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_video);
          final String url = DataManager.FILE_PATH + message1.getMessage().toString();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "video/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("audio")) {
          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_audio);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Uri myUri = Uri.parse(url);
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(myUri, "audio/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("photo")) {
          holder.thumb.setImage(
              DataManager.FILE_PATH + message1.getMessage(), R.drawable.placeholder_image);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "image/*");
                  mContext.startActivity(intent);
                }
              });
        }
        if (message1.getIsmine().equals("yes")) {
          holder.thumb.setBackgroundResource(R.drawable.message_you);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.RIGHT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.leftMargin = 50;
          lp1.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.thumb.setBackgroundResource(R.drawable.message_from);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.LEFT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.rightMargin = 50;
          lp1.leftMargin = 20;
        }
        holder.thumb.setLayoutParams(lp1);
      }
      return convertView;
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView =
          LayoutInflater.from(getContext()).inflate(R.layout.ease_row_chat_history, parent, false);
    }
    ViewHolder holder = (ViewHolder) convertView.getTag();
    if (holder == null) {
      holder = new ViewHolder();
      holder.name = (TextView) convertView.findViewById(R.id.name);
      holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number);
      holder.message = (TextView) convertView.findViewById(R.id.message);
      holder.time = (TextView) convertView.findViewById(R.id.time);
      holder.avatar = (ImageView) convertView.findViewById(R.id.avatar);
      holder.msgState = convertView.findViewById(R.id.msg_state);
      holder.list_itease_layout =
          (RelativeLayout) convertView.findViewById(R.id.list_itease_layout);
      convertView.setTag(holder);
    }
    holder.list_itease_layout.setBackgroundResource(R.drawable.ease_mm_listitem);

    // 获取与此用户/群组的会话
    EMConversation conversation = getItem(position);
    // 获取用户username或者群组groupid
    String username = conversation.getUserName();

    if (conversation.getType() == EMConversationType.GroupChat) {
      // 群聊消息,显示群聊头像
      holder.avatar.setImageResource(R.drawable.ease_group_icon);
      EMGroup group = EMClient.getInstance().groupManager().getGroup(username);
      holder.name.setText(group != null ? group.getGroupName() : username);
    } else if (conversation.getType() == EMConversationType.ChatRoom) {
      holder.avatar.setImageResource(R.drawable.ease_group_icon);
      EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(username);
      holder.name.setText(
          room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username);
    } else {
      EaseUserUtils.setUserAvatar(getContext(), username, holder.avatar);
      EaseUserUtils.setUserNick(username, holder.name);
    }

    if (conversation.getUnreadMsgCount() > 0) {
      // 显示与此用户的消息未读数
      holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount()));
      holder.unreadLabel.setVisibility(View.VISIBLE);
    } else {
      holder.unreadLabel.setVisibility(View.INVISIBLE);
    }

    if (conversation.getAllMsgCount() != 0) {
      // 把最后一条消息的内容作为item的message内容
      EMMessage lastMessage = conversation.getLastMessage();
      holder.message.setText(
          EaseSmileUtils.getSmiledText(
              getContext(), EaseCommonUtils.getMessageDigest(lastMessage, (this.getContext()))),
          BufferType.SPANNABLE);

      holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
      if (lastMessage.direct() == EMMessage.Direct.SEND
          && lastMessage.status() == EMMessage.Status.FAIL) {
        holder.msgState.setVisibility(View.VISIBLE);
      } else {
        holder.msgState.setVisibility(View.GONE);
      }
    }

    // 设置自定义属性
    holder.name.setTextColor(primaryColor);
    holder.message.setTextColor(secondaryColor);
    holder.time.setTextColor(timeColor);
    if (primarySize != 0) holder.name.setTextSize(TypedValue.COMPLEX_UNIT_PX, primarySize);
    if (secondarySize != 0) holder.message.setTextSize(TypedValue.COMPLEX_UNIT_PX, secondarySize);
    if (timeSize != 0) holder.time.setTextSize(TypedValue.COMPLEX_UNIT_PX, timeSize);

    return convertView;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      convertView = inflater.inflate(R.layout.post_list_adapter_row, parent, false);

      viewHolder = new ViewHolder();
      viewHolder.name = (TextView) convertView.findViewById(R.id.name);
      viewHolder.createdTime = (TextView) convertView.findViewById(R.id.createdTime);
      viewHolder.message = (TextView) convertView.findViewById(R.id.message);

      viewHolder.picture = (ImageView) convertView.findViewById(R.id.picture);
      viewHolder.fullPicture = (ImageView) convertView.findViewById(R.id.fullPicture);

      viewHolder.share = (ImageButton) convertView.findViewById(R.id.btnShare);
      viewHolder.unlike = (ImageButton) convertView.findViewById(R.id.btnUnLike);
      viewHolder.like = (ImageButton) convertView.findViewById(R.id.btnLike);
      viewHolder.comment = (ImageButton) convertView.findViewById(R.id.btnComment);

      viewHolder.listView = (ListView) convertView.findViewById(R.id.listView2);

      dataBaseLikeHandler.open();

      stringLocalPostLikedMap = dataBaseLikeHandler.returnValue();

      viewHolder.share.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              FragmentManager fragmentManager = activity.getFragmentManager();

              FacebookSdk.sdkInitialize(activity);
              ShareDialog shareDialog = new ShareDialog(activity);

              if (ShareDialog.canShow(ShareLinkContent.class)) {
                ShareLinkContent linkContent =
                    new ShareLinkContent.Builder()
                        .setContentTitle(postVOs.get((Integer) view.getTag()).getName())
                        .setContentDescription("Compartido por SwenApp. Buscanos en Google Play")
                        .setContentUrl(Uri.parse(postVOs.get((Integer) view.getTag()).getLink()))
                        .build();

                shareDialog.show(linkContent);

                int points = preferences.getInt("points", 0);
                points = points + 10;

                SharedPreferences.Editor editor = preferences.edit();
                editor.putInt("points", points);
                editor.commit();

                int share = preferences.getInt("share", 0);
                share = share + 1;

                SharedPreferences.Editor editorShare = preferences.edit();
                editorShare.putInt("share", share);
                editorShare.commit();

                Desafios desafios = new Desafios(context, preferences, fragmentManager);

                if ((postVOs
                    .get((Integer) view.getTag())
                    .getMessage()
                    .contains("#SentiteComodo"))) {
                  int shareSentiteComodo = preferences.getInt("shareSentiteComodo", 0);
                  shareSentiteComodo = shareSentiteComodo + 1;

                  editorShare.putInt("shareSentiteComodo", shareSentiteComodo);
                }

                if ((postVOs.get((Integer) view.getTag()).getMessage().contains("#Gifcard"))) {
                  int shareGifCard = preferences.getInt("shareGifCard", 0);
                  shareGifCard = shareGifCard + 1;

                  editorShare.putInt("shareGifCard", shareGifCard);
                }

                PerfilFragment.getInstance().setValues();

                desafios.getMedallaPorAcciones();
              }
            }
          });

      viewHolder.comment.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              FragmentManager fragmentManager = activity.getFragmentManager();
              DialogComment dialogo =
                  new DialogComment(context, postVOs.get((Integer) view.getTag()).getId());
              dialogo.show(fragmentManager, "tagAlerta");
              reloadListComments();

              int points = preferences.getInt("points", 0);
              points = points + 5;

              SharedPreferences.Editor editor = preferences.edit();
              editor.putInt("points", points);
              editor.commit();

              int comment = preferences.getInt("comment", 0);
              comment = comment + 1;

              SharedPreferences.Editor editorComment = preferences.edit();
              editorComment.putInt("comment", comment);
              editorComment.commit();

              Desafios desafios = new Desafios(context, preferences, fragmentManager);

              desafios.getMedallaPorAcciones();

              PerfilFragment.getInstance().setValues();
            }
          });

      viewHolder.unlike.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              String id = postVOs.get((Integer) view.getTag()).getId();
              FragmentManager fragmentManager = activity.getFragmentManager();

              viewHolder.unlike.setVisibility(View.GONE);
              viewHolder.like.setVisibility(View.VISIBLE);

              Toast.makeText(context, "Me gusta +1", Toast.LENGTH_LONG).show();

              if (!stringLocalPostLikedMap.containsKey(id)) {
                dataBaseLikeHandler.insertData(id, true);
              } else {
                LocalPostLiked localPostLiked = stringLocalPostLikedMap.get(id);
                dataBaseLikeHandler.upDate(
                    localPostLiked.getId(), localPostLiked.getPostID(), true);
              }

              int points = preferences.getInt("points", 0);
              points = points + 1;

              SharedPreferences.Editor editor = preferences.edit();
              editor.putInt("points", points);
              editor.commit();

              int like = preferences.getInt("like", 0);
              like = like + 1;

              SharedPreferences.Editor editorLike = preferences.edit();
              editorLike.putInt("like", like);
              editorLike.commit();

              stringLocalPostLikedMap = dataBaseLikeHandler.returnValue();

              Desafios desafios = new Desafios(context, preferences, fragmentManager);

              desafios.getMedallaPorAcciones();

              PerfilFragment.getInstance().setValues();
            }
          });

      viewHolder.like.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              String id = postVOs.get((Integer) view.getTag()).getId();

              viewHolder.unlike.setVisibility(View.VISIBLE);
              viewHolder.like.setVisibility(View.GONE);

              Toast.makeText(context, "Me gusta -1", Toast.LENGTH_LONG).show();

              LocalPostLiked localPostLiked = stringLocalPostLikedMap.get(id);
              try {
                dataBaseLikeHandler.upDate(
                    localPostLiked.getId(), localPostLiked.getPostID(), false);
              } catch (Exception e) {
                // todo;
              }

              stringLocalPostLikedMap = dataBaseLikeHandler.returnValue();
            }
          });

      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    PostVO postVO = postVOs.get(position);
    if (postVO != null) {
      viewHolder.share.setTag(position);
      viewHolder.comment.setTag(position);
      viewHolder.like.setTag(position);
      viewHolder.unlike.setTag(position);
      viewHolder.id = postVO.getId();
      viewHolder.name.setText(postVO.getName());
      viewHolder.createdTime.setText(postVO.getCreatedTime());
      viewHolder.message.setText(postVO.getMessage());
      Picasso.with(context).load(postVO.getPicture()).into(viewHolder.picture);
      Picasso.with(context).load(postVO.getFullPicture()).into(viewHolder.fullPicture);

      if (stringLocalPostLikedMap.containsKey(postVO.getId())) {
        if (stringLocalPostLikedMap.get(postVO.getId()).isLiked()) {
          viewHolder.unlike.setVisibility(View.GONE);
          viewHolder.like.setVisibility(View.VISIBLE);
        } else {
          viewHolder.unlike.setVisibility(View.VISIBLE);
          viewHolder.like.setVisibility(View.GONE);
        }
      } else {
        viewHolder.unlike.setVisibility(View.VISIBLE);
        viewHolder.like.setVisibility(View.GONE);
      }

      if (commentsListMaps.containsKey(postVO.getId())) {
        List<LocalPostComment> localPostComments = commentsListMaps.get(postVO.getId());
        List<String> list = new ArrayList<>();
        for (LocalPostComment localPostComment : localPostComments) {
          list.add(localPostComment.getComment());
        }
        viewHolder.listView.setAdapter(
            new ArrayAdapter(context, android.R.layout.simple_list_item_1, list));
      } else {
        viewHolder.listView.setAdapter(
            new ArrayAdapter(context, android.R.layout.simple_list_item_1, new ArrayList()));
      }
    }

    return convertView;
  }