1/*
2 * Copyright (C) 2013 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
17package com.android.photos.adapters;
18
19import android.content.Context;
20import android.database.Cursor;
21import android.graphics.drawable.Drawable;
22import android.text.format.DateFormat;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.CursorAdapter;
27import android.widget.ImageView;
28import android.widget.ProgressBar;
29import android.widget.TextView;
30
31import com.android.gallery3d.R;
32import com.android.photos.data.AlbumSetLoader;
33import com.android.photos.shims.LoaderCompatShim;
34
35import java.util.Date;
36
37public class AlbumSetCursorAdapter extends CursorAdapter {
38
39    private LoaderCompatShim<Cursor> mDrawableFactory;
40
41    public void setDrawableFactory(LoaderCompatShim<Cursor> factory) {
42        mDrawableFactory = factory;
43    }
44
45    public AlbumSetCursorAdapter(Context context) {
46        super(context, null, false);
47    }
48
49    @Override
50    public void bindView(View v, Context context, Cursor cursor) {
51        TextView titleTextView = (TextView) v.findViewById(
52                R.id.album_set_item_title);
53        titleTextView.setText(cursor.getString(AlbumSetLoader.INDEX_TITLE));
54
55        TextView countTextView = (TextView) v.findViewById(
56                R.id.album_set_item_count);
57        int count = cursor.getInt(AlbumSetLoader.INDEX_COUNT);
58        countTextView.setText(context.getResources().getQuantityString(
59                R.plurals.number_of_photos, count, count));
60
61        ImageView thumbImageView = (ImageView) v.findViewById(
62                R.id.album_set_item_image);
63        Drawable recycle = thumbImageView.getDrawable();
64        Drawable drawable = mDrawableFactory.drawableForItem(cursor, recycle);
65        if (recycle != drawable) {
66            thumbImageView.setImageDrawable(drawable);
67        }
68    }
69
70    @Override
71    public View newView(Context context, Cursor cursor, ViewGroup parent) {
72        return LayoutInflater.from(context).inflate(
73                R.layout.album_set_item, parent, false);
74    }
75}
76