This repository was archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathAlbumArtist.java
More file actions
163 lines (135 loc) · 4.02 KB
/
AlbumArtist.java
File metadata and controls
163 lines (135 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.simplecity.amp_library.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.annimon.stream.Stream;
import com.simplecity.amp_library.utils.ComparisonUtils;
import com.simplecity.amp_library.utils.DataManager;
import com.simplecity.amp_library.utils.StringUtils;
import io.reactivex.Single;
import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class AlbumArtist implements
Serializable,
Comparable<AlbumArtist>,
ArtworkProvider,
Sortable {
public String name;
public List<Album> albums = new ArrayList<>();
private String sortKey;
public AlbumArtist(String name, List<Album> albums) {
this.name = name;
this.albums = albums;
}
public Single<List<Song>> getSongsSingle() {
return DataManager.getInstance().getSongsObservable(song -> Stream.of(albums)
.map(album -> album.id)
.anyMatch(albumId -> albumId == song.albumId))
.first(Collections.emptyList());
}
@Override
public String getSortKey() {
if (sortKey == null) {
setSortKey();
}
return sortKey;
}
@Override
public void setSortKey() {
sortKey = StringUtils.keyFor(name);
}
@Override
@NonNull
public String getArtworkKey() {
return name;
}
public static class Builder {
private String name;
private List<Album> albums = new ArrayList<>();
public Builder name(String name) {
this.name = name;
return this;
}
public Builder albums(List<Album> albums) {
this.albums = albums;
return this;
}
public Builder album(Album album) {
this.albums.add(album);
return this;
}
public AlbumArtist build() {
return new AlbumArtist(this.name, this.albums);
}
}
public int getNumAlbums() {
return albums.size();
}
public int getNumSongs() {
int numSongs = 0;
for (Album album : albums) {
numSongs += album.numSongs;
}
return numSongs;
}
@Override
public String toString() {
return "AlbumArtist{" +
"name='" + name + '\'' +
", albums=" + albums +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AlbumArtist that = (AlbumArtist) o;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
return albums != null ? albums.equals(that.albums) : that.albums == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (albums != null ? albums.hashCode() : 0);
return result;
}
@Nullable
@Override
public String getRemoteArtworkUrl() {
try {
return "https://artwork.shuttlemusicplayer.app/api/v1/artwork?artist=" + URLEncoder.encode(name, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
return null;
}
}
@Nullable
@Override
public InputStream getMediaStoreArtwork() {
return null;
}
@Nullable
@Override
public InputStream getFolderArtwork() {
return null;
}
@Nullable
@Override
public InputStream getTagArtwork() {
return null;
}
@Nullable
@Override
public List<File> getFolderArtworkFiles() {
return Collections.emptyList();
}
@Override
public int compareTo(@NonNull AlbumArtist albumArtist) {
return ComparisonUtils.compare(getSortKey(), albumArtist.getSortKey());
}
}