Search in sources :

Example 1 with ViewModelAdapter

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;
}
Also used : R(com.simplecity.amp_library.R) LogUtils(com.simplecity.amp_library.utils.LogUtils) Context(android.content.Context) Stream(com.annimon.stream.Stream) LayoutInflater(android.view.LayoutInflater) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) InclExclHelper(com.simplecity.amp_library.sql.databases.InclExclHelper) List(java.util.List) Toast(android.widget.Toast) View(android.view.View) DataManager(com.simplecity.amp_library.utils.DataManager) Observable(io.reactivex.Observable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InclExclItem(com.simplecity.amp_library.model.InclExclItem) Collections(java.util.Collections) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) SuppressLint(android.annotation.SuppressLint) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) InclExclView(com.simplecity.amp_library.ui.modelviews.InclExclView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 2 with ViewModelAdapter

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

Example 3 with ViewModelAdapter

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);
    }
}
Also used : FileBrowser(com.simplecity.amp_library.utils.FileBrowser) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 4 with ViewModelAdapter

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();
}
Also used : ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 5 with 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);
}
Also used : FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Aggregations

ViewModelAdapter (com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)16 RecyclerView (android.support.v7.widget.RecyclerView)7 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 R (com.simplecity.amp_library.R)5 List (java.util.List)5 LayoutInflater (android.view.LayoutInflater)4 View (android.view.View)4 FragmentModule (com.simplecity.amp_library.dagger.module.FragmentModule)4 Observable (io.reactivex.Observable)4 SuppressLint (android.annotation.SuppressLint)3 Context (android.content.Context)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 Stream (com.annimon.stream.Stream)3 Bundle (android.os.Bundle)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 PagerSnapHelper (android.support.v7.widget.PagerSnapHelper)2 SnapHelper (android.support.v7.widget.SnapHelper)2 ViewGroup (android.view.ViewGroup)2 ViewTreeObserver (android.view.ViewTreeObserver)2