Search in sources :

Example 6 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class MainActivity method onTitleModified.

/* ===============================================================
	 * DIALOG LISTENER IMPLEMENTATION (For the example of onItemClick)
	 * =============================================================== */
@Override
public void onTitleModified(int position, String newTitle) {
    AbstractFlexibleItem abstractItem = mAdapter.getItem(position);
    assert abstractItem != null;
    if (abstractItem instanceof AbstractItem) {
        AbstractItem exampleItem = (AbstractItem) abstractItem;
        exampleItem.setTitle(newTitle);
    } else if (abstractItem instanceof HeaderItem) {
        HeaderItem headerItem = (HeaderItem) abstractItem;
        headerItem.setTitle(newTitle);
    }
    mAdapter.updateItem(position, abstractItem, null);
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) AbstractItem(eu.davidea.samples.flexibleadapter.items.AbstractItem) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem)

Example 7 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class FragmentSelectionModes method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    //Get copy of the Database list
    List<AbstractFlexibleItem> items = DatabaseService.getInstance().getDatabaseList();
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new ExampleAdapter(items, getActivity());
    //This will rebind new item when refreshed
    mAdapter.setNotifyChangeOfUnfilteredItems(true).setMode(SelectableAdapter.MODE_SINGLE);
    // Experimenting NEW features (v5.0.0)
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    //Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // Divider item decorator with DrawOver enabled
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider).withDrawOver(true));
    mRecyclerView.postDelayed(new Runnable() {

        @Override
        public void run() {
            Snackbar.make(getView(), "Selection MODE_SINGLE is enabled", Snackbar.LENGTH_SHORT).show();
        }
    }, 1500L);
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_SINGLE);
    // Add 2 Scrollable Headers
    mAdapter.addUserLearnedSelection(savedInstanceState == null);
    mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(getString(R.string.selection_modes_use_case_title), getString(R.string.selection_modes_use_case_description)), 1100L, true);
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 8 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class DatabaseService method resetItems.

public void resetItems() {
    List<StaggeredItem> mergedItems = new ArrayList<>();
    for (AbstractFlexibleItem item : mItems) {
        if (item instanceof StaggeredItem) {
            StaggeredItem staggeredItem = (StaggeredItem) item;
            staggeredItem.setStatus(StaggeredItemStatus.C);
            staggeredItem.setHeader(headers.get(StaggeredItemStatus.C));
            mergedItems.addAll(staggeredItem.splitAllItems());
        }
    }
    for (StaggeredHeaderItem header : headers.values()) {
        header.setHidden(true);
    }
    mItems.addAll(mergedItems);
    Collections.sort(mItems, new ItemComparatorById());
    createMergedItems();
}
Also used : StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ArrayList(java.util.ArrayList) StaggeredItem(eu.davidea.samples.flexibleadapter.items.StaggeredItem)

Aggregations

AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)8 Test (org.junit.Test)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (eu.davidea.flexibleadapter.common.DividerItemDecoration)1 IExpandable (eu.davidea.flexibleadapter.items.IExpandable)1 IHeader (eu.davidea.flexibleadapter.items.IHeader)1 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)1 AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)1 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)1 HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)1 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)1 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)1 StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)1 StaggeredItem (eu.davidea.samples.flexibleadapter.items.StaggeredItem)1 SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)1 ArrayList (java.util.ArrayList)1