Search in sources :

Example 1 with Song

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();
}
Also used : Song(me.echeung.listenmoeapi.models.Song) Activity(android.app.Activity)

Example 2 with Song

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);
}
Also used : RadioViewModel(me.echeung.moemoekyun.viewmodels.RadioViewModel) Song(me.echeung.listenmoeapi.models.Song) ParseException(java.text.ParseException)

Example 3 with Song

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);
}
Also used : Song(me.echeung.listenmoeapi.models.Song) Intent(android.content.Intent)

Example 4 with Song

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());
}
Also used : PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) Song(me.echeung.listenmoeapi.models.Song)

Example 5 with Song

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();
}
Also used : Context(android.content.Context) Song(me.echeung.listenmoeapi.models.Song) RequestSongCallback(me.echeung.listenmoeapi.callbacks.RequestSongCallback) R(me.echeung.moemoekyun.R) Intent(android.content.Intent) App(me.echeung.moemoekyun.App) SongAdapter(me.echeung.moemoekyun.adapters.songslist.SongAdapter) ClipData(android.content.ClipData) RecyclerView(android.support.v7.widget.RecyclerView) FavoriteSongCallback(me.echeung.listenmoeapi.callbacks.FavoriteSongCallback) AlertDialog(android.support.v7.app.AlertDialog) DataBindingUtil(android.databinding.DataBindingUtil) Toast(android.widget.Toast) SongItemBinding(me.echeung.moemoekyun.databinding.SongItemBinding) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Snackbar(android.support.design.widget.Snackbar) Activity(android.app.Activity) SongItemBinding(me.echeung.moemoekyun.databinding.SongItemBinding)

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