From f93604f330b592f6e572ce7631f779f1f05de731 Mon Sep 17 00:00:00 2001 From: Brandon Maxwell Date: Mon, 29 Feb 2016 19:57:43 -0800 Subject: Hiding add number button in Blocked Management UI + When new filtering is possible, we should hide the add number button from the blocked numbers management UI. + Added method to FilteredNumberCompat to check if it's possible to use the new filtering implementation. This is needed because prior to migrating to new filtering, users need to be able to unblock numbers. Just checking the SDK version is not sufficient, we need to know if the user has migrated their numbers. Bug=26664600 Change-Id: I60433465074911f13a26736221ddacc9a8bbcf88 --- .../android/dialer/compat/FilteredNumberCompat.java | 14 ++++++++++++-- .../dialer/filterednumber/BlockedNumbersFragment.java | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java index c70df71b7..63a2a32cd 100644 --- a/src/com/android/dialer/compat/FilteredNumberCompat.java +++ b/src/com/android/dialer/compat/FilteredNumberCompat.java @@ -99,15 +99,25 @@ public class FilteredNumberCompat { } /** - * @return {@code true} if the new filtering is enabled, {@code false} otherwise. + * @return {@code true} if the current SDK version supports using new filtering, {@code false} + * otherwise. */ - public static boolean useNewFiltering() { + public static boolean canUseNewFiltering() { if (isEnabledForTest != null) { return CompatUtils.isNCompatible() && isEnabledForTest; } return CompatUtils.isNCompatible() && isNewFilteringEnabled; } + /** + * @return {@code true} if the new filtering should be used, i.e. it's enabled and any necessary + * migration has been performed, {@code false} otherwise. + */ + public static boolean useNewFiltering() { + // TODO(maxwelb): Add shared preference for when the Dialer blocked list has been migrated + return canUseNewFiltering(); + } + @NeededForTesting public static void setIsEnabledForTest(Boolean isEnabled) { isEnabledForTest = isEnabled; diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java index a8786609b..38615cce8 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java @@ -32,8 +32,10 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import com.android.contacts.common.compat.CompatUtils; import com.android.contacts.common.lettertiles.LetterTileDrawable; import com.android.dialer.R; +import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberContract; import com.android.dialer.filterednumber.FilteredNumbersUtil.CheckForSendToVoicemailContactListener; import com.android.dialer.filterednumber.FilteredNumbersUtil.ImportSendToVoicemailContactsListener; @@ -83,7 +85,7 @@ public class BlockedNumbersFragment extends ListFragment mBlockedNumbersDisabledForEmergency = getListView().findViewById(R.id.blocked_numbers_disabled_for_emergency); mBlockedNumberListDivider = getActivity().findViewById(R.id.blocked_number_list_divider); - getListView().findViewById(R.id.import_button).setOnClickListener(this);; + getListView().findViewById(R.id.import_button).setOnClickListener(this); getListView().findViewById(R.id.view_numbers_button).setOnClickListener(this); getListView().findViewById(R.id.add_number_linear_layout).setOnClickListener(this); @@ -118,6 +120,15 @@ public class BlockedNumbersFragment extends ListFragment actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(R.string.manage_blocked_numbers_label); + // If the device can use the framework blocking solution, users should not be able to add + // new blocked numbers from the Blocked Management UI. They will be shown a promo card + // asking them to migrate to new blocking instead. + if (FilteredNumberCompat.canUseNewFiltering()) { + getListView().findViewById(R.id.add_number_linear_layout).setVisibility(View.GONE); + getListView().findViewById(R.id.add_number_linear_layout).setOnClickListener(null); + mBlockedNumberListDivider.setVisibility(View.INVISIBLE); + } + FilteredNumbersUtil.checkForSendToVoicemailContact( getActivity(), new CheckForSendToVoicemailContactListener() { @Override @@ -152,16 +163,15 @@ public class BlockedNumbersFragment extends ListFragment }; final String selection = FilteredNumberContract.FilteredNumberColumns.TYPE + "=" + FilteredNumberContract.FilteredNumberTypes.BLOCKED_NUMBER; - final CursorLoader cursorLoader = new CursorLoader( + return new CursorLoader( getContext(), FilteredNumberContract.FilteredNumber.CONTENT_URI, projection, selection, null, null); - return cursorLoader; } @Override public void onLoadFinished(Loader loader, Cursor data) { mAdapter.swapCursor(data); - if (data.getCount() == 0) { + if (FilteredNumberCompat.canUseNewFiltering() || data.getCount() == 0) { mBlockedNumberListDivider.setVisibility(View.INVISIBLE); } else { mBlockedNumberListDivider.setVisibility(View.VISIBLE); -- cgit v1.2.3