use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.
the class SongAdapter method updateSongs.
private void updateSongs() {
final Activity activityRef = activity.get();
if (activityRef == null)
return;
if (allSongs == null || allSongs.isEmpty())
return;
visibleSongs = allSongs;
if (!TextUtils.isEmpty(filterQuery)) {
visibleSongs = new ArrayList<>();
for (final Song song : allSongs) {
if (song.search(filterQuery)) {
visibleSongs.add(song);
}
}
}
SongSortUtil.sort(activityRef, listId, visibleSongs);
notifyDataSetChanged();
}
use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.
the class RadioService method onSocketReceive.
@Override
public void onSocketReceive(SocketUpdateResponse.Details info) {
final RadioViewModel viewModel = App.getRadioViewModel();
final Song song = info.getSong();
viewModel.setCurrentSong(song);
try {
this.trackStartTime = ISO8601.toCalendar(info.getStartTime());
} catch (ParseException e) {
e.printStackTrace();
}
viewModel.setLastSong(info.getLastPlayed().get(0));
viewModel.setSecondLastSong(info.getLastPlayed().get(1));
viewModel.setListeners(info.getListeners());
viewModel.setRequester(info.getRequester());
viewModel.setEvent(info.getEvent());
if (info.getQueue() != null) {
viewModel.setQueueSize(info.getQueue().getInQueue());
viewModel.setInQueueByUser(info.getQueue().getInQueueByUser());
viewModel.setQueuePosition(info.getQueue().getInQueueBeforeUser());
}
updateMediaSession();
updateNotification();
sendPublicIntent(RadioService.META_CHANGED);
}
use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.
the class RadioService method sendPublicIntent.
/**
* Sends an intent out for services like Last.fm.
*
* @param action The broadcast event.
*/
public void sendPublicIntent(final String action) {
final Song song = App.getRadioViewModel().getCurrentSong();
if (song == null || !App.getPreferenceUtil().shouldBroadcastIntent())
return;
// Scrobbling only works if there's actually progress
if (song.getDuration() == 0 || trackStartTime == null)
return;
final Intent intent = new Intent(action.replace(APP_PACKAGE_NAME, MUSIC_PACKAGE_NAME));
intent.putExtra("id", song.getId());
intent.putExtra("artist", song.getAlbumsString());
intent.putExtra("album", song.getAlbumsString());
intent.putExtra("track", song.getTitle());
intent.putExtra("duration", song.getDuration());
intent.putExtra("position", GregorianCalendar.getInstance().getTimeInMillis() - trackStartTime.getTimeInMillis());
intent.putExtra("playing", isPlaying());
intent.putExtra("scrobbling_source", APP_PACKAGE_NAME);
sendStickyBroadcast(intent);
}
use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.
the class RadioService method updateMediaSessionPlaybackState.
private void updateMediaSessionPlaybackState() {
if (!mediaSession.isActive()) {
return;
}
// Play/pause state
final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder().setActions(MEDIA_SESSION_ACTIONS).setState(isStreamStarted() ? isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED : PlaybackStateCompat.STATE_STOPPED, 0, 1);
// Favorite action
if (App.getAuthUtil().isAuthenticated()) {
final Song currentSong = App.getRadioViewModel().getCurrentSong();
final int favoriteIcon = currentSong == null || !currentSong.isFavorite() ? R.drawable.ic_star_border_white_24dp : R.drawable.ic_star_white_24dp;
stateBuilder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(TOGGLE_FAVORITE, getString(R.string.favorite), favoriteIcon).build());
}
mediaSession.setPlaybackState(stateBuilder.build());
}
use of me.echeung.listenmoeapi.models.Song in project android-app by LISTEN-moe.
the class SongActionsUtil method showSongActionsDialog.
public static void showSongActionsDialog(final Activity activity, final SongAdapter adapter, final Song song) {
if (activity == null)
return;
final String favoriteAction = song.isFavorite() ? activity.getString(R.string.action_unfavorite) : activity.getString(R.string.action_favorite);
final SongItemBinding binding = DataBindingUtil.inflate(activity.getLayoutInflater(), R.layout.song_item, null, false);
binding.setSong(song);
binding.setDetailed(true);
new AlertDialog.Builder(activity, R.style.DialogTheme).setView(binding.getRoot()).setPositiveButton(android.R.string.cancel, null).setNegativeButton(favoriteAction, (dialogInterface, in) -> SongActionsUtil.toggleFavorite(activity, adapter, song)).setNeutralButton(activity.getString(R.string.action_request), (dialogInterface, im) -> SongActionsUtil.request(activity, adapter, song)).create().show();
}
Aggregations