private void setDataInThread() {
    if (mResponseUsers.getmResponseCode() == 200) {
      JsonUserProfiles profile = new JsonUserProfiles(mResponseUsers.getmResponseData());
      LinkedList<TableProfile> requestProfiles = profile.getJsonObjectResponse();

      if (requestProfiles != null)
        if (requestProfiles.size() > 0) {
          new CommonQueries(mContext).queryCreateUsersProfiles(requestProfiles);
        }
    }

    if (mAllConversations.getmResponseCode() == 200) {
      JsonAnonis jAnoni = new JsonAnonis(mAllConversations.getmResponseData());
      List<TableAnoni> incomeAnoni = jAnoni.getJsonArrayResponse();

      if (incomeAnoni != null) {
        if (mAnoni.size() != 0 & incomeAnoni.size() != 0) {
          for (TableAnoni a : incomeAnoni) {
            boolean contain = false;
            for (int i = 0; i < mAnoni.size(); i++) {
              if (mAnoni.get(i).getId() == a.getId()) {
                contain = true;
                if (mAnoni.get(i).getMessages().size() < a.getMessages().size()) {
                  for (int j = 0; j < a.getMessages().size(); j++) {
                    boolean message_contain = false;
                    for (int k = 0; k < mAnoni.get(i).getMessages().size(); k++) {
                      if (a.getMessages().get(j).equals(mAnoni.get(i).getMessages().get(k))
                          == true) {
                        message_contain = true;
                      }
                    }
                    if (message_contain == false) ;
                    mAnoni.get(i).getMessages().add(a.getMessages().get(j));
                  }
                }
              }
            }

            if (contain == false) {
              mAnoni.add(a);
            }
          }
        }

        if (mAnoni.size() == 0) {
          mAnoni = incomeAnoni;
        }
      }

      new CommonQueries(mContext).queryCreateOfUpdateAllAnoni(mAnoni);

      Collections.sort(mAnoni, new AnoniComparator());

      // Need find last update
      long time_to_save = 0;
      if (mAnoni != null)
        if (mAnoni.size() > 0) {
          for (int i = 0; i < mAnoni.size(); i++) {
            if (mAnoni.get(i).getUpdated_at() > time_to_save)
              time_to_save = mAnoni.get(i).getUpdated_at();
          }
        }
      SharedPreferences prefs = mContext.getSharedPreferences(Const.PREFS_NAME, 0);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putLong(Const.GLOBAL_DATE, time_to_save);
      editor.commit();
    }
  }
  /**
   * 1 - Parse conversations list string and save it to Array. 2 - Set array to adapter. View data
   * as List of conversations.
   */
  private void setData() {

    if (mResponseUsers.getmResponseCode() == 200) {
      JsonProfiles profile = new JsonProfiles(mResponseUsers.getmResponseData());
      List<TableProfile> requestProfiles = new LinkedList<TableProfile>();
      requestProfiles = profile.getJsonObjectResponse();

      if (requestProfiles != null)
        if (requestProfiles.size() > 0) {
          mProfiles = requestProfiles;

          new CommonQueries(mContext).queryCreateUsersProfiles(requestProfiles);
        }
    }

    if (mAllConversations.getmResponseCode() == 200) {
      JsonAnonis jAnoni = new JsonAnonis(mAllConversations.getmResponseData());

      List<TableAnoni> incomeAnoni = jAnoni.getJsonArrayResponse();

      new CommonQueries(mContext).queryCreateAllAnoni(incomeAnoni);

      if (incomeAnoni != null)
        if (incomeAnoni.size() > 0) {
          int count_of_messages = 0;
          for (TableAnoni t : incomeAnoni) {
            count_of_messages = count_of_messages + t.getMessages().size();
          }

          Utils.updateCountOfMessages(count_of_messages);
        }

      if (incomeAnoni != null) {
        if (mAnoni.size() != 0 & incomeAnoni.size() != 0) {

          for (TableAnoni a : incomeAnoni) {
            boolean contain = false;
            for (int i = 0; i < mAnoni.size(); i++) {
              if (mAnoni.get(i).getId() == a.getId()) {
                contain = true;
                for (int j = 0; j < a.getMessages().size(); j++) {
                  mAnoni.get(i).getMessages().add(a.getMessages().get(j));
                }
              }
            }

            if (contain == false) {
              mAnoni.add(a);
            }
          }
        }

        if (mAnoni.size() == 0) {
          mAnoni = incomeAnoni;
        }
      }

      // new CommonQueries(mContext).queryCreateOfUpdateAllAnoni(mAnoni);
      // saveAllConversationsInThread(mAnoni);

      // Collections.sort(mAnoni, new AnoniComparator());

      if (adapter != null) {

        if (adapter.isEmpty() == true) Log.v(TAG, "Adapter: is Empty");
        // if(adapter.isEmpty() == true) {
        adapter =
            new ConversationsAdapter(
                mContext,
                ConversationsActivity.this,
                R.layout.row_event,
                filterHideConvs(mAnoni),
                mProfiles);
        ConversationsActivity.this.setListAdapter(adapter);
        // }
        adapter.notifyDataSetChanged();
      } else {
        adapter =
            new ConversationsAdapter(
                mContext,
                ConversationsActivity.this,
                R.layout.row_event,
                filterHideConvs(mAnoni),
                mProfiles);
        ConversationsActivity.this.setListAdapter(adapter);
        adapter.notifyDataSetChanged();
      }

      long time_to_save = 0;
      if (mAnoni != null)
        if (mAnoni.size() > 0)
          for (int i = 0; i < mAnoni.size(); i++) {
            if (mAnoni.get(i).getUpdated_at() > time_to_save) {
              time_to_save = mAnoni.get(i).getUpdated_at();
            }
          }
      Log.v(TAG, "Time first save in MS: " + time_to_save);
      SharedPreferences prefs = mContext.getSharedPreferences(Const.PREFS_NAME, 0);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putLong(Const.GLOBAL_DATE, time_to_save);
      editor.putBoolean(Const.START_SYNC_MESSAGES, true);
      editor.commit();
    }
  }
    @Override
    public void onReceive(Context arg0, Intent arg1) {

      TableAnoni an = new TableAnoni();
      TableProfile pro = new TableProfile();

      an = (TableAnoni) arg1.getExtras().getSerializable(Const.SERIALIZE_NEW_MESSAGE);
      pro = (TableProfile) arg1.getExtras().getSerializable(Const.SERIALIZE_NEW_REVELS);

      if (an == null) an = new TableAnoni();
      if (pro == null) pro = new TableProfile();

      Log.e(TAG, "We received msg to Conversations");
      if (an != null & pro != null) {

        if (an.getId() != 0 & pro.getId() == 0) {

          if (mAnoni != null) {
            if (mAnoni.size() > 0) {
              boolean contain = false;

              for (int i = 0; i < mAnoni.size(); i++) {
                if (mAnoni.get(i).getId() == an.getId()) {
                  contain = true;

                  //	Log.e(TAG, "Step 1 conv");

                  // Need to prevent duplicates
                  if (mAnoni.get(i).getMessages() != null)
                    if (mAnoni.get(i).getMessages().size() > 0) {
                      for (int k = 0; k < an.getMessages().size(); k++) {
                        boolean msg_contain = false;
                        //	Log.e(TAG, "Step 2 conv");
                        for (int j = 0; j < mAnoni.get(i).getMessages().size(); j++) {
                          if (mAnoni.get(i).getMessages().get(j).getId()
                              == an.getMessages().get(k).getId()) {
                            msg_contain = true;
                            //	Log.e(TAG, "Step 3 conv");
                          }
                        }

                        if (msg_contain == false) {
                          //	Log.e(TAG, "Only 1 msg");
                          mAnoni.get(i).getMessages().add(an.getMessages().get(k));
                        }
                      }
                    }

                  mAnoni.get(i).setUpdated_at(an.getUpdated_at());
                  /*TableAnoni temp = new TableAnoni();
                  temp = mAnoni.get(i);
                  mAnoni.remove(i);
                  mAnoni.add(0, temp);
                  */
                  break;
                }
              }

              if (contain == false) {
                mAnoni.add(0, an);
              }
            }

            if (mAnoni.size() == 0) {
              mAnoni.add(an);
            }
          }
        }

        if (an.getId() == 0 & pro.getId() != 0) {

          Log.v(TAG, "Update profile revelations");

          if (mProfiles != null) {
            if (mProfiles.size() > 0) {

              for (int i = 0; i < mProfiles.size(); i++) {
                if (mProfiles.get(i).getId() == pro.getId()) {
                  mProfiles.set(i, pro);
                }
              }

            } else {
              mProfiles.add(pro);
            }
          }
        }
        /*
        if(an.getId() == 0 & pro.getId() != 0) {
        	if(mProfiles != null) {
        		for(int i=0; i < mProfiles.size(); i++) {
        			boolean contain = false;
        			if(mProfiles.get(i).getId() == pro.getId()) {
        				contain = true;
        			}

        			if(contain == false) {
        				mProfiles.add(pro);
        			}
        		}
        	}
        }*/

        Collections.sort(mAnoni, new AnoniComparator());

        /* if(adapter != null) {
        	if(adapter.isEmpty() == true) {
        		adapter = new ConversationsAdapter(mContext, ConversationsActivity.this, R.layout.row_event, filterHideConvs(mAnoni), mProfiles);
        		ConversationsActivity.this.setListAdapter(adapter);
        	}
        } else {*/
        adapter =
            new ConversationsAdapter(
                mContext,
                ConversationsActivity.this,
                R.layout.row_event,
                filterHideConvs(mAnoni),
                mProfiles);
        ConversationsActivity.this.setListAdapter(adapter);
        // }
        adapter.notifyDataSetChanged();
      }
      // Log.e("Receiver","We are geting ths message");
    }