Search in sources :

Example 1 with LastFmAlbum

use of com.simplecity.amp_library.lastfm.LastFmAlbum in project Shuttle by timusus.

the class DialogUtils method showBiographyDialog.

public static void showBiographyDialog(final Context context, @BioType int type, String artistName, String albumName) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customView = inflater.inflate(R.layout.dialog_biography, null, false);
    final ProgressBar progressBar = (ProgressBar) customView.findViewById(R.id.progress);
    final TextView message = (TextView) customView.findViewById(R.id.message);
    final ScrollView scrollView = (ScrollView) customView.findViewById(R.id.scrollView);
    ThemeUtils.themeScrollView(scrollView);
    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) {
                    message.setText(Html.fromHtml(response.body().artist.bio.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) {
                    message.setText(Html.fromHtml(response.body().album.wiki.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 = getBuilder(context).title(R.string.info).customView(customView, false).negativeText(R.string.close);
    Dialog dialog = builder.show();
    dialog.setOnDismissListener(dialog1 -> {
    });
}
Also used : Call(retrofit2.Call) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) Response(retrofit2.Response) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar)

Aggregations

Dialog (android.app.Dialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ListView (android.widget.ListView)1 ProgressBar (android.widget.ProgressBar)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 LastFmAlbum (com.simplecity.amp_library.lastfm.LastFmAlbum)1 LastFmArtist (com.simplecity.amp_library.lastfm.LastFmArtist)1 BlacklistView (com.simplecity.amp_library.ui.modelviews.BlacklistView)1 ColorView (com.simplecity.amp_library.ui.modelviews.ColorView)1 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)1 WhitelistView (com.simplecity.amp_library.ui.modelviews.WhitelistView)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1