Search in sources :

Example 6 with Song

use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.

the class SongDetailAdapter method getView.

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    final LayoutInflater inflater = LayoutInflater.from(getContext());
    final SongItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.song_item, parent, false);
    final Song song = getItem(position);
    binding.setSong(song);
    binding.setDetailed(true);
    return binding.getRoot();
}
Also used : Song(me.echeung.listenmoeapi.models.Song) LayoutInflater(android.view.LayoutInflater) SongItemBinding(me.echeung.moemoekyun.databinding.SongItemBinding) NonNull(android.support.annotation.NonNull)

Example 7 with Song

use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.

the class SongAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    final Song song = visibleSongs.get(position);
    final SongViewHolder songHolder = (SongViewHolder) holder;
    songHolder.bind(song);
}
Also used : Song(me.echeung.listenmoeapi.models.Song)

Example 8 with Song

use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.

the class AppNotification method update.

void update() {
    if (!service.isStreamStarted()) {
        return;
    }
    final Song song = getCurrentSong();
    final Bitmap albumArt = AlbumArtUtil.getCurrentAlbumArt();
    final boolean isPlaying = service.isPlaying();
    // Play/pause action
    final NotificationCompat.Action playPauseAction = new NotificationCompat.Action(isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp, isPlaying ? service.getString(R.string.action_pause) : service.getString(R.string.action_play), getPlaybackActionService(RadioService.PLAY_PAUSE));
    // Build the notification
    final Intent action = new Intent(service, MainActivity.class);
    action.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent clickIntent = PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT);
    final PendingIntent deleteIntent = getPlaybackActionService(RadioService.STOP);
    MediaStyle style = new MediaStyle().setMediaSession(service.getMediaSession().getSessionToken());
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_icon).setLargeIcon(albumArt).setContentIntent(clickIntent).setDeleteIntent(deleteIntent).addAction(playPauseAction).setContentTitle(service.getString(R.string.app_name)).setOngoing(isPlaying).setShowWhen(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setOnlyAlertOnce(true);
    // For pre-Oreo colored notifications
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && !AlbumArtUtil.isDefaultAlbumArt()) {
        builder.setColor(AlbumArtUtil.getCurrentAccentColor());
    }
    // Needs to be set after setting the color
    builder.setStyle(style.setShowActionsInCompactView(0));
    if (song != null) {
        builder.setContentTitle(song.getTitle());
        builder.setContentText(song.getArtistsString());
        builder.setSubText(song.getAlbumsString());
        // Add favorite action if logged in
        if (App.getAuthUtil().isAuthenticated()) {
            builder.addAction(new NotificationCompat.Action(song.isFavorite() ? R.drawable.ic_star_white_24dp : R.drawable.ic_star_border_white_24dp, song.isFavorite() ? service.getString(R.string.action_unfavorite) : service.getString(R.string.action_favorite), getPlaybackActionService(RadioService.TOGGLE_FAVORITE)));
            builder.setStyle(style.setShowActionsInCompactView(0, 1));
        }
    }
    final Notification notification = builder.build();
    if (isPlaying) {
        service.startForeground(NOTIFICATION_ID, notification);
    } else {
        service.stopForeground(false);
        notificationManager.notify(NOTIFICATION_ID, notification);
    }
}
Also used : Song(me.echeung.listenmoeapi.models.Song) Bitmap(android.graphics.Bitmap) MediaStyle(android.support.v4.media.app.NotificationCompat.MediaStyle) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 9 with Song

use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.

the class RadioService method favoriteCurrentSong.

private void favoriteCurrentSong() {
    final Song currentSong = App.getRadioViewModel().getCurrentSong();
    if (currentSong == null)
        return;
    final int songId = currentSong.getId();
    if (songId == -1)
        return;
    if (!App.getAuthUtil().isAuthenticated()) {
        showLoginRequiredToast();
        return;
    }
    final boolean isCurrentlyFavorite = currentSong.isFavorite();
    final FavoriteSongCallback callback = new FavoriteSongCallback() {

        @Override
        public void onSuccess() {
            final Song currentSong = App.getRadioViewModel().getCurrentSong();
            if (currentSong.getId() == songId) {
                App.getRadioViewModel().setIsFavorited(!isCurrentlyFavorite);
            }
            final Intent favIntent = new Intent(SongActionsUtil.FAVORITE_EVENT);
            sendBroadcast(favIntent);
            updateNotification();
            updateMediaSessionPlaybackState();
        }

        @Override
        public void onFailure(final String message) {
            Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
        }
    };
    App.getApiClient().toggleFavorite(String.valueOf(songId), isCurrentlyFavorite, callback);
}
Also used : Song(me.echeung.listenmoeapi.models.Song) Intent(android.content.Intent) FavoriteSongCallback(me.echeung.listenmoeapi.callbacks.FavoriteSongCallback)

Example 10 with Song

use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.

the class RadioService method updateMediaSession.

private void updateMediaSession() {
    final Song currentSong = App.getRadioViewModel().getCurrentSong();
    if (currentSong == null) {
        mediaSession.setMetadata(null);
        return;
    }
    final MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentSong.getTitle()).putString(MediaMetadataCompat.METADATA_KEY_ARTIST, currentSong.getArtistsString()).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentSong.getAlbumsString()).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, currentSong.getDuration());
    if (App.getPreferenceUtil().shouldShowLockscreenAlbumArt()) {
        final Bitmap albumArt = AlbumArtUtil.getCurrentAlbumArt();
        if (albumArt != null && !AlbumArtUtil.isDefaultAlbumArt()) {
            metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
            updateNotification();
        }
    }
    mediaSession.setMetadata(metaData.build());
    updateMediaSessionPlaybackState();
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Song(me.echeung.listenmoeapi.models.Song) Bitmap(android.graphics.Bitmap)

Aggregations

Song (me.echeung.listenmoeapi.models.Song)11 Intent (android.content.Intent)4 Activity (android.app.Activity)2 Bitmap (android.graphics.Bitmap)2 FavoriteSongCallback (me.echeung.listenmoeapi.callbacks.FavoriteSongCallback)2 SongItemBinding (me.echeung.moemoekyun.databinding.SongItemBinding)2 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 DataBindingUtil (android.databinding.DataBindingUtil)1 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 MediaStyle (android.support.v4.media.app.NotificationCompat.MediaStyle)1 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1