use of com.simplecity.amp_library.http.lastfm.LastFmAlbum in project Shuttle by timusus.
the class BiographyDialog method getBiographyDialog.
private static MaterialDialog getBiographyDialog(final Context context, @BioType int type, String artistName, String albumName) {
@SuppressLint("InflateParams") View customView = LayoutInflater.from(context).inflate(R.layout.dialog_biography, null, false);
final ProgressBar progressBar = customView.findViewById(R.id.progress);
final TextView message = customView.findViewById(R.id.message);
Callback<LastFmArtist> artistCallback = new Callback<LastFmArtist>() {
@Override
public void onResponse(Call<LastFmArtist> call, Response<LastFmArtist> response) {
progressBar.setVisibility(View.GONE);
if (response != null && response.isSuccessful()) {
if (response.body() != null && response.body().artist != null && response.body().artist.bio != null) {
String summary = response.body().artist.bio.summary;
if (ShuttleUtils.hasNougat()) {
message.setText(Html.fromHtml(summary, Html.FROM_HTML_MODE_COMPACT));
} else {
message.setText(Html.fromHtml(summary));
}
} else {
message.setText(R.string.no_artist_info);
}
}
}
@Override
public void onFailure(Call<LastFmArtist> call, Throwable t) {
progressBar.setVisibility(View.GONE);
switch(type) {
case BioType.ARTIST:
message.setText(R.string.no_artist_info);
break;
case BioType.ALBUM:
message.setText(R.string.no_album_info);
break;
}
}
};
Callback<LastFmAlbum> albumCallback = new Callback<LastFmAlbum>() {
@Override
public void onResponse(Call<LastFmAlbum> call, Response<LastFmAlbum> response) {
progressBar.setVisibility(View.GONE);
if (response != null && response.isSuccessful()) {
if (response.body() != null && response.body().album != null && response.body().album.wiki != null) {
String summary = response.body().album.wiki.summary;
if (ShuttleUtils.hasNougat()) {
message.setText(Html.fromHtml(summary, Html.FROM_HTML_MODE_COMPACT));
} else {
message.setText(Html.fromHtml(summary));
}
} else {
message.setText(R.string.no_album_info);
}
}
}
@Override
public void onFailure(Call<LastFmAlbum> call, Throwable t) {
progressBar.setVisibility(View.GONE);
switch(type) {
case BioType.ARTIST:
message.setText(R.string.no_artist_info);
break;
case BioType.ALBUM:
message.setText(R.string.no_album_info);
break;
}
}
};
switch(type) {
case BioType.ARTIST:
HttpClient.getInstance().lastFmService.getLastFmArtistResult(artistName).enqueue(artistCallback);
break;
case BioType.ALBUM:
HttpClient.getInstance().lastFmService.getLastFmAlbumResult(artistName, albumName).enqueue(albumCallback);
break;
}
MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.info).customView(customView, false).negativeText(R.string.close);
return builder.build();
}
Aggregations