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