Search in sources :

Example 16 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class QueuePresenter method saveQueue.

public void saveQueue(Context context, MenuItem item) {
    Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(PlaylistUtils.ARG_PLAYLIST);
    PlaylistUtils.addToPlaylist(context, playlist, MusicUtils.getQueue(), null);
}
Also used : Playlist(com.simplecity.amp_library.model.Playlist)

Example 17 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class PlaylistUtils method addToFavorites.

/**
     * Add a song to the favourites playlist
     */
public static void addToFavorites(final Context context) {
    Song song = MusicUtils.getSong();
    if (song == null) {
        return;
    }
    Observable.fromCallable(Playlist::favoritesPlaylist).flatMap(playlist -> playlist.getSongsObservable(context).flatMap(new Func1<List<Song>, Observable<Playlist>>() {

        @Override
        public Observable<Playlist> call(List<Song> songs) {
            Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist.id);
            ContentValues values = new ContentValues();
            values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, song.id);
            values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, songs.size() + 1);
            context.getContentResolver().insert(uri, values);
            return Observable.just(playlist);
        }
    })).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(playlist -> {
        Toast.makeText(context, context.getResources().getString(R.string.song_to_favourites, song.name), Toast.LENGTH_SHORT).show();
        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MusicService.InternalIntents.FAVORITE_CHANGED));
    });
}
Also used : R(com.simplecity.amp_library.R) Spannable(android.text.Spannable) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Song(com.simplecity.amp_library.model.Song) CheckBox(android.widget.CheckBox) ContentResolver(android.content.ContentResolver) MediaStore(android.provider.MediaStore) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Log(android.util.Log) Playlist(com.simplecity.amp_library.model.Playlist) BaseColumns(android.provider.BaseColumns) SubMenu(android.view.SubMenu) Query(com.simplecity.amp_library.model.Query) List(java.util.List) TextView(android.widget.TextView) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) TextWatcher(android.text.TextWatcher) FileType(com.simplecity.amp_library.interfaces.FileType) Context(android.content.Context) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) Dialog(android.app.Dialog) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) Observable(rx.Observable) SpannableStringBuilder(android.text.SpannableStringBuilder) Func1(rx.functions.Func1) Toast(android.widget.Toast) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Cursor(android.database.Cursor) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) FileWriter(java.io.FileWriter) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Crashlytics(com.crashlytics.android.Crashlytics) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) ContentValues(android.content.ContentValues) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) List(java.util.List) Intent(android.content.Intent) Uri(android.net.Uri) Observable(rx.Observable)

Example 18 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class PlaylistUtils method makePlaylistMenu.

public static void makePlaylistMenu(Context context, SubMenu sub, int fragmentGroupId) {
    Query query = new Query.Builder().uri(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI).projection(new String[] { BaseColumns._ID, MediaStore.Audio.PlaylistsColumns.NAME }).build();
    SqlBriteUtils.createQuery(context, Playlist::new, query).observeOn(AndroidSchedulers.mainThread()).subscribe(playlists -> {
        sub.clear();
        sub.add(fragmentGroupId, MusicUtils.Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
        for (Playlist playlist : playlists) {
            final Intent intent = new Intent();
            intent.putExtra(ShuttleUtils.ARG_PLAYLIST, playlist);
            sub.add(fragmentGroupId, MusicUtils.Defs.PLAYLIST_SELECTED, 0, playlist.name).setIntent(intent);
        }
    });
}
Also used : Playlist(com.simplecity.amp_library.model.Playlist) Query(com.simplecity.amp_library.model.Query) Intent(android.content.Intent)

Example 19 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class PlaylistUtils method addToPlaylist.

/**
     * Method addToPlaylist.
     *
     * @param playlist Playlist
     * @param songs    List<Song>
     * @return boolean true if the playlist addition was successful
     */
public static void addToPlaylist(Context context, Playlist playlist, List<Song> songs) {
    if (playlist == null || songs == null || songs.isEmpty()) {
        return;
    }
    playlist.getSongsObservable(context).observeOn(AndroidSchedulers.mainThread()).subscribe(existingSongs -> {
        if (!SettingsManager.getInstance().ignoreDuplicates()) {
            List<Song> duplicates = Stream.of(existingSongs).filter(songs::contains).distinct().collect(Collectors.toList());
            if (!duplicates.isEmpty()) {
                View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist_duplicates, null);
                TextView messageText = (TextView) customView.findViewById(R.id.textView);
                CheckBox applyToAll = (CheckBox) customView.findViewById(R.id.applyToAll);
                CheckBox alwaysAdd = (CheckBox) customView.findViewById(R.id.alwaysAdd);
                if (duplicates.size() <= 1) {
                    applyToAll.setVisibility(View.GONE);
                    applyToAll.setChecked(false);
                }
                messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
                applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
                DialogUtils.getBuilder(context).title(R.string.dialog_title_playlist_duplicates).customView(customView, false).positiveText(R.string.dialog_button_playlist_duplicate_add).autoDismiss(false).onPositive((dialog, which) -> {
                    if (duplicates.size() != 1 && !applyToAll.isChecked()) {
                        duplicates.remove(0);
                        messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
                        applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
                    } else {
                        insertPlaylistItems(context, playlist, songs, existingSongs.size());
                        SettingsManager.getInstance().setIgnoreDuplicates(alwaysAdd.isChecked());
                        dialog.dismiss();
                    }
                }).negativeText(R.string.dialog_button_playlist_duplicate_skip).onNegative((dialog, which) -> {
                    if (duplicates.size() != 1 && !applyToAll.isChecked()) {
                        songs.remove(duplicates.remove(0));
                        messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
                        applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
                    } else {
                        Stream.of(duplicates).filter(songs::contains).forEach(songs::remove);
                        insertPlaylistItems(context, playlist, songs, existingSongs.size());
                        SettingsManager.getInstance().setIgnoreDuplicates(alwaysAdd.isChecked());
                        dialog.dismiss();
                    }
                }).show();
            } else {
                insertPlaylistItems(context, playlist, songs, existingSongs.size());
            }
        } else {
            insertPlaylistItems(context, playlist, songs, existingSongs.size());
        }
    });
}
Also used : R(com.simplecity.amp_library.R) Spannable(android.text.Spannable) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Song(com.simplecity.amp_library.model.Song) CheckBox(android.widget.CheckBox) ContentResolver(android.content.ContentResolver) MediaStore(android.provider.MediaStore) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Log(android.util.Log) Playlist(com.simplecity.amp_library.model.Playlist) BaseColumns(android.provider.BaseColumns) SubMenu(android.view.SubMenu) Query(com.simplecity.amp_library.model.Query) List(java.util.List) TextView(android.widget.TextView) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) TextWatcher(android.text.TextWatcher) FileType(com.simplecity.amp_library.interfaces.FileType) Context(android.content.Context) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) Dialog(android.app.Dialog) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) Observable(rx.Observable) SpannableStringBuilder(android.text.SpannableStringBuilder) Func1(rx.functions.Func1) Toast(android.widget.Toast) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Cursor(android.database.Cursor) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) FileWriter(java.io.FileWriter) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Crashlytics(com.crashlytics.android.Crashlytics) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) Song(com.simplecity.amp_library.model.Song) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Example 20 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class PlaylistUtils method addFileObjectsToPlaylist.

public static void addFileObjectsToPlaylist(Context context, Playlist playlist, List<BaseFileObject> fileObjects) {
    ProgressDialog progressDialog = ProgressDialog.show(context, "", context.getString(R.string.gathering_songs), false);
    long folderCount = Stream.of(fileObjects).filter(value -> value.fileType == FileType.FOLDER).count();
    if (folderCount > 0) {
        progressDialog.show();
    }
    ShuttleUtils.getSongsForFileObjects(fileObjects).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        addToPlaylist(context, playlist, songs);
    });
}
Also used : R(com.simplecity.amp_library.R) Spannable(android.text.Spannable) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Song(com.simplecity.amp_library.model.Song) CheckBox(android.widget.CheckBox) ContentResolver(android.content.ContentResolver) MediaStore(android.provider.MediaStore) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Log(android.util.Log) Playlist(com.simplecity.amp_library.model.Playlist) BaseColumns(android.provider.BaseColumns) SubMenu(android.view.SubMenu) Query(com.simplecity.amp_library.model.Query) List(java.util.List) TextView(android.widget.TextView) ContentValues(android.content.ContentValues) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) TextWatcher(android.text.TextWatcher) FileType(com.simplecity.amp_library.interfaces.FileType) Context(android.content.Context) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) Dialog(android.app.Dialog) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) Observable(rx.Observable) SpannableStringBuilder(android.text.SpannableStringBuilder) Func1(rx.functions.Func1) Toast(android.widget.Toast) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Cursor(android.database.Cursor) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) FileWriter(java.io.FileWriter) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Crashlytics(com.crashlytics.android.Crashlytics) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) ProgressDialog(android.app.ProgressDialog)

Aggregations

Playlist (com.simplecity.amp_library.model.Playlist)35 Intent (android.content.Intent)22 View (android.view.View)19 List (java.util.List)19 Uri (android.net.Uri)17 R (com.simplecity.amp_library.R)17 Song (com.simplecity.amp_library.model.Song)17 Context (android.content.Context)16 LayoutInflater (android.view.LayoutInflater)16 Toast (android.widget.Toast)16 SubMenu (android.view.SubMenu)15 Stream (com.annimon.stream.Stream)15 ContentUris (android.content.ContentUris)14 MediaStore (android.provider.MediaStore)14 TextView (android.widget.TextView)14 ArrayList (java.util.ArrayList)14 Query (com.simplecity.amp_library.model.Query)12 TimeUnit (java.util.concurrent.TimeUnit)12 NonNull (android.support.annotation.NonNull)11 Collections (java.util.Collections)11