diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java index 24690c60..45ebc870 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java @@ -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) @@ -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(); diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentDataBinding.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentDataBinding.java index 457b643b..358cf77f 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentDataBinding.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentDataBinding.java @@ -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; @@ -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 @@ -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) @@ -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 @@ -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; } diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentSelectionModes.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentSelectionModes.java index 26f75356..f9a897aa 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentSelectionModes.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/fragments/FragmentSelectionModes.java @@ -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 ); } diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseService.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseService.java index d012e079..17e31c6c 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseService.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseService.java @@ -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. diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseType.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseType.java index 2529fd2c..34daf20f 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseType.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/services/DatabaseType.java @@ -9,6 +9,7 @@ public enum DatabaseType { EXPANDABLE_SECTIONS, EXPANDABLE_MULTI_LEVEL, ENDLESS_SCROLLING, + DATA_BINDING, MODEL_HOLDERS, LAYOUT_HORIZONTAL, LAYOUT_STAGGERED, diff --git a/flexible-adapter-app/src/main/res/menu/activity_entry_drawer.xml b/flexible-adapter-app/src/main/res/menu/activity_entry_drawer.xml index b83d7ea6..9b4f0f3e 100644 --- a/flexible-adapter-app/src/main/res/menu/activity_entry_drawer.xml +++ b/flexible-adapter-app/src/main/res/menu/activity_entry_drawer.xml @@ -18,7 +18,7 @@ android:title="@string/filter"/> - - - diff --git a/flexible-adapter-app/src/main/res/values/strings.xml b/flexible-adapter-app/src/main/res/values/strings.xml index ab125954..da4134d6 100644 --- a/flexible-adapter-app/src/main/res/values/strings.xml +++ b/flexible-adapter-app/src/main/res/values/strings.xml @@ -131,6 +131,8 @@ Follow the steps in the Wiki page of the library.]]> Data Binding Check the code!]]> + Refresh or tap FAB button to update dataset with Data Binding. + Data Binding Extension Expandable Sections Sections with [sticky] headers that can expand/collapse + Draggable items + Filter + Scroll Animations