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(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.v(TAG, "onCreate()"); this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.conversation); mContext = ConversationsActivity.this; mRes = this.getResources(); PushPreferences prefsd = PushManager.shared().getPreferences(); Logger.info("My Application onCreate - App APID: " + prefsd.getPushId()); if (mReceiver == null) { mReceiver = new Receiver(); if (filter == null) { filter = new IntentFilter("com.anoni.PUSHER_MESSAGE_CONV"); this.registerReceiver(mReceiver, filter); } } PackageManager manager = this.getPackageManager(); PackageInfo info = null; try { info = manager.getPackageInfo(this.getPackageName(), 0); } catch (NameNotFoundException e) { e.printStackTrace(); } // Custom Title Bar------------------------------------------------------------ getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); mTextViewProgressLoading = (TextView) findViewById(R.id.tv_titlebar_loading); mTextViewProgress = (TextView) findViewById(R.id.tv_titlebar); // mTextViewProgress.setText(getTitle()+" "+info.versionName); mTextViewProgress.setText(getTitle()); titleProgressBar = (ProgressBar) findViewById(R.id.leadProgressBar); titleProgressBar.setProgress(0); // ---------------------------------------------------------------------------- // Toast.makeText(mContext, "App is onCreate()", Toast.LENGTH_SHORT).show(); SharedPreferences prefs = getSharedPreferences(Const.PREFS_NAME, 0); mId = prefs.getString(Const.PREFS_ID, ""); Intent messageservice = new Intent(this, MessageService.class); messageservice.putExtra("channel", "user-"); startService(messageservice); bLaunch = prefs.getBoolean(Const.FIRST_LAUNCH, false); // Get Screen resolution Utils.getScreenSize(mContext); Log.v(TAG, "mId " + mId); Log.v(TAG, TAG); et_search_text = (EditText) findViewById(R.id.et_search_text); et_search_text.setHint("search conversations"); // 231 et_search_text.addTextChangedListener( new TextWatcher() { private int state = 0; @Override public void afterTextChanged(Editable arg0) { if (et_search_text.getText().toString().length() > 0) { // mConver.clear(); String str = et_search_text.getText().toString(); mAnoni = searchEngine(str); adapter = new ConversationsAdapter( mContext, ConversationsActivity.this, R.layout.row_event, filterHideConvs(mAnoni), mProfiles); ConversationsActivity.this.setListAdapter(adapter); } else { if (state == 1) { mAnoni = new CommonQueries(mContext).queryGetAllAnoni(); adapter = new ConversationsAdapter( mContext, ConversationsActivity.this, R.layout.row_event, filterHideConvs(mAnoni), mProfiles); ConversationsActivity.this.setListAdapter(adapter); } } if (adapter != null) adapter.notifyDataSetChanged(); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (arg0.length() == 0) state = 0; else state = 1; } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {} }); mResume = false; // its not a first start if (bLaunch == false) { mAnoni = new CommonQueries(mContext).queryGetAllAnoni(); mProfiles = new CommonQueries(mContext).queryGetAllUsersProfiles(); } if (mAnoni != null) if (mAnoni.size() > 0) { Collections.sort(mAnoni, new AnoniComparator()); adapter = new ConversationsAdapter( mContext, ConversationsActivity.this, R.layout.row_event, filterHideConvs(mAnoni), mProfiles); ConversationsActivity.this.setListAdapter(adapter); if (adapter != null) { adapter.notifyDataSetChanged(); } } bQuit = false; /* if(bLaunch == false) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Const.FIRST_LAUNCH, true); editor.commit(); new PopUpText(mContext).showPopUp(); requestGetConversations(); //task = new AsyncRequest(); //task.execute(); } else { task_second = new AsyncRequestSecond(); task_second.execute(); } */ // Correct if (bLaunch == true) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Const.FIRST_LAUNCH, false); editor.commit(); Log.v(TAG, "getConvsFirstStart()"); // getConvsFirstStart(); task = new AsyncRequest(); task.execute(); } else { // getConvsSecondStart(); task_second = new AsyncRequestSecond(); task_second.execute(); } }