2 * Copyright (C) 2014 The CyanogenMod Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.lineageos.eleven.adapters;
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;
26 import org.lineageos.eleven.Config;
27 import org.lineageos.eleven.R;
28 import org.lineageos.eleven.cache.ImageFetcher;
29 import org.lineageos.eleven.loaders.SongLoader;
30 import org.lineageos.eleven.model.Song;
32 import java.util.List;
34 public abstract class ArtistDetailSongAdapter extends DetailSongAdapter {
35 public ArtistDetailSongAdapter(Activity activity) {
39 protected int rowLayoutId() { return R.layout.artist_detail_song; }
41 protected Config.IdType getSourceType() {
42 return Config.IdType.Artist;
45 @Override // LoaderCallbacks
46 public Loader<List<Song>> onCreateLoader(int id, Bundle args) {
48 setSourceId(args.getLong(Config.ID));
49 final String selection = MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + getSourceId();
50 return new SongLoader(mActivity, selection);
53 protected Holder newHolder(View root, ImageFetcher fetcher) {
54 return new ArtistHolder(root, fetcher);
57 private static class ArtistHolder extends Holder {
61 protected ArtistHolder(View root, ImageFetcher fetcher) {
63 art = (ImageView)root.findViewById(R.id.album_art);
64 album = (TextView)root.findViewById(R.id.album);
67 protected void update(Song song) {
68 title.setText(song.mSongName);
69 album.setText(song.mAlbumName);
71 if (song.mAlbumId >= 0) {
72 fetcher.loadAlbumImage(song.mArtistName, song.mAlbumName, song.mAlbumId, art);