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();
}
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);
}
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);
}
}
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);
}
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();
}
Aggregations