Search in sources :

Example 1 with ErrorView

use of com.moro.mtweaks.views.recyclerview.customcontrols.ErrorView in project MTweaks-KernelAdiutorMOD by morogoku.

the class CustomControlsFragment method load.

private void load(List<RecyclerViewItem> items) {
    mControlsProvider = new Controls(getActivity());
    for (final Controls.ControlItem item : mControlsProvider.getAllControls()) {
        CardView cardView = getCard(item);
        cardView.clearItems();
        try {
            String title = item.getTitle();
            String description = item.getDescription();
            if (item.getControl() == Items.Control.SWITCH) {
                SwitchView switchView = new SwitchView();
                if (description != null) {
                    switchView.setTitle(title);
                    switchView.setSummary(description);
                } else {
                    switchView.setSummary(title);
                }
                switchView.setChecked(Values.getBool(item.getString("enable")));
                switchView.addOnSwitchListener(new SwitchView.OnSwitchListener() {

                    @Override
                    public void onChanged(SwitchView switchView, boolean isChecked) {
                        Values.run(item.getApply(), item, isChecked ? "1" : "0");
                        mControlsProvider.commit();
                    }
                });
                cardView.addItem(switchView);
            } else if (item.getControl() == Items.Control.SEEKBAR) {
                SeekBarView seekBarView = new SeekBarView();
                seekBarView.setTitle(title);
                if (description != null) {
                    seekBarView.setSummary(description);
                }
                seekBarView.setMax(item.getInt("max"));
                seekBarView.setMin(item.getInt("min"));
                seekBarView.setProgress(Values.getInt(item.getString("progress")));
                seekBarView.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {

                    @Override
                    public void onStop(SeekBarView seekBarView, int position, String value) {
                        Values.run(item.getApply(), item, String.valueOf(position));
                        mControlsProvider.commit();
                    }

                    @Override
                    public void onMove(SeekBarView seekBarView, int position, String value) {
                    }
                });
                cardView.addItem(seekBarView);
            } else if (item.getControl() == Items.Control.GENERIC) {
                GenericSelectView genericSelectView = new GenericSelectView();
                if (description != null) {
                    genericSelectView.setTitle(title);
                    genericSelectView.setSummary(description);
                } else {
                    genericSelectView.setSummary(title);
                }
                genericSelectView.setValue(Values.getString(item.getString("value")));
                genericSelectView.setValueRaw(genericSelectView.getValue());
                genericSelectView.setOnGenericValueListener(new GenericSelectView.OnGenericValueListener() {

                    @Override
                    public void onGenericValueSelected(GenericSelectView genericSelectView, String value) {
                        Values.run(item.getApply(), item, value);
                        genericSelectView.setValue(value);
                        mControlsProvider.commit();
                    }
                });
                cardView.addItem(genericSelectView);
            }
        } catch (CustomControlException e) {
            ErrorView errorView = new ErrorView();
            errorView.setException(e);
            cardView.addItem(errorView);
        }
        items.add(cardView);
    }
}
Also used : CustomControlException(com.moro.mtweaks.utils.tools.customcontrols.CustomControlException) SwitchView(com.moro.mtweaks.views.recyclerview.SwitchView) CardView(com.moro.mtweaks.views.recyclerview.CardView) SeekBarView(com.moro.mtweaks.views.recyclerview.SeekBarView) GenericSelectView(com.moro.mtweaks.views.recyclerview.GenericSelectView) Controls(com.moro.mtweaks.database.tools.customcontrols.Controls) ErrorView(com.moro.mtweaks.views.recyclerview.customcontrols.ErrorView)

Aggregations

Controls (com.moro.mtweaks.database.tools.customcontrols.Controls)1 CustomControlException (com.moro.mtweaks.utils.tools.customcontrols.CustomControlException)1 CardView (com.moro.mtweaks.views.recyclerview.CardView)1 GenericSelectView (com.moro.mtweaks.views.recyclerview.GenericSelectView)1 SeekBarView (com.moro.mtweaks.views.recyclerview.SeekBarView)1 SwitchView (com.moro.mtweaks.views.recyclerview.SwitchView)1 ErrorView (com.moro.mtweaks.views.recyclerview.customcontrols.ErrorView)1