OSDN Git Service

1da8464f012ad0c212df1b6d4fe8d679316bb8d1
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / adapters / ArtistDetailSongAdapter.java
1 /*
2 * Copyright (C) 2014 The CyanogenMod 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.cyanogenmod.eleven.adapters;
17
18 import android.app.Activity;
19 import android.os.Bundle;
20 import android.provider.MediaStore;
21 import android.support.v4.content.Loader;
22 import android.view.View;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25
26 import com.cyanogenmod.eleven.Config;
27 import com.cyanogenmod.eleven.R;
28 import com.cyanogenmod.eleven.cache.ImageFetcher;
29 import com.cyanogenmod.eleven.loaders.SongLoader;
30 import com.cyanogenmod.eleven.model.Song;
31
32 import java.util.List;
33
34 public abstract class ArtistDetailSongAdapter extends DetailSongAdapter {
35     public ArtistDetailSongAdapter(Activity activity) {
36         super(activity);
37     }
38
39     protected int rowLayoutId() { return R.layout.artist_detail_song; }
40
41     protected Config.IdType getSourceType() {
42         return Config.IdType.Artist;
43     }
44
45     @Override // LoaderCallbacks
46     public Loader<List<Song>> onCreateLoader(int id, Bundle args) {
47         onLoading();
48         setSourceId(args.getLong(Config.ID));
49         final String selection = MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + getSourceId();
50         return new SongLoader(mActivity, selection);
51     }
52
53     protected Holder newHolder(View root, ImageFetcher fetcher) {
54         return new ArtistHolder(root, fetcher);
55     }
56
57     private static class ArtistHolder extends Holder {
58         ImageView art;
59         TextView album;
60
61         protected ArtistHolder(View root, ImageFetcher fetcher) {
62             super(root, fetcher);
63             art = (ImageView)root.findViewById(R.id.album_art);
64             album = (TextView)root.findViewById(R.id.album);
65         }
66
67         protected void update(Song song) {
68             title.setText(song.mSongName);
69             album.setText(song.mAlbumName);
70
71             if (song.mAlbumId >= 0) {
72                 fetcher.loadAlbumImage(song.mArtistName, song.mAlbumName, song.mAlbumId, art);
73             }
74         }
75     }
76 }