diff options
author | Andrew Lee <anwlee@google.com> | 2014-04-17 17:32:17 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-04-17 17:32:17 +0000 |
commit | 1375a1a62d9962bc6bc89edb983ecca72c5b1279 (patch) | |
tree | 4e3a882c54d6e09e398d95adde3efad4402afb34 | |
parent | f653040adb93cafdd8f9cd4fdfa5f69ed0b1f77d (diff) | |
parent | 5c2a2743026ec6f9ba0ae37f3de768ba7a8a9935 (diff) |
Merge "Only show voicemail tab if there is at least one active provider."
-rw-r--r-- | src/com/android/dialer/calllog/CallLogActivity.java | 52 | ||||
-rw-r--r-- | src/com/android/dialer/list/ViewPagerTabs.java | 2 |
2 files changed, 47 insertions, 7 deletions
diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index cdd0baff1..0e6a0a328 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.content.Intent; +import android.database.Cursor; import android.os.Bundle; import android.provider.CallLog.Calls; import android.support.v13.app.FragmentPagerAdapter; @@ -31,14 +32,17 @@ import android.view.MenuItem; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.list.ViewPagerTabs; +import com.android.dialer.voicemail.VoicemailStatusHelper; +import com.android.dialer.voicemail.VoicemailStatusHelperImpl; -public class CallLogActivity extends Activity { - +public class CallLogActivity extends Activity implements CallLogQueryHandler.Listener { private ViewPager mViewPager; + private ViewPagerTabs mViewPagerTabs; private ViewPagerAdapter mViewPagerAdapter; private CallLogFragment mAllCallsFragment; private CallLogFragment mMissedCallsFragment; private CallLogFragment mVoicemailFragment; + private VoicemailStatusHelper mVoicemailStatusHelper; private String[] mTabTitles; @@ -46,7 +50,10 @@ public class CallLogActivity extends Activity { private static final int TAB_INDEX_MISSED = 1; private static final int TAB_INDEX_VOICEMAIL = 2; - private static final int TAB_INDEX_COUNT = 3; + private static final int TAB_INDEX_COUNT_DEFAULT = 2; + private static final int TAB_INDEX_COUNT_WITH_VOICEMAIL = 3; + + private boolean mHasActiveVoicemailProvider; public class ViewPagerAdapter extends FragmentPagerAdapter { public ViewPagerAdapter(FragmentManager fm) { @@ -76,7 +83,8 @@ public class CallLogActivity extends Activity { @Override public int getCount() { - return TAB_INDEX_COUNT; + return mHasActiveVoicemailProvider ? TAB_INDEX_COUNT_WITH_VOICEMAIL : + TAB_INDEX_COUNT_DEFAULT; } } @@ -92,7 +100,7 @@ public class CallLogActivity extends Activity { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(true); - mTabTitles = new String[TAB_INDEX_COUNT]; + mTabTitles = new String[TAB_INDEX_COUNT_WITH_VOICEMAIL]; mTabTitles[0] = getString(R.string.call_log_all_title); mTabTitles[1] = getString(R.string.call_log_missed_title); mTabTitles[2] = getString(R.string.call_log_voicemail_title); @@ -103,8 +111,18 @@ public class CallLogActivity extends Activity { mViewPager.setAdapter(mViewPagerAdapter); mViewPager.setOffscreenPageLimit(2); - ViewPagerTabs tabs = (ViewPagerTabs) findViewById(R.id.viewpager_header); - tabs.setViewPager(mViewPager); + mViewPagerTabs = (ViewPagerTabs) findViewById(R.id.viewpager_header); + mViewPagerTabs.setViewPager(mViewPager); + + mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); + } + + @Override + protected void onResume() { + super.onResume(); + CallLogQueryHandler callLogQueryHandler = + new CallLogQueryHandler(this.getContentResolver(), this); + callLogQueryHandler.fetchVoicemailStatus(); } @Override @@ -140,4 +158,24 @@ public class CallLogActivity extends Activity { } return super.onOptionsItemSelected(item); } + + @Override + public void onVoicemailStatusFetched(Cursor statusCursor) { + if (this.isFinishing()) { + return; + } + + // Update mHasActiveVoicemailProvider, which controls the number of tabs displayed. + int activeSources = mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor); + if (activeSources > 0 != mHasActiveVoicemailProvider) { + mHasActiveVoicemailProvider = activeSources > 0; + mViewPagerAdapter.notifyDataSetChanged(); + mViewPagerTabs.setViewPager(mViewPager); + } + } + + @Override + public void onCallsFetched(Cursor statusCursor) { + // Do nothing. Implemented to satisfy CallLogQueryHandler.Listener. + } }
\ No newline at end of file diff --git a/src/com/android/dialer/list/ViewPagerTabs.java b/src/com/android/dialer/list/ViewPagerTabs.java index 7e6c78061..a538d09d0 100644 --- a/src/com/android/dialer/list/ViewPagerTabs.java +++ b/src/com/android/dialer/list/ViewPagerTabs.java @@ -113,6 +113,8 @@ public class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnP } private void addTabs(PagerAdapter adapter) { + mChild.removeAllViews(); + final int count = adapter.getCount(); for (int i = 0; i < count; i++) { addTab(adapter.getPageTitle(i), i); |