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(); } } }
/** * 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(); } }