use of com.simplecity.amp_library.ui.modelviews.TabViewModel 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();
}
Aggregations