Ejemplo n.º 1
0
  private void setSecondData() {

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

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

      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 (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();
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * 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();
    }
  }
Ejemplo n.º 3
0
  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();
    }
  }