use of com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter 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.simplecityapps.recycler_adapter.adapter.ViewModelAdapter in project Shuttle by timusus.
the class TabChooserDialog method getDialog.
public static MaterialDialog getDialog(Activity activity) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
ViewModelAdapter adapter = new ViewModelAdapter();
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(adapter::moveItem, (fromPosition, toPosition) -> {
}, () -> {
}));
TabViewModel.Listener listener = new TabViewModel.Listener() {
@Override
public void onStartDrag(TabViewModel.ViewHolder holder) {
itemTouchHelper.startDrag(holder);
}
@Override
public void onFolderChecked(TabViewModel tabViewModel, TabViewModel.ViewHolder viewHolder) {
if (!ShuttleUtils.isUpgraded()) {
viewHolder.checkBox.setChecked(false);
tabViewModel.categoryItem.isChecked = false;
UpgradeDialog.getUpgradeDialog(activity).show();
}
}
};
List<ViewModel> items = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).map(categoryItem -> {
TabViewModel tabViewModel = new TabViewModel(categoryItem);
tabViewModel.setListener(listener);
return tabViewModel;
}).collect(Collectors.toList());
adapter.setItems(items);
RecyclerView recyclerView = new RecyclerView(activity);
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(adapter);
itemTouchHelper.attachToRecyclerView(recyclerView);
return new MaterialDialog.Builder(activity).title(R.string.pref_title_choose_tabs).customView(recyclerView, false).positiveText(R.string.button_done).onPositive((dialog, which) -> {
SharedPreferences.Editor editor = sharedPreferences.edit();
Stream.of(adapter.items).indexed().forEach(viewModelIntPair -> {
((TabViewModel) viewModelIntPair.getSecond()).categoryItem.sortOrder = viewModelIntPair.getFirst();
((TabViewModel) viewModelIntPair.getSecond()).categoryItem.savePrefs(editor);
});
LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(LibraryController.EVENT_TABS_CHANGED));
}).negativeText(R.string.close).build();
}
use of com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter in project Shuttle by timusus.
the class FolderFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
disposables = new CompositeDisposable();
adapter = new ViewModelAdapter();
fileBrowser = new FileBrowser();
if (savedInstanceState != null) {
currentDir = savedInstanceState.getString(ARG_CURRENT_DIR);
}
displayedInTabs = getArguments().getBoolean(ARG_DISPLAYED_IN_TABS);
if (displayedInTabs) {
setHasOptionsMenu(true);
}
}
use of com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter in project Shuttle by timusus.
the class PlaylistFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new ViewModelAdapter();
}
use of com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter in project Shuttle by timusus.
the class QueuePagerFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
viewModelAdapter = new ViewModelAdapter();
ShuttleApplication.getInstance().getAppComponent().plus(new FragmentModule(this)).inject(this);
}
Aggregations