Home | History | Annotate | Download | only in filterednumber
      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.telephony.PhoneNumberUtils;
     22 import android.view.View;
     23 import com.android.contacts.common.ContactPhotoManager;
     24 import com.android.dialer.app.R;
     25 import com.android.dialer.blocking.BlockNumberDialogFragment;
     26 import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
     27 import com.android.dialer.location.GeoUtil;
     28 import com.android.dialer.logging.InteractionEvent;
     29 import com.android.dialer.logging.Logger;
     30 import com.android.dialer.phonenumbercache.ContactInfoHelper;
     31 
     32 public class BlockedNumbersAdapter extends NumbersAdapter {
     33 
     34   private BlockedNumbersAdapter(
     35       Context context,
     36       FragmentManager fragmentManager,
     37       ContactInfoHelper contactInfoHelper,
     38       ContactPhotoManager contactPhotoManager) {
     39     super(context, fragmentManager, contactInfoHelper, contactPhotoManager);
     40   }
     41 
     42   public static BlockedNumbersAdapter newBlockedNumbersAdapter(
     43       Context context, FragmentManager fragmentManager) {
     44     return new BlockedNumbersAdapter(
     45         context,
     46         fragmentManager,
     47         new ContactInfoHelper(context, GeoUtil.getCurrentCountryIso(context)),
     48         ContactPhotoManager.getInstance(context));
     49   }
     50 
     51   @Override
     52   public void bindView(View view, final Context context, Cursor cursor) {
     53     super.bindView(view, context, cursor);
     54     final Integer id = cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns._ID));
     55     final String countryIso =
     56         cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.COUNTRY_ISO));
     57     final String number = cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.NUMBER));
     58 
     59     final View deleteButton = view.findViewById(R.id.delete_button);
     60     deleteButton.setOnClickListener(
     61         new View.OnClickListener() {
     62           @Override
     63           public void onClick(View view) {
     64             BlockNumberDialogFragment.show(
     65                 id,
     66                 number,
     67                 countryIso,
     68                 PhoneNumberUtils.formatNumber(number, countryIso),
     69                 R.id.blocked_numbers_activity_container,
     70                 getFragmentManager(),
     71                 new BlockNumberDialogFragment.Callback() {
     72                   @Override
     73                   public void onFilterNumberSuccess() {}
     74 
     75                   @Override
     76                   public void onUnfilterNumberSuccess() {
     77                     Logger.get(context)
     78                         .logInteraction(InteractionEvent.Type.UNBLOCK_NUMBER_MANAGEMENT_SCREEN);
     79                   }
     80 
     81                   @Override
     82                   public void onChangeFilteredNumberUndo() {}
     83                 });
     84           }
     85         });
     86 
     87     updateView(view, number, countryIso);
     88   }
     89 
     90   @Override
     91   public boolean isEmpty() {
     92     // Always return false, so that the header with blocking-related options always shows.
     93     return false;
     94   }
     95 }
     96