use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class MusicService method notifyChange.
private void notifyChange(String what, boolean fromUser) {
if (what.equals(InternalIntents.TRACK_ENDING)) {
//We're just about to change tracks, so 'current song' is the song that just finished
Song finishedSong = currentSong;
if (finishedSong != null) {
if (finishedSong.hasPlayed()) {
Observable.fromCallable(() -> {
ShuttleUtils.incrementPlayCount(this, finishedSong);
return null;
}).subscribeOn(Schedulers.io()).subscribe();
}
scrobbleBroadcast(Status.COMPLETE, finishedSong);
}
return;
}
updateMediaSession(what);
if (what.equals(InternalIntents.POSITION_CHANGED)) {
return;
}
getExtras(fromUser).subscribeOn(Schedulers.io()).subscribe(extras -> {
final Intent intent = new Intent(what);
intent.putExtras(extras);
sendBroadcast(intent);
});
//Tasker intent
Intent taskerIntent = new Intent(ExternalIntents.TASKER);
//Pebble intent
Intent pebbleIntent = new Intent(ExternalIntents.PEBBLE);
pebbleIntent.putExtra("artist", getArtistName());
pebbleIntent.putExtra("album", getAlbumName());
pebbleIntent.putExtra("track", getSongName());
if (what.equals(InternalIntents.PLAY_STATE_CHANGED)) {
updateNotification();
// Bluetooth intent
getExtras(fromUser).subscribeOn(Schedulers.io()).subscribe(extras -> {
final Intent intent = new Intent(ExternalIntents.AVRCP_PLAY_STATE_CHANGED);
intent.putExtras(extras);
sendBroadcast(intent);
});
if (isPlaying()) {
if (currentSong != null) {
currentSong.setResumed();
}
//Last.fm scrobbler intent
scrobbleBroadcast(Status.RESUME, currentSong);
//Tasker intent
taskerIntent.putExtra("%MTRACK", getSongName());
//Pebble intent
sendBroadcast(pebbleIntent);
} else {
if (currentSong != null) {
currentSong.setPaused();
}
//Last.fm scrobbler intent
scrobbleBroadcast(Status.PAUSE, currentSong);
//Tasker intent
taskerIntent.putExtra("%MTRACK", "");
}
sendBroadcast(taskerIntent);
} else if (what.equals(InternalIntents.META_CHANGED)) {
if (currentSong != null) {
currentSong.setStartTime();
}
//Tasker intent
taskerIntent.putExtra("%MTRACK", getSongName());
sendBroadcast(taskerIntent);
//Bluetooth intent
getExtras(fromUser).subscribeOn(Schedulers.io()).subscribe(extras -> {
final Intent intent = new Intent(ExternalIntents.AVRCP_META_CHANGED);
intent.putExtras(extras);
sendBroadcast(intent);
});
//Pebble intent
sendBroadcast(pebbleIntent);
//Last.fm scrobbler intent
scrobbleBroadcast(Status.START, currentSong);
}
if (what.equals(InternalIntents.QUEUE_CHANGED)) {
saveQueue(true);
if (isPlaying()) {
setNextTrack();
}
} else {
saveQueue(false);
}
mWidgetProviderLarge.notifyChange(MusicService.this, what);
mWidgetProviderMedium.notifyChange(MusicService.this, what);
mWidgetProviderSmall.notifyChange(MusicService.this, what);
mWidgetProviderExtraLarge.notifyChange(MusicService.this, what);
}
use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class MusicService method openFile.
/**
* Opens a file and prepares it for playback
*
* @param path The path of the file to open
*/
public void openFile(String path, @Nullable Action0 completion) {
synchronized (this) {
if (path == null) {
return;
}
Uri uri = Uri.parse(path);
long id = -1;
try {
id = Long.valueOf(uri.getLastPathSegment());
} catch (NumberFormatException ignored) {
}
Predicate<Song> predicate;
long finalId = id;
if (finalId != -1 && (path.startsWith(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString()) || path.startsWith(MediaStore.Files.getContentUri("external").toString()))) {
predicate = song -> song.id == finalId;
} else {
if (uri != null && path.startsWith("content://")) {
path = uri.getPath();
}
String finalPath = path;
predicate = song -> song.path.contains(finalPath);
}
DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(predicate).collect(Collectors.toList())).subscribe(songs -> {
if (!songs.isEmpty()) {
currentSong = songs.get(0);
open(currentSong);
if (completion != null) {
completion.call();
}
}
});
}
}
use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class MainActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_search:
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
intent.putExtra(SearchManager.QUERY, "");
startActivityForResult(intent, REQUEST_SEARCH);
return true;
case EQUALIZER:
final Intent equalizerIntent = new Intent(this, EqualizerActivity.class);
startActivity(equalizerIntent);
return true;
case GO_TO_ARTIST:
long time = System.currentTimeMillis();
Album currentAlbum = MusicUtils.getAlbum();
if (currentAlbum != null) {
DataManager.getInstance().getAlbumArtistsRelay().first().flatMap(Observable::from).filter(albumArtist -> albumArtist.name.equals(currentAlbum.albumArtistName) && com.annimon.stream.Stream.of(albumArtist.albums).anyMatch(album -> album.id == currentAlbum.id)).observeOn(AndroidSchedulers.mainThread()).subscribe(albumArtist -> {
swapFragments(DetailFragment.newInstance(albumArtist), true);
new Handler().postDelayed(() -> mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true), time - System.currentTimeMillis() + 250);
});
}
return true;
case GO_TO_ALBUM:
time = System.currentTimeMillis();
currentAlbum = MusicUtils.getAlbum();
if (currentAlbum != null) {
DataManager.getInstance().getAlbumsRelay().first().flatMap(Observable::from).filter(album -> album.id == currentAlbum.id).observeOn(AndroidSchedulers.mainThread()).subscribe(album -> {
swapFragments(DetailFragment.newInstance(album), true);
new Handler().postDelayed(() -> mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true), time - System.currentTimeMillis() + 250);
});
}
return true;
case TIMER:
SleepTimer.createTimer(this, MusicUtils.getTimerActive(), MusicUtils.getTimeRemaining());
return true;
case DELETE_ITEM:
new DialogUtils.DeleteDialogBuilder().context(this).singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Collections.singletonList(MusicUtils.getSongName())).songsToDelete(Observable.just(Collections.singletonList(MusicUtils.getSong()))).build().show();
return true;
case NEW_PLAYLIST:
PlaylistUtils.createPlaylistDialog(this, MusicUtils.getQueue());
return true;
case PLAYLIST_SELECTED:
List<Song> songs = MusicUtils.getQueue();
Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
PlaylistUtils.addToPlaylist(this, playlist, songs);
return true;
case CLEAR_QUEUE:
MusicUtils.clearQueue();
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return true;
case TAGGER:
TaggerDialog.newInstance(MusicUtils.getSong()).show(getSupportFragmentManager());
return true;
case VIEW_INFO:
DialogUtils.showSongInfoDialog(this, MusicUtils.getSong());
return true;
case R.id.menu_favorite:
PlaylistUtils.toggleFavorite(this);
return true;
case R.id.menu_share:
DialogUtils.showShareDialog(MainActivity.this, MusicUtils.getSong());
return true;
case R.id.menu_queue:
Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
if (playingFragment != null) {
((PlayerFragment) playingFragment).toggleQueue();
}
return true;
case android.R.id.home:
playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
if (playingFragment != null) {
Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
if (childFragment != null && childFragment instanceof QueueFragment) {
((PlayerFragment) playingFragment).toggleQueue();
toggleQueue(false);
return true;
}
}
if (mSlidingUpPanelLayout != null) {
if (mSlidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.COLLAPSED && mSlidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.HIDDEN) {
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true);
return true;
}
}
break;
}
return super.onOptionsItemSelected(item);
}
use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class MusicService method makeShuffleList.
public void makeShuffleList() {
synchronized (this) {
if (playlist == null || playlist.isEmpty()) {
return;
}
shuffleList = new ArrayList<>(playlist);
Song currentSong = null;
if (playPos >= 0 && playPos < shuffleList.size()) {
currentSong = shuffleList.remove(playPos);
}
Collections.shuffle(shuffleList);
if (currentSong != null) {
shuffleList.add(0, currentSong);
}
playPos = 0;
}
}
use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class BlacklistHelper method addToBlacklist.
public static void addToBlacklist(List<Song> songs) {
BriteDatabase db = DataManager.getInstance().getBlacklistDatabase();
BriteDatabase.Transaction transaction = db.newTransaction();
try {
Stream.of(songs).map(song -> {
ContentValues contentValues = new ContentValues();
contentValues.put(BlacklistDbOpenHelper.COLUMN_SONG_ID, song.id);
return contentValues;
}).forEach(contentValues -> db.insert(BlacklistDbOpenHelper.TABLE_SONGS, contentValues));
transaction.markSuccessful();
} finally {
transaction.end();
}
}
Aggregations