diff options
5 files changed, 58 insertions, 36 deletions
diff --git a/res/layout/blocked_number_fragment.xml b/res/layout/blocked_number_fragment.xml index 906e8a10c..c5760da3a 100644 --- a/res/layout/blocked_number_fragment.xml +++ b/res/layout/blocked_number_fragment.xml @@ -52,36 +52,28 @@ </android.support.v7.widget.CardView> - <android.support.v7.widget.CardView + + <LinearLayout + android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" - card_view:cardCornerRadius="0dp"> + android:background="@color/background_dialer_white"> - <LinearLayout - android:orientation="vertical" + <ListView android:id="@+id/blocked_numbers_list" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="@color/background_dialer_white"> - - <include layout="@layout/blocked_number_header" /> + android:layout_height="match_parent" + android:layout_weight="1" + android:drawSelectorOnTop="false" + android:headerDividersEnabled="false" /> - <ListView android:id="@id/android:list" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_weight="1" - android:drawSelectorOnTop="false" - android:headerDividersEnabled="false" /> - - <TextView android:id="@android:id/empty" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingStart="@dimen/blocked_number_horizontal_margin" - android:paddingTop="@dimen/blocked_number_top_margin" - android:paddingBottom="@dimen/blocked_number_bottom_margin" - android:text="@string/listNoBlockedNumbers" /> - - </LinearLayout> + <TextView android:id="@android:id/empty" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingStart="@dimen/blocked_number_horizontal_margin" + android:paddingTop="@dimen/blocked_number_top_margin" + android:paddingBottom="@dimen/blocked_number_bottom_margin" + android:text="@string/listNoBlockedNumbers" /> - </android.support.v7.widget.CardView> + </LinearLayout> </LinearLayout> diff --git a/res/layout/blocked_number_header.xml b/res/layout/blocked_number_header.xml index e16efbcf4..0c8c086e4 100644 --- a/res/layout/blocked_number_header.xml +++ b/res/layout/blocked_number_header.xml @@ -13,7 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. --> -<merge xmlns:android="http://schemas.android.com/apk/res/android"> +<android.support.v7.widget.CardView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:card_view="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + card_view:cardCornerRadius="0dp"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" @@ -72,4 +77,4 @@ android:layout_marginTop="8dp" android:text="@string/blockNumber" /> -</merge> +</android.support.v7.widget.CardView> diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java index 594ceebee..1987b809d 100644 --- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java +++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java @@ -131,8 +131,13 @@ public class DefaultVoicemailNotifier { NewCall newCall = itr.next(); // Skip notifying for numbers which are blocked. - if (FilteredNumbersUtil.isBlocked(mContext, newCall.number, newCall.countryIso)) { + if (FilteredNumbersUtil.shouldBlockVoicemail( + mContext, newCall.number, newCall.countryIso, newCall.dateMs)) { itr.remove(); + + if (FilteredNumbersUtil.shouldHideBlockedCalls(mContext)) { + mContext.getContentResolver().delete(newCall.voicemailUri, null, null); + } continue; } @@ -236,6 +241,7 @@ public class DefaultVoicemailNotifier { public final String accountId; public final String transcription; public final String countryIso; + public final long dateMs; public NewCall( Uri callsUri, @@ -245,7 +251,8 @@ public class DefaultVoicemailNotifier { String accountComponentName, String accountId, String transcription, - String countryIso) { + String countryIso, + long dateMs) { this.callsUri = callsUri; this.voicemailUri = voicemailUri; this.number = number; @@ -254,6 +261,7 @@ public class DefaultVoicemailNotifier { this.accountId = accountId; this.transcription = transcription; this.countryIso = countryIso; + this.dateMs = dateMs; } } @@ -284,7 +292,8 @@ public class DefaultVoicemailNotifier { Calls.PHONE_ACCOUNT_COMPONENT_NAME, Calls.PHONE_ACCOUNT_ID, Calls.TRANSCRIPTION, - Calls.COUNTRY_ISO + Calls.COUNTRY_ISO, + Calls.DATE }; private static final int ID_COLUMN_INDEX = 0; private static final int NUMBER_COLUMN_INDEX = 1; @@ -294,6 +303,7 @@ public class DefaultVoicemailNotifier { private static final int PHONE_ACCOUNT_ID_COLUMN_INDEX = 5; private static final int TRANSCRIPTION_COLUMN_INDEX = 6; private static final int COUNTRY_ISO_COLUMN_INDEX = 7; + private static final int DATE_COLUMN_INDEX = 8; private final ContentResolver mContentResolver; private final Context mContext; @@ -345,7 +355,8 @@ public class DefaultVoicemailNotifier { cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME_COLUMN_INDEX), cursor.getString(PHONE_ACCOUNT_ID_COLUMN_INDEX), cursor.getString(TRANSCRIPTION_COLUMN_INDEX), - cursor.getString(COUNTRY_ISO_COLUMN_INDEX)); + cursor.getString(COUNTRY_ISO_COLUMN_INDEX), + cursor.getLong(DATE_COLUMN_INDEX)); } } diff --git a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java index 728d8b287..06ae0e084 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java @@ -17,12 +17,14 @@ package com.android.dialer.filterednumber; import android.app.ListFragment; import android.app.LoaderManager; +import android.content.Context; import android.content.CursorLoader; import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; import android.widget.CompoundButton; +import android.widget.ListView; import android.widget.Switch; import android.view.LayoutInflater; import android.view.View; @@ -87,6 +89,12 @@ public class BlockedNumberFragment extends ListFragment implements @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + LayoutInflater inflater = + (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + ListView listView = (ListView) getActivity().findViewById(R.id.blocked_numbers_list); + listView.addHeaderView(inflater.inflate(R.layout.blocked_number_header, null)); + getLoaderManager().initLoader(0, null, this); } diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java index 0e162acfa..ac3d16e34 100644 --- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java +++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java @@ -191,7 +191,8 @@ public class FilteredNumbersUtil { * WARNING: This method should NOT be executed on the UI thread. * Use {@code FilteredNumberAsyncQueryHandler} to asynchronously check if a number is blocked. */ - public static boolean isBlocked(Context context, String number, String countryIso) { + public static boolean shouldBlockVoicemail( + Context context, String number, String countryIso, long dateMs) { final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); if (TextUtils.isEmpty(normalizedNumber)) { return false; @@ -199,21 +200,26 @@ public class FilteredNumbersUtil { final Cursor cursor = context.getContentResolver().query( FilteredNumber.CONTENT_URI, - new String[] { FilteredNumberColumns._ID }, + new String[] { + FilteredNumberColumns.CREATION_TIME + }, FilteredNumberColumns.NORMALIZED_NUMBER + "=?", new String[] { normalizedNumber }, null); - boolean isBlocked = false; + boolean shouldBlock = false; if (cursor != null) { try { - isBlocked = cursor.getCount() > 0; + cursor.moveToFirst(); + + // Block if number is found and it was added before this voicemail was received. + shouldBlock = cursor.getCount() > 0 && dateMs > cursor.getLong(0); } finally { cursor.close(); } } - return isBlocked; + return shouldBlock; } public static boolean shouldHideBlockedCalls(Context context) { |