Merge pull request #178 from Materight/lastfm
Added localized biography and wiki for albums
This commit is contained in:
commit
28e23635de
40 changed files with 213 additions and 82 deletions
|
|
@ -5,18 +5,23 @@ import android.content.Intent;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
|
|
@ -34,6 +39,8 @@ import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
|||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.model.LastFmAlbum;
|
||||
import com.kabouzeid.gramophone.loader.AlbumLoader;
|
||||
import com.kabouzeid.gramophone.misc.SimpleObservableScrollViewCallbacks;
|
||||
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
|
||||
|
|
@ -45,8 +52,13 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Be careful when changing things in this Activity!
|
||||
|
|
@ -81,6 +93,11 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
private int toolbarColor;
|
||||
private float toolbarAlpha;
|
||||
|
||||
@Nullable
|
||||
private Spanned wiki;
|
||||
private MaterialDialog wikiDialog;
|
||||
private LastFMRestClient lastFMRestClient;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -89,6 +106,8 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
|
||||
supportPostponeEnterTransition();
|
||||
|
||||
lastFMRestClient = new LastFMRestClient(this);
|
||||
|
||||
setUpObservableListViewParams();
|
||||
setUpToolBar();
|
||||
setUpViews();
|
||||
|
|
@ -233,6 +252,49 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
return true;
|
||||
}
|
||||
|
||||
private void loadWiki() {
|
||||
loadWiki(Locale.getDefault().getLanguage());
|
||||
}
|
||||
|
||||
private void loadWiki(@Nullable final String lang) {
|
||||
wiki = null;
|
||||
|
||||
lastFMRestClient.getApiService()
|
||||
.getAlbumInfo(getAlbum().getTitle(), getAlbum().getArtistName(), lang)
|
||||
.enqueue(new Callback<LastFmAlbum>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<LastFmAlbum> call, @NonNull Response<LastFmAlbum> response) {
|
||||
final LastFmAlbum lastFmAlbum = response.body();
|
||||
if (lastFmAlbum != null && lastFmAlbum.getAlbum() != null && lastFmAlbum.getAlbum().getWiki() != null) {
|
||||
final String wikiContent = lastFmAlbum.getAlbum().getWiki().getContent();
|
||||
if (wikiContent != null && !wikiContent.trim().isEmpty()) {
|
||||
wiki = Html.fromHtml(wikiContent);
|
||||
}
|
||||
}
|
||||
|
||||
// If the "lang" parameter is set and no wiki is given, retry with default language
|
||||
if (wiki == null && lang != null) {
|
||||
loadWiki(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util.isAllowedToDownloadMetadata(AlbumDetailActivity.this)) {
|
||||
if (wiki != null) {
|
||||
wikiDialog.setContent(wiki);
|
||||
} else {
|
||||
wikiDialog.dismiss();
|
||||
Toast.makeText(AlbumDetailActivity.this, getResources().getString(R.string.wiki_unavailable), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<LastFmAlbum> call, @NonNull Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
|
@ -257,6 +319,25 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
case R.id.action_go_to_artist:
|
||||
NavigationUtil.goToArtist(this, getAlbum().getArtistId());
|
||||
return true;
|
||||
case R.id.action_wiki:
|
||||
if (wikiDialog == null) {
|
||||
wikiDialog = new MaterialDialog.Builder(this)
|
||||
.title(album.getTitle())
|
||||
.positiveText(android.R.string.ok)
|
||||
.build();
|
||||
}
|
||||
if (Util.isAllowedToDownloadMetadata(this)) {
|
||||
if (wiki != null) {
|
||||
wikiDialog.setContent(wiki);
|
||||
wikiDialog.show();
|
||||
} else {
|
||||
Toast.makeText(this, getResources().getString(R.string.wiki_unavailable), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
wikiDialog.show();
|
||||
loadWiki();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
@ -323,6 +404,11 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
private void setAlbum(Album album) {
|
||||
this.album = album;
|
||||
loadAlbumCover();
|
||||
|
||||
if (Util.isAllowedToDownloadMetadata(this)) {
|
||||
loadWiki();
|
||||
}
|
||||
|
||||
albumTitleView.setText(album.getTitle());
|
||||
adapter.swapDataSet(album.songs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -97,6 +99,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
private Artist artist;
|
||||
@Nullable
|
||||
private Spanned biography;
|
||||
private MaterialDialog biographyDialog;
|
||||
private HorizontalAlbumAdapter albumAdapter;
|
||||
private ArtistSongAdapter songAdapter;
|
||||
|
||||
|
|
@ -219,34 +222,47 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
}
|
||||
|
||||
private void loadBiography() {
|
||||
lastFMRestClient.getApiService().getArtistInfo(getArtist().getName(), null).enqueue(new Callback<LastFmArtist>() {
|
||||
@Override
|
||||
public void onResponse(Call<LastFmArtist> call, Response<LastFmArtist> response) {
|
||||
LastFmArtist lastFmArtist = response.body();
|
||||
if (lastFmArtist.getArtist() != null) {
|
||||
String bio = lastFmArtist.getArtist().getBio().getContent();
|
||||
if (bio != null && !bio.trim().equals("")) {
|
||||
biography = Html.fromHtml(bio);
|
||||
return;
|
||||
}
|
||||
}
|
||||
biography = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<LastFmArtist> call, Throwable t) {
|
||||
t.printStackTrace();
|
||||
biography = null;
|
||||
}
|
||||
});
|
||||
loadBiography(Locale.getDefault().getLanguage());
|
||||
}
|
||||
|
||||
private MaterialDialog getBiographyDialog() {
|
||||
return new MaterialDialog.Builder(ArtistDetailActivity.this)
|
||||
.title(getArtist().getName())
|
||||
.content(biography != null ? biography : "")
|
||||
.positiveText(android.R.string.ok)
|
||||
.build();
|
||||
private void loadBiography(@Nullable final String lang) {
|
||||
biography = null;
|
||||
|
||||
lastFMRestClient.getApiService()
|
||||
.getArtistInfo(getArtist().getName(), lang, null)
|
||||
.enqueue(new Callback<LastFmArtist>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<LastFmArtist> call, @NonNull Response<LastFmArtist> response) {
|
||||
final LastFmArtist lastFmArtist = response.body();
|
||||
if (lastFmArtist != null && lastFmArtist.getArtist() != null) {
|
||||
final String bioContent = lastFmArtist.getArtist().getBio().getContent();
|
||||
if (bioContent != null && !bioContent.trim().isEmpty()) {
|
||||
biography = Html.fromHtml(bioContent);
|
||||
}
|
||||
}
|
||||
|
||||
// If the "lang" parameter is set and no biography is given, retry with default language
|
||||
if (biography == null && lang != null) {
|
||||
loadBiography(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util.isAllowedToDownloadMetadata(ArtistDetailActivity.this)) {
|
||||
if (biography != null) {
|
||||
biographyDialog.setContent(biography);
|
||||
} else {
|
||||
biographyDialog.dismiss();
|
||||
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.biography_unavailable), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<LastFmArtist> call, @NonNull Throwable t) {
|
||||
t.printStackTrace();
|
||||
biography = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadArtistImage(final boolean forceDownload) {
|
||||
|
|
@ -339,10 +355,22 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
super.onBackPressed();
|
||||
return true;
|
||||
case R.id.action_biography:
|
||||
if (biography != null) {
|
||||
getBiographyDialog().show();
|
||||
if (biographyDialog == null) {
|
||||
biographyDialog = new MaterialDialog.Builder(this)
|
||||
.title(artist.getName())
|
||||
.positiveText(android.R.string.ok)
|
||||
.build();
|
||||
}
|
||||
if (Util.isAllowedToDownloadMetadata(ArtistDetailActivity.this)) {
|
||||
if (biography != null) {
|
||||
biographyDialog.setContent(biography);
|
||||
biographyDialog.show();
|
||||
} else {
|
||||
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.biography_unavailable), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.biography_unavailable), Toast.LENGTH_SHORT).show();
|
||||
biographyDialog.show();
|
||||
loadBiography();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_re_download_artist_image:
|
||||
|
|
@ -410,7 +438,11 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
private void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
loadArtistImage(false);
|
||||
loadBiography();
|
||||
|
||||
if (Util.isAllowedToDownloadMetadata(this)) {
|
||||
loadBiography();
|
||||
}
|
||||
|
||||
artistName.setText(artist.getName());
|
||||
songAdapter.swapDataSet(artist.getSongs());
|
||||
albumAdapter.swapDataSet(artist.albums);
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
|||
Toast.makeText(this, getResources().getString(R.string.album_or_artist_empty), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr).enqueue(new Callback<LastFmAlbum>() {
|
||||
lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, null).enqueue(new Callback<LastFmAlbum>() {
|
||||
@Override
|
||||
public void onResponse(Call<LastFmAlbum> call, Response<LastFmAlbum> response) {
|
||||
LastFmAlbum lastFmAlbum = response.body();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue