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