Search in sources :

Example 1 with BlacklistAdapter

use of com.simplecity.amp_library.ui.adapters.BlacklistAdapter in project Shuttle by timusus.

the class DialogUtils method showBlacklistDialog.

public static void showBlacklistDialog(final Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
    final MaterialDialog.Builder builder = getBuilder(context).title(R.string.blacklist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_blacklist).onNegative((materialDialog, dialogAction) -> {
        BlacklistHelper.deleteAllSongs();
        Toast.makeText(context, R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
    });
    final Dialog dialog = builder.build();
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    final BlacklistAdapter blacklistAdapter = new BlacklistAdapter();
    blacklistAdapter.setBlackListListener((v, position, song) -> {
        BlacklistHelper.deleteSong(song.id);
        if (blacklistAdapter.items.size() == 0) {
            dialog.dismiss();
        }
    });
    recyclerView.setAdapter(blacklistAdapter);
    Observable<List<Song>> songsObservable = SqlBriteUtils.createContinuousQuery(ShuttleApplication.getInstance(), Song::new, Song.getQuery()).first();
    Observable<List<BlacklistedSong>> blacklistObservable = BlacklistHelper.getBlacklistSongsObservable();
    Subscription subscription = Observable.combineLatest(songsObservable, blacklistObservable, (songs, blacklistedSongs) -> Stream.of(songs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).sorted((a, b) -> ComparisonUtils.compare(a.albumArtistName, b.albumArtistName)).sorted((a, b) -> ComparisonUtils.compareInt(b.year, a.year)).sorted((a, b) -> ComparisonUtils.compareInt(a.track, b.track)).sorted((a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber)).sorted((a, b) -> ComparisonUtils.compare(a.albumName, b.albumName)).map(song -> (AdaptableItem) new BlacklistView(song)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(blacklistViews -> {
        if (blacklistViews.size() == 0) {
            blacklistAdapter.addItem(0, new EmptyView(R.string.blacklist_empty));
        } else {
            blacklistAdapter.setItems(blacklistViews);
        }
    });
    dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
    dialog.show();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) Subscription(rx.Subscription) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Aggregations

Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 ContentProviderOperation (android.content.ContentProviderOperation)1 Context (android.content.Context)1 Intent (android.content.Intent)1 OperationApplicationException (android.content.OperationApplicationException)1 Bitmap (android.graphics.Bitmap)1 Color (android.graphics.Color)1 Drawable (android.graphics.drawable.Drawable)1 RemoteException (android.os.RemoteException)1 StringRes (android.support.annotation.StringRes)1 Snackbar (android.support.design.widget.Snackbar)1 FileProvider (android.support.v4.content.FileProvider)1 IntentCompat (android.support.v4.content.IntentCompat)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Html (android.text.Html)1 LayoutInflater (android.view.LayoutInflater)1