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.view.View;
22 import android.widget.ImageView;
23 import android.widget.TextView;
25 import androidx.loader.content.Loader;
27 import org.lineageos.eleven.Config;
28 import org.lineageos.eleven.R;
29 import org.lineageos.eleven.cache.ImageFetcher;
30 import org.lineageos.eleven.loaders.SongLoader;
31 import org.lineageos.eleven.model.Song;
33 import java.util.List;
35 public abstract class ArtistDetailSongAdapter extends DetailSongAdapter {
36 public ArtistDetailSongAdapter(Activity activity) {
40 protected int rowLayoutId() { return R.layout.artist_detail_song; }
42 protected Config.IdType getSourceType() {
43 return Config.IdType.Artist;
46 @Override // LoaderCallbacks
47 public Loader<List<Song>> onCreateLoader(int id, Bundle args) {
49 setSourceId(args.getLong(Config.ID));
50 final String selection = MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + getSourceId();
51 return new SongLoader(mActivity, selection);
54 protected Holder newHolder(View root, ImageFetcher fetcher) {
55 return new ArtistHolder(root, fetcher);
58 private static class ArtistHolder extends Holder {
62 protected ArtistHolder(View root, ImageFetcher fetcher) {
64 art = (ImageView)root.findViewById(R.id.album_art);
65 album = (TextView)root.findViewById(R.id.album);
68 protected void update(Song song) {
69 title.setText(song.mSongName);
70 album.setText(song.mAlbumName);
72 if (song.mAlbumId >= 0) {
73 fetcher.loadAlbumImage(song.mArtistName, song.mAlbumName, song.mAlbumId, art);