Search in sources :

Example 1 with InclExclView

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;
}
Also used : R(com.simplecity.amp_library.R) LogUtils(com.simplecity.amp_library.utils.LogUtils) Context(android.content.Context) Stream(com.annimon.stream.Stream) LayoutInflater(android.view.LayoutInflater) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) InclExclHelper(com.simplecity.amp_library.sql.databases.InclExclHelper) List(java.util.List) Toast(android.widget.Toast) View(android.view.View) DataManager(com.simplecity.amp_library.utils.DataManager) Observable(io.reactivex.Observable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InclExclItem(com.simplecity.amp_library.model.InclExclItem) Collections(java.util.Collections) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) SuppressLint(android.annotation.SuppressLint) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 2 with InclExclView

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());
}
Also used : InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) List(java.util.List) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel)

Aggregations

InclExclView (com.simplecity.amp_library.ui.modelviews.InclExclView)2 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)2 List (java.util.List)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 Toast (android.widget.Toast)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Stream (com.annimon.stream.Stream)1 R (com.simplecity.amp_library.R)1 InclExclItem (com.simplecity.amp_library.model.InclExclItem)1 InclExclHelper (com.simplecity.amp_library.sql.databases.InclExclHelper)1 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)1 DataManager (com.simplecity.amp_library.utils.DataManager)1 LogUtils (com.simplecity.amp_library.utils.LogUtils)1 ViewModelAdapter (com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)1 Observable (io.reactivex.Observable)1