1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.dialer.app.filterednumber;
17 
18 import android.app.FragmentManager;
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.view.View;
22 import com.android.dialer.app.R;
23 import com.android.dialer.blocking.BlockNumberDialogFragment;
24 import com.android.dialer.contactphoto.ContactPhotoManager;
25 import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
26 import com.android.dialer.location.GeoUtil;
27 import com.android.dialer.logging.InteractionEvent;
28 import com.android.dialer.logging.Logger;
29 import com.android.dialer.phonenumbercache.ContactInfoHelper;
30 import com.android.dialer.phonenumberutil.PhoneNumberHelper;
31 
32 /** TODO(calderwoodra): documentation */
33 public class BlockedNumbersAdapter extends NumbersAdapter {
34 
BlockedNumbersAdapter( Context context, FragmentManager fragmentManager, ContactInfoHelper contactInfoHelper, ContactPhotoManager contactPhotoManager)35   private BlockedNumbersAdapter(
36       Context context,
37       FragmentManager fragmentManager,
38       ContactInfoHelper contactInfoHelper,
39       ContactPhotoManager contactPhotoManager) {
40     super(context, fragmentManager, contactInfoHelper, contactPhotoManager);
41   }
42 
newBlockedNumbersAdapter( Context context, FragmentManager fragmentManager)43   public static BlockedNumbersAdapter newBlockedNumbersAdapter(
44       Context context, FragmentManager fragmentManager) {
45     return new BlockedNumbersAdapter(
46         context,
47         fragmentManager,
48         new ContactInfoHelper(context, GeoUtil.getCurrentCountryIso(context)),
49         ContactPhotoManager.getInstance(context));
50   }
51 
52   @Override
bindView(View view, final Context context, Cursor cursor)53   public void bindView(View view, final Context context, Cursor cursor) {
54     super.bindView(view, context, cursor);
55     final Integer id = cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns._ID));
56     final String countryIso =
57         cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.COUNTRY_ISO));
58     final String number = cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.NUMBER));
59 
60     final View deleteButton = view.findViewById(R.id.delete_button);
61     deleteButton.setOnClickListener(
62         new View.OnClickListener() {
63           @Override
64           public void onClick(View view) {
65             BlockNumberDialogFragment.show(
66                 id,
67                 number,
68                 countryIso,
69                 PhoneNumberHelper.formatNumber(getContext(), number, countryIso),
70                 R.id.blocked_numbers_activity_container,
71                 getFragmentManager(),
72                 new BlockNumberDialogFragment.Callback() {
73                   @Override
74                   public void onFilterNumberSuccess() {}
75 
76                   @Override
77                   public void onUnfilterNumberSuccess() {
78                     Logger.get(context)
79                         .logInteraction(InteractionEvent.Type.UNBLOCK_NUMBER_MANAGEMENT_SCREEN);
80                   }
81 
82                   @Override
83                   public void onChangeFilteredNumberUndo() {}
84                 });
85           }
86         });
87 
88     updateView(view, number, countryIso);
89   }
90 
91   @Override
isEmpty()92   public boolean isEmpty() {
93     // Always return false, so that the header with blocking-related options always shows.
94     return false;
95   }
96 }
97