OSDN Git Service

Migrate to AndroidX
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / 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 org.lineageos.eleven.adapters;
17
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;
24
25 import androidx.loader.content.Loader;
26
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;
32
33 import java.util.List;
34
35 public abstract class ArtistDetailSongAdapter extends DetailSongAdapter {
36     public ArtistDetailSongAdapter(Activity activity) {
37         super(activity);
38     }
39
40     protected int rowLayoutId() { return R.layout.artist_detail_song; }
41
42     protected Config.IdType getSourceType() {
43         return Config.IdType.Artist;
44     }
45
46     @Override // LoaderCallbacks
47     public Loader<List<Song>> onCreateLoader(int id, Bundle args) {
48         onLoading();
49         setSourceId(args.getLong(Config.ID));
50         final String selection = MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + getSourceId();
51         return new SongLoader(mActivity, selection);
52     }
53
54     protected Holder newHolder(View root, ImageFetcher fetcher) {
55         return new ArtistHolder(root, fetcher);
56     }
57
58     private static class ArtistHolder extends Holder {
59         ImageView art;
60         TextView album;
61
62         protected ArtistHolder(View root, ImageFetcher fetcher) {
63             super(root, fetcher);
64             art = (ImageView)root.findViewById(R.id.album_art);
65             album = (TextView)root.findViewById(R.id.album);
66         }
67
68         protected void update(Song song) {
69             title.setText(song.mSongName);
70             album.setText(song.mAlbumName);
71
72             if (song.mAlbumId >= 0) {
73                 fetcher.loadAlbumImage(song.mArtistName, song.mAlbumName, song.mAlbumId, art);
74             }
75         }
76     }
77 }