Search in sources :

Example 1 with TabViewModel

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();
}
Also used : R(com.simplecity.amp_library.R) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) CategoryItem(com.simplecity.amp_library.model.CategoryItem) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) SharedPreferences(android.content.SharedPreferences) LibraryController(com.simplecity.amp_library.ui.fragments.LibraryController) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) PreferenceManager(android.preference.PreferenceManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Activity(android.app.Activity) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) TabViewModel(com.simplecity.amp_library.ui.modelviews.TabViewModel) RecyclerView(android.support.v7.widget.RecyclerView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Aggregations

Activity (android.app.Activity)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PreferenceManager (android.preference.PreferenceManager)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 R (com.simplecity.amp_library.R)1 CategoryItem (com.simplecity.amp_library.model.CategoryItem)1 LibraryController (com.simplecity.amp_library.ui.fragments.LibraryController)1 TabViewModel (com.simplecity.amp_library.ui.modelviews.TabViewModel)1 ItemTouchHelperCallback (com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback)1 ShuttleUtils (com.simplecity.amp_library.utils.ShuttleUtils)1 ViewModelAdapter (com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)1 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)1 List (java.util.List)1