Skip to content

Commit

Permalink
Resolved #217 - Data binding in DemoApp
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed May 2, 2017
1 parent b50295e commit 20c2b7e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ private void hideFab() {

private void showFab() {
if (mFragment instanceof FragmentHeadersSections ||
mFragment instanceof FragmentDataBinding ||
mFragment instanceof FragmentStaggeredLayout ||
mFragment instanceof FragmentAsyncFilter) {
ViewCompat.animate(mFab)
Expand Down Expand Up @@ -838,7 +839,8 @@ public void onUpdateEmptyView(int size) {
mRefreshHandler.sendEmptyMessage(2);
fastScroller.setVisibility(View.GONE);
}
if (mAdapter != null && !mAdapter.isRestoreInTime()) {
if (mAdapter != null && !mAdapter.isRestoreInTime() &&
DatabaseService.getInstance().getDatabaseType() != DatabaseType.DATA_BINDING) {
String message = (mAdapter.hasSearchText() ? "Filtered " : "Refreshed ");
message += size + " items in " + mAdapter.getTime() + "ms";
Snackbar.make(findViewById(R.id.main_view), message, Snackbar.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import eu.davidea.flipview.FlipView;
import eu.davidea.samples.flexibleadapter.R;
import eu.davidea.samples.flexibleadapter.animators.GarageDoorItemAnimator;
import eu.davidea.samples.flexibleadapter.items.AbstractItem;
import eu.davidea.samples.flexibleadapter.items.HeaderItem;
import eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem;
import eu.davidea.samples.flexibleadapter.services.DatabaseConfiguration;
import eu.davidea.samples.flexibleadapter.services.DatabaseService;

Expand Down Expand Up @@ -71,7 +73,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
FlipView.resetLayoutAnimationDelay(true, 1000L);

//Create New Database and Initialize RecyclerView
DatabaseService.getInstance().createHeadersSectionsDatabase(12, 4);
DatabaseService.getInstance().createDataBindingDatabase(12, 4);
initializeRecyclerView(savedInstanceState);

//Restore FAB button and icon
Expand All @@ -83,20 +85,20 @@ public void onActivityCreated(Bundle savedInstanceState) {

@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
//Initialize Adapter and RecyclerView
// Initialize Adapter and RecyclerView
mAdapter = new BindingFlexibleAdapter<>(getActivity(), true);
//Experimenting NEW features (v5.0.0)
// Experimenting NEW features (v5.0.0)
mAdapter.setNotifyChangeOfUnfilteredItems(true)//We have highlighted text while filtering, so let's enable this feature to be consistent with the active filter
.setAnimationOnScrolling(DatabaseConfiguration.animateOnScrolling);
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setHasFixedSize(true); //Size of RV will not change
//NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
// NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
// a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
mRecyclerView.setItemAnimator(new GarageDoorItemAnimator());

//Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
FastScroller fastScroller = (FastScroller) getView().findViewById(R.id.fast_scroller);
mAdapter.setFastScroller(fastScroller);
mAdapter.setLongPressDragEnabled(true)
Expand All @@ -108,6 +110,10 @@ private void initializeRecyclerView(Bundle savedInstanceState) {
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);

mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(
getString(R.string.databinding_use_case_title),
getString(R.string.databinding_use_case_description)), 500L, false);
}

@Override
Expand All @@ -116,9 +122,13 @@ public void performFabAction() {
items.addAll(DatabaseService.getInstance().getDatabaseList());
} else if (fabClickedTimes == 2) {
HeaderItem headerItem = DatabaseService.newHeader(mAdapter.getItemCountOfTypes(R.layout.recycler_header_item) + 1);
items.add(1, DatabaseService.newSimpleItem(fabClickedTimes * 111, headerItem));
AbstractItem newItem = DatabaseService.newSimpleItem(fabClickedTimes * 111, headerItem);
items.add(1, newItem);
DatabaseService.getInstance().addItem(1, newItem); //Refreshing is consistent too
} else {
items.add(0, DatabaseService.newSimpleItem(fabClickedTimes * 111, null));
AbstractItem newItem = DatabaseService.newSimpleItem(fabClickedTimes * 111, null);
items.add(0, newItem);
DatabaseService.getInstance().addItem(0, newItem); //Refreshing is consistent too
}
++fabClickedTimes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void run() {
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
getString(R.string.selection_modes_use_case_description)), 1200L, true
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public void createHeadersSectionsDatabase(int size, int headers) {
}
}

/*
* Same as HeadersSection, but with different property type
*/
public void createDataBindingDatabase(int size, int headers) {
createHeadersSectionsDatabase(size, headers);
databaseType = DatabaseType.DATA_BINDING;
}

/*
* List of Holder Items and Header. Only Holder Simple Items will be
* added to the list. IHolder items hold the model data inside.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum DatabaseType {
EXPANDABLE_SECTIONS,
EXPANDABLE_MULTI_LEVEL,
ENDLESS_SCROLLING,
DATA_BINDING,
MODEL_HOLDERS,
LAYOUT_HORIZONTAL,
LAYOUT_STAGGERED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:title="@string/filter"/>
<item
android:id="@+id/nav_animator"
android:icon="@drawable/ic_animation_grey600_24dp"
android:icon="@drawable/ic_chart_gantt_grey600_24dp"
android:title="@string/animator"/>
<item
android:id="@+id/nav_headers_and_sections"
Expand Down Expand Up @@ -89,9 +89,6 @@
android:id="@+id/nav_github"
android:icon="@drawable/ic_github_circle_grey600_24dp"
android:title="@string/github"/>
<!--<item-->
<!--android:id="@+id/nav_empty_space"-->
<!--android:title=""/>-->
</menu>
</item>

Expand Down
2 changes: 2 additions & 0 deletions flexible-adapter-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ Follow the steps in the <b>Wiki</b> page of the library.]]></string>

<string name="databinding">Data Binding</string>
<string name="databinding_description"><![CDATA[Data Binding Extension Library<br/><font color="#ff4081"><b>Check the code!</b>]]></string>
<string name="databinding_use_case_description">Refresh or tap FAB button to update dataset with Data Binding.</string>
<string name="databinding_use_case_title">Data Binding Extension</string>

<string name="expandable_sections">Expandable Sections</string>
<string name="expandable_sections_description">Sections with [sticky] headers that can expand/collapse + Draggable items + Filter + Scroll Animations</string>
Expand Down

0 comments on commit 20c2b7e

Please sign in to comment.