private void onTaskTipsComplete(Group<Tip> group, boolean recentOnly, Exception ex) { SegmentedButton buttons = getHeaderButton(); boolean update = false; if (group != null) { if (recentOnly) { mStateHolder.setTipsRecent(group); if (buttons.getSelectedButtonIndex() == 0) { mListAdapter.setGroup(mStateHolder.getTipsRecent()); update = true; } } else { mStateHolder.setTipsPopular(group); if (buttons.getSelectedButtonIndex() == 1) { mListAdapter.setGroup(mStateHolder.getTipsPopular()); update = true; } } } else { if (recentOnly) { mStateHolder.setTipsRecent(new Group<Tip>()); if (buttons.getSelectedButtonIndex() == 0) { mListAdapter.setGroup(mStateHolder.getTipsRecent()); update = true; } } else { mStateHolder.setTipsPopular(new Group<Tip>()); if (buttons.getSelectedButtonIndex() == 1) { mListAdapter.setGroup(mStateHolder.getTipsPopular()); update = true; } } NotificationsUtil.ToastReasonForFailure(this, ex); } if (recentOnly) { mStateHolder.setIsRunningTaskTipsRecent(false); mStateHolder.setRanOnceTipsRecent(true); if (mStateHolder.getTipsRecent().size() == 0 && buttons.getSelectedButtonIndex() == 0) { setEmptyView(mLayoutEmpty); } } else { mStateHolder.setIsRunningTaskTipsPopular(false); mStateHolder.setRanOnceTipsPopular(true); if (mStateHolder.getTipsPopular().size() == 0 && buttons.getSelectedButtonIndex() == 1) { setEmptyView(mLayoutEmpty); } } if (update) { mListAdapter.notifyDataSetChanged(); getListView().setSelection(0); } if (!mStateHolder.getIsRunningTaskTipsRecent() && !mStateHolder.getIsRunningTaskTipsPopular()) { setProgressBarIndeterminateVisibility(false); } }
private void onStartTaskTips() { if (mListAdapter != null) { if (mStateHolder.getRecentOnly()) { mStateHolder.setIsRunningTaskTipsRecent(true); mListAdapter.setGroup(mStateHolder.getTipsRecent()); } else { mStateHolder.setIsRunningTaskTipsPopular(true); mListAdapter.setGroup(mStateHolder.getTipsPopular()); } mListAdapter.notifyDataSetChanged(); } setProgressBarIndeterminateVisibility(true); setLoadingView(); }
@Override public void onPause() { super.onPause(); ((Foursquared) getApplication()).removeLocationUpdates(mSearchLocationObserver); if (isFinishing()) { mStateHolder.cancelTasks(); mListAdapter.removeObserver(); unregisterReceiver(mLoggedOutReceiver); } }
private void updateTip(Tip tip) { mStateHolder.updateTip(tip); mListAdapter.notifyDataSetInvalidated(); }
private void ensureUi() { LayoutInflater inflater = LayoutInflater.from(this); mLayoutEmpty = inflater.inflate(R.layout.tips_activity_empty, null); mLayoutEmpty.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); mListAdapter = new TipsListAdapter( this, ((Foursquared) getApplication()).getRemoteResourceManager(), R.layout.tip_venue_list_item); if (mStateHolder.getRecentOnly()) { mListAdapter.setGroup(mStateHolder.getTipsRecent()); if (mStateHolder.getTipsRecent().size() == 0) { if (mStateHolder.getRanOnceTipsRecent()) { setEmptyView(mLayoutEmpty); } else { setLoadingView(); } } } else { mListAdapter.setGroup(mStateHolder.getTipsPopular()); if (mStateHolder.getTipsPopular().size() == 0) { if (mStateHolder.getRanOnceTipsPopular()) { setEmptyView(mLayoutEmpty); } else { setLoadingView(); } } } SegmentedButton buttons = getHeaderButton(); buttons.clearButtons(); buttons.addButtons( getString(R.string.user_details_tips_activity_btn_recent), getString(R.string.user_details_tips_activity_btn_popular)); if (mStateHolder.mRecentOnly) { buttons.setPushedButtonIndex(0); } else { buttons.setPushedButtonIndex(1); } buttons.setOnClickListener( new OnClickListenerSegmentedButton() { @Override public void onClick(int index) { if (index == 0) { mStateHolder.setRecentOnly(true); mListAdapter.setGroup(mStateHolder.getTipsRecent()); if (mStateHolder.getTipsRecent().size() < 1) { if (mStateHolder.getRanOnceTipsRecent()) { setEmptyView(mLayoutEmpty); } else { setLoadingView(); mStateHolder.startTaskTips(UserDetailsTipsActivity.this, true); } } } else { mStateHolder.setRecentOnly(false); mListAdapter.setGroup(mStateHolder.getTipsPopular()); if (mStateHolder.getTipsPopular().size() < 1) { if (mStateHolder.getRanOnceTipsPopular()) { setEmptyView(mLayoutEmpty); } else { setLoadingView(); mStateHolder.startTaskTips(UserDetailsTipsActivity.this, false); } } } mListAdapter.notifyDataSetChanged(); getListView().setSelection(0); } }); ListView listView = getListView(); listView.setAdapter(mListAdapter); listView.setSmoothScrollbarEnabled(false); listView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Tip tip = (Tip) parent.getAdapter().getItem(position); Intent intent = new Intent(UserDetailsTipsActivity.this, TipActivity.class); intent.putExtra(TipActivity.EXTRA_TIP_PARCEL, tip); startActivityForResult(intent, ACTIVITY_TIP); } }); if (mStateHolder.getIsRunningTaskTipsRecent() || mStateHolder.getIsRunningTaskTipsPopular()) { setProgressBarIndeterminateVisibility(true); } else { setProgressBarIndeterminateVisibility(false); } setTitle(getString(R.string.user_details_tips_activity_title, mStateHolder.getUsername())); }