From b26a9d56a7ea07c713f20511859d3344aeb1b4b4 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 28 Oct 2015 11:31:31 -0700 Subject: Call blocking normalization cleanup. - Remove unnecessary getter. + Reorganized arguments logic in FilterNumberDialogFragment. Bug: 25343277 Change-Id: I7541f21ed28794b4a5d73e0c6c6d895ca6402c77 --- .../database/FilteredNumberAsyncQueryHandler.java | 12 ++-------- .../filterednumber/FilterNumberDialogFragment.java | 27 +++++++++++++--------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java index 25613a6f8..db52e3134 100644 --- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java +++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java @@ -129,7 +129,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { public final boolean startBlockedQuery(final OnCheckBlockedListener listener, String normalizedNumber, String number, String countryIso) { if (normalizedNumber == null) { - normalizedNumber = getNormalizedNumber(number, countryIso); + normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); if (normalizedNumber == null) { return true; } @@ -138,14 +138,6 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { return false; } - public static String getNormalizedNumber(String number, String countryIso) { - if (PhoneNumberHelper.isUriNumber(number)) { - return number; - } else { - return PhoneNumberUtils.formatNumberToE164(number, countryIso); - } - } - /** * Check if the normalized number given has been blocked. */ @@ -182,7 +174,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { public final void blockNumber(final OnBlockNumberListener listener, String normalizedNumber, String number, String countryIso) { if (normalizedNumber == null) { - normalizedNumber = getNormalizedNumber(number, countryIso); + normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); } ContentValues v = new ContentValues(); v.put(FilteredNumberColumns.NORMALIZED_NUMBER, normalizedNumber); diff --git a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java index 8473e324a..4a45be24a 100644 --- a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java +++ b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java @@ -26,6 +26,7 @@ import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; import android.support.design.widget.Snackbar; +import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.view.View; import android.widget.Toast; @@ -58,8 +59,10 @@ public class FilterNumberDialogFragment extends DialogFragment { private static final String ARG_DISPLAY_NUMBER = "argDisplayNumber"; private static final String ARG_PARENT_VIEW_ID = "parentViewId"; + private String mNumber; private String mDisplayNumber; private String mNormalizedNumber; + private String mCountryIso; private FilteredNumberAsyncQueryHandler mHandler; private View mParentView; @@ -109,12 +112,16 @@ public class FilterNumberDialogFragment extends DialogFragment { super.onCreateDialog(savedInstanceState); final boolean isBlocked = getArguments().containsKey(ARG_BLOCK_ID); + mNumber = getArguments().getString(ARG_NUMBER); mDisplayNumber = getArguments().getString(ARG_DISPLAY_NUMBER); + mNormalizedNumber = getArguments().getString(ARG_NORMALIZED_NUMBER); + mCountryIso = getArguments().getString(ARG_COUNTRY_ISO); + if (TextUtils.isEmpty(mNormalizedNumber)) { - String number = getArguments().getString(ARG_NUMBER); - String countryIso = getArguments().getString(ARG_COUNTRY_ISO); - mNormalizedNumber = - FilteredNumberAsyncQueryHandler.getNormalizedNumber(number, countryIso); + mNormalizedNumber = PhoneNumberUtils.formatNumberToE164(mNumber, mCountryIso); + } + if (TextUtils.isEmpty(mDisplayNumber)) { + mDisplayNumber = mNumber; } mHandler = new FilteredNumberAsyncQueryHandler(getContext().getContentResolver()); @@ -148,11 +155,9 @@ public class FilterNumberDialogFragment extends DialogFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - String number = getArguments().getString(ARG_NUMBER); - if (TextUtils.isEmpty(mNormalizedNumber) || - !FilteredNumbersUtil.canBlockNumber(getActivity(), number)) { + if (!FilteredNumbersUtil.canBlockNumber(getActivity(), mNormalizedNumber)) { dismiss(); - Toast.makeText(getContext(), getString(R.string.invalidNumber, number), + Toast.makeText(getContext(), getString(R.string.invalidNumber, mDisplayNumber), Toast.LENGTH_SHORT).show(); } } @@ -222,9 +227,9 @@ public class FilterNumberDialogFragment extends DialogFragment { mHandler.blockNumber( onBlockNumberListener, - getArguments().getString(ARG_NORMALIZED_NUMBER), - getArguments().getString(ARG_NUMBER), - getArguments().getString(ARG_COUNTRY_ISO)); + mNormalizedNumber, + mNumber, + mCountryIso); } private void unblockNumber() { -- cgit v1.2.3