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.LogTag;
     22 import com.android.mms.data.Conversation;
     23 
     24 import android.content.Context;
     25 import android.database.Cursor;
     26 import android.util.Log;
     27 import android.view.LayoutInflater;
     28 import android.view.View;
     29 import android.view.ViewGroup;
     30 import android.widget.AbsListView;
     31 import android.widget.CursorAdapter;
     32 
     33 /**
     34  * The back-end data adapter for ConversationList.
     35  */
     36 //TODO: This should be public class ConversationListAdapter extends ArrayAdapter<Conversation>
     37 public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
     38     private static final String TAG = "ConversationListAdapter";
     39     private static final boolean LOCAL_LOGV = false;
     40 
     41     private final LayoutInflater mFactory;
     42     private OnContentChangedListener mOnContentChangedListener;
     43 
     44     public ConversationListAdapter(Context context, Cursor cursor) {
     45         super(context, cursor, false /* auto-requery */);
     46         mFactory = LayoutInflater.from(context);
     47     }
     48 
     49     @Override
     50     public void bindView(View view, Context context, Cursor cursor) {
     51         if (!(view instanceof ConversationListItem)) {
     52             Log.e(TAG, "Unexpected bound view: " + view);
     53             return;
     54         }
     55 
     56         ConversationListItem headerView = (ConversationListItem) view;
     57         Conversation conv = Conversation.from(context, cursor);
     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