Search in sources :

Example 1 with Lyrics

use of com.kabouzeid.gramophone.model.lyrics.Lyrics in project Phonograph by kabouzeid.

the class FlatPlayerFragment method updateLyrics.

private void updateLyrics() {
    if (updateLyricsAsyncTask != null)
        updateLyricsAsyncTask.cancel(false);
    final Song song = MusicPlayerRemote.getCurrentSong();
    updateLyricsAsyncTask = new AsyncTask<Void, Void, Lyrics>() {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            lyrics = null;
            playerAlbumCoverFragment.setLyrics(null);
            toolbar.getMenu().removeItem(R.id.action_show_lyrics);
        }

        @Override
        protected Lyrics doInBackground(Void... params) {
            String data = MusicUtil.getLyrics(song);
            if (TextUtils.isEmpty(data)) {
                return null;
            }
            return Lyrics.parse(song, data);
        }

        @Override
        protected void onPostExecute(Lyrics l) {
            lyrics = l;
            playerAlbumCoverFragment.setLyrics(lyrics);
            if (lyrics == null) {
                if (toolbar != null) {
                    toolbar.getMenu().removeItem(R.id.action_show_lyrics);
                }
            } else {
                Activity activity = getActivity();
                if (toolbar != null && activity != null)
                    if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
                        int color = ToolbarContentTintHelper.toolbarContentColor(activity, Color.TRANSPARENT);
                        Drawable drawable = ImageUtil.getTintedVectorDrawable(activity, R.drawable.ic_comment_text_outline_white_24dp, color);
                        toolbar.getMenu().add(Menu.NONE, R.id.action_show_lyrics, Menu.NONE, R.string.action_show_lyrics).setIcon(drawable).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                    }
            }
        }

        @Override
        protected void onCancelled(Lyrics s) {
            onPostExecute(null);
        }
    }.execute();
}
Also used : Song(com.kabouzeid.gramophone.model.Song) AsyncTask(android.os.AsyncTask) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AbsSlidingMusicPanelActivity(com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity) Activity(android.app.Activity) Lyrics(com.kabouzeid.gramophone.model.lyrics.Lyrics)

Example 2 with Lyrics

use of com.kabouzeid.gramophone.model.lyrics.Lyrics in project Phonograph by kabouzeid.

the class CardPlayerFragment method updateLyrics.

private void updateLyrics() {
    if (updateLyricsAsyncTask != null)
        updateLyricsAsyncTask.cancel(false);
    final Song song = MusicPlayerRemote.getCurrentSong();
    updateLyricsAsyncTask = new AsyncTask<Void, Void, Lyrics>() {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            lyrics = null;
            playerAlbumCoverFragment.setLyrics(null);
            toolbar.getMenu().removeItem(R.id.action_show_lyrics);
        }

        @Override
        protected Lyrics doInBackground(Void... params) {
            String data = MusicUtil.getLyrics(song);
            if (TextUtils.isEmpty(data)) {
                return null;
            }
            return Lyrics.parse(song, data);
        }

        @Override
        protected void onPostExecute(Lyrics l) {
            lyrics = l;
            playerAlbumCoverFragment.setLyrics(lyrics);
            if (lyrics == null) {
                if (toolbar != null) {
                    toolbar.getMenu().removeItem(R.id.action_show_lyrics);
                }
            } else {
                Activity activity = getActivity();
                if (toolbar != null && activity != null)
                    if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
                        int color = ToolbarContentTintHelper.toolbarContentColor(activity, Color.TRANSPARENT);
                        Drawable drawable = ImageUtil.getTintedVectorDrawable(activity, R.drawable.ic_comment_text_outline_white_24dp, color);
                        toolbar.getMenu().add(Menu.NONE, R.id.action_show_lyrics, Menu.NONE, R.string.action_show_lyrics).setIcon(drawable).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                    }
            }
        }

        @Override
        protected void onCancelled(Lyrics s) {
            onPostExecute(null);
        }
    }.execute();
}
Also used : Song(com.kabouzeid.gramophone.model.Song) AsyncTask(android.os.AsyncTask) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AbsSlidingMusicPanelActivity(com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity) Activity(android.app.Activity) Lyrics(com.kabouzeid.gramophone.model.lyrics.Lyrics)

Aggregations

Activity (android.app.Activity)2 Drawable (android.graphics.drawable.Drawable)2 AsyncTask (android.os.AsyncTask)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 Song (com.kabouzeid.gramophone.model.Song)2 Lyrics (com.kabouzeid.gramophone.model.lyrics.Lyrics)2 AbsSlidingMusicPanelActivity (com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity)2