Search in sources :

Example 1 with WhitelistAdapter

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

the class DialogUtils method showWhitelistDialog.

public static void showWhitelistDialog(final Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
    final MaterialDialog.Builder builder = getBuilder(context).title(R.string.whitelist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_whitelist).onNegative((materialDialog, dialogAction) -> {
        WhitelistHelper.deleteAllFolders();
        Toast.makeText(context, R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
    });
    final Dialog dialog = builder.build();
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    final WhitelistAdapter whitelistadapter = new WhitelistAdapter();
    whitelistadapter.setWhitelistListener((v, position, songWhitelist) -> {
        WhitelistHelper.deleteFolder(songWhitelist);
        whitelistadapter.removeItem(position);
        if (whitelistadapter.items.size() == 0) {
            dialog.dismiss();
        }
    });
    recyclerView.setAdapter(whitelistadapter);
    Subscription subscription = WhitelistHelper.getWhitelistFolders().map(whitelistFolders -> Stream.of(whitelistFolders).map(folder -> (AdaptableItem) new WhitelistView(folder)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(whitelistViews -> {
        if (whitelistViews.size() == 0) {
            whitelistadapter.addItem(0, new EmptyView(R.string.whitelist_empty));
        } else {
            whitelistadapter.setItems(whitelistViews);
        }
    });
    dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
    dialog.show();
}
Also used : WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Subscription(rx.Subscription) 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) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Aggregations

Dialog (android.app.Dialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ListView (android.widget.ListView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 WhitelistAdapter (com.simplecity.amp_library.ui.adapters.WhitelistAdapter)1 BlacklistView (com.simplecity.amp_library.ui.modelviews.BlacklistView)1 ColorView (com.simplecity.amp_library.ui.modelviews.ColorView)1 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)1 WhitelistView (com.simplecity.amp_library.ui.modelviews.WhitelistView)1 Subscription (rx.Subscription)1