Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2008 Esmertec AG.
      3  * Copyright (C) 2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mms.ui;
     19 
     20 import com.android.mms.R;
     21 import com.android.mms.data.Conversation;
     22 
     23 import android.content.Context;
     24 import android.database.Cursor;
     25 import android.util.Log;
     26 import android.view.LayoutInflater;
     27 import android.view.View;
     28 import android.view.ViewGroup;
     29 import android.widget.AbsListView;
     30 import android.widget.CursorAdapter;
     31 
     32 /**
     33  * The back-end data adapter for ConversationList.
     34  */
     35 //TODO: This should be public class ConversationListAdapter extends ArrayAdapter<Conversation>
     36 public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
     37     private static final String TAG = "ConversationListAdapter";
     38     private static final boolean LOCAL_LOGV = false;
     39 
     40     private final LayoutInflater mFactory;
     41     private OnContentChangedListener mOnContentChangedListener;
     42 
     43     public ConversationListAdapter(Context context, Cursor cursor) {
     44         super(context, cursor, false /* auto-requery */);
     45         mFactory = LayoutInflater.from(context);
     46     }
     47 
     48     @Override
     49     public void bindView(View view, Context context, Cursor cursor) {
     50         if (!(view instanceof ConversationListItem)) {
     51             Log.e(TAG, "Unexpected bound view: " + view);
     52             return;
     53         }
     54 
     55         ConversationListItem headerView = (ConversationListItem) view;
     56         Conversation conv = Conversation.from(context, cursor);
     57 
     58         ConversationListItemData ch = new ConversationListItemData(context, conv);
     59         headerView.bind(context, ch);
     60     }
     61 
     62     public void onMovedToScrapHeap(View view) {
     63         ConversationListItem headerView = (ConversationListItem)view;
     64         headerView.unbind();
     65     }
     66 
     67     @Override
     68     public View newView(Context context, Cursor cursor, ViewGroup parent) {
     69         if (LOCAL_LOGV) Log.v(TAG, "inflating new view");
     70         return mFactory.inflate(R.layout.conversation_list_item, parent, false);
     71     }
     72 
     73     public interface OnContentChangedListener {
     74         void onContentChanged(ConversationListAdapter adapter);
     75     }
     76 
     77     public void setOnContentChangedListener(OnContentChangedListener l) {
     78         mOnContentChangedListener = l;
     79     }
     80 
     81     @Override
     82     protected void onContentChanged() {
     83         if (mCursor != null && !mCursor.isClosed()) {
     84             if (mOnContentChangedListener != null) {
     85                 mOnContentChangedListener.onContentChanged(this);
     86             }
     87         }
     88     }
     89 }
     90