Home | History | Annotate | Download | only in list
      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.list;
     17 
     18 import android.content.Context;
     19 import android.content.res.Resources;
     20 import android.database.Cursor;
     21 import android.view.View;
     22 import com.android.contacts.common.list.ContactListItemView;
     23 import com.android.dialer.app.R;
     24 import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
     25 import com.android.dialer.location.GeoUtil;
     26 
     27 /** List adapter to display search results for adding a blocked number. */
     28 public class BlockedListSearchAdapter extends RegularSearchListAdapter {
     29 
     30   private Resources resources;
     31   private FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler;
     32 
     33   public BlockedListSearchAdapter(Context context) {
     34     super(context);
     35     resources = context.getResources();
     36     disableAllShortcuts();
     37     setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, true);
     38 
     39     filteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(context);
     40   }
     41 
     42   @Override
     43   protected boolean isChanged(boolean showNumberShortcuts) {
     44     return setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, showNumberShortcuts || isQuerySipAddress);
     45   }
     46 
     47   public void setViewBlocked(ContactListItemView view, Integer id) {
     48     view.setTag(R.id.block_id, id);
     49     final int textColor = resources.getColor(R.color.blocked_number_block_color);
     50     view.getDataView().setTextColor(textColor);
     51     view.getLabelView().setTextColor(textColor);
     52     //TODO: Add icon
     53   }
     54 
     55   public void setViewUnblocked(ContactListItemView view) {
     56     view.setTag(R.id.block_id, null);
     57     final int textColor = resources.getColor(R.color.dialer_secondary_text_color);
     58     view.getDataView().setTextColor(textColor);
     59     view.getLabelView().setTextColor(textColor);
     60     //TODO: Remove icon
     61   }
     62 
     63   @Override
     64   protected void bindView(View itemView, int partition, Cursor cursor, int position) {
     65     super.bindView(itemView, partition, cursor, position);
     66 
     67     final ContactListItemView view = (ContactListItemView) itemView;
     68     // Reset view state to unblocked.
     69     setViewUnblocked(view);
     70 
     71     final String number = getPhoneNumber(position);
     72     final String countryIso = GeoUtil.getCurrentCountryIso(mContext);
     73     final FilteredNumberAsyncQueryHandler.OnCheckBlockedListener onCheckListener =
     74         new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() {
     75           @Override
     76           public void onCheckComplete(Integer id) {
     77             if (id != null && id != FilteredNumberAsyncQueryHandler.INVALID_ID) {
     78               setViewBlocked(view, id);
     79             }
     80           }
     81         };
     82     filteredNumberAsyncQueryHandler.isBlockedNumber(onCheckListener, number, countryIso);
     83   }
     84 }
     85