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();
}
Aggregations