blob: 40d0eafb89bd50a64cfa59f291c7f16b65c9ea44 [file] [log] [blame]
/*
* Copyright (C) 2008 Esmertec AG.
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.mms.ui;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CursorAdapter;
import com.android.mms.R;
import com.android.mms.data.Conversation;
/**
* The back-end data adapter for ConversationList.
*/
//TODO: This should be public class ConversationListAdapter extends ArrayAdapter<Conversation>
public class ConversationListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
private static final String TAG = "ConversationListAdapter";
private static final boolean LOCAL_LOGV = false;
private final LayoutInflater mFactory;
private OnContentChangedListener mOnContentChangedListener;
public ConversationListAdapter(Context context, Cursor cursor) {
super(context, cursor, false /* auto-requery */);
mFactory = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (!(view instanceof ConversationListItem)) {
Log.e(TAG, "Unexpected bound view: " + view);
return;
}
ConversationListItem headerView = (ConversationListItem) view;
Conversation conv = Conversation.from(context, cursor);
headerView.bind(context, conv);
}
public void onMovedToScrapHeap(View view) {
ConversationListItem headerView = (ConversationListItem)view;
headerView.unbind();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
if (LOCAL_LOGV) Log.v(TAG, "inflating new view");
return mFactory.inflate(R.layout.conversation_list_item, parent, false);
}
public interface OnContentChangedListener {
void onContentChanged(ConversationListAdapter adapter);
}
public void setOnContentChangedListener(OnContentChangedListener l) {
mOnContentChangedListener = l;
}
@Override
protected void onContentChanged() {
if (mCursor != null && !mCursor.isClosed()) {
if (mOnContentChangedListener != null) {
mOnContentChangedListener.onContentChanged(this);
}
}
}
public void uncheckAll() {
int count = getCount();
for (int i = 0; i < count; i++) {
Cursor cursor = (Cursor)getItem(i);
Conversation conv = Conversation.from(mContext, cursor);
conv.setIsChecked(false);
}
}
}