use of com.simplecity.amp_library.ui.modelviews.InclExclView in project Shuttle by timusus.
the class InclExclDialog method getDialog.
public static MaterialDialog getDialog(Context context, @InclExclItem.Type int type) {
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.dialog_incl_excl, null);
final MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getTitleResId(type)).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_whitelist).onNegative((materialDialog, dialogAction) -> {
InclExclHelper.deleteAllItems(type);
Toast.makeText(context, getItemsDeletedResId(type), Toast.LENGTH_SHORT).show();
});
final MaterialDialog dialog = builder.build();
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
final ViewModelAdapter inclExclAdapter = new ViewModelAdapter();
recyclerView.setAdapter(inclExclAdapter);
InclExclView.ClickListener listener = inclExclView -> {
InclExclHelper.deleteInclExclItem(inclExclView.inclExclItem);
if (inclExclAdapter.items.size() == 0) {
dialog.dismiss();
}
};
getItems(type, listener).observeOn(AndroidSchedulers.mainThread()).subscribe(inclExclViews -> {
if (inclExclViews.size() == 0) {
inclExclAdapter.setItems(Collections.singletonList(new EmptyView(getItemsEmptyResId(type))));
} else {
inclExclAdapter.setItems(inclExclViews);
}
}, error -> LogUtils.logException(TAG, "Error setting incl/excl items", error));
return dialog;
}
use of com.simplecity.amp_library.ui.modelviews.InclExclView in project Shuttle by timusus.
the class InclExclDialog method getItems.
private static Observable<List<ViewModel>> getItems(@InclExclItem.Type int type, InclExclView.ClickListener listener) {
Observable<List<InclExclItem>> items = type == InclExclItem.Type.INCLUDE ? DataManager.getInstance().getIncludeItems() : DataManager.getInstance().getExcludeItems();
return items.map(inclExclItems -> Stream.of(inclExclItems).map(inclExclItem -> {
InclExclView inclExclView = new InclExclView(inclExclItem);
inclExclView.setClickListener(listener);
return (ViewModel) inclExclView;
}).toList());
}
Aggregations