UltimateRecyclerView icon indicating copy to clipboard operation
UltimateRecyclerView copied to clipboard

Support Coordinatorlayout / Appbarlayout

Open jensneuse opened this issue 10 years ago • 8 comments

Hey, will you support the new android design library?

AS long as your recycler is wrapped inside a framelayout it won't work.

Changing ultimateRV to a Coordinatorlayout might work. One could then add a Appbarlayout directly to the Coordinatorlayout. Nevertheless, adding additional content to the screen might get complicated.

I could also imagine that wrapping RV into a swiperefreshlayout could break connection to Coordinatorlayout.

After all, the easiest way to manage this seems to directly put a RV into the Coordinatorlayout, which would make me drop ultimateRV in the current state.

jensneuse avatar Jul 01 '15 08:07 jensneuse

Thank you so much for your input, could you start a simple abstract class and put it in here?

jjhesk avatar Jul 01 '15 14:07 jjhesk

Would you go a little more into detail about your request? I'm not 100% sure..

Besides I'd like to first figure out if there are different possibilities like adding the necessary Flags to mRecycler programmatically. Hopefully it's manageable without a complete refactoring.

The way ultimateRV implemented StickyHeaders is just so lazy that I really don't want to drop it.

jensneuse avatar Jul 01 '15 14:07 jensneuse

I think add some features of android design library is pretty good.However,the URV is a FrameLayout rather than a child class of Recyclerview so I'm not sure which is the best way to add those feature into the URV.We hope to listen your idea about this.

cymcsg avatar Jul 02 '15 03:07 cymcsg

According to a blog I was thinking that you cannot put a Framelayout directly into Coordinatorlayout and just make it work. http://inthecheesefactory.com/blog/android-design-support-library-codelab/en They say just the Recyclerview + support.v4.NestedScrollview will work.

tldr - You can, of course, put FrameLayout inside CoordinatorLayout! There's just two things: In order to accomplish those sweet interactions with AppBarLayout you have to put either Recycler or NestedScrollview inside your FrameLayout AND make sure to add app:layout_behavior="@string/appbar_scrolling_view_behavior" to your FrameLayout.

In this case our FrameLayout = UltimateRecyclerView so your Layout should look somewhat like this and it just works! (even SwipeRefreshLayout still works):

android.support.design.widget.CoordinatorLayout android:id="@+id/coordinatorLayout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_material_light">

<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
    android:id="@+id/ultimate_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_material_light"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:recyclerviewScrollbars="vertical"/>

<com.xxx.xxx.layout.ControllableAppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:title="Toolbar"/>

</com.xxx.xxx.layout.ControllableAppBarLayout>

</android.support.design.widget.CoordinatorLayout>

ControllableAppBarLayout origins from here: https://gist.github.com/blipinsk/3f8fb37209de6d3eea99

It adds the functionality to expand/collapse the Layout from code.

To sum up I suggest to the library owner to deprecate stuff like internal Toolbar interaction via Listeners and transitions as there is no more need for these. You will get this functionality without any code, just via XML.

jensneuse avatar Jul 02 '15 06:07 jensneuse

Thank you so much for your advise @jnsone11. Would u like to add this into the sample app folder as an new activity?

jjhesk avatar Jul 02 '15 08:07 jjhesk

I'll pull it when there's some time to put things together. Glad to contribute to such a great lib.

By the way, I found a bug when using swipeRefreshLayout. If you are using Coordinatorlayout with a scrollable Toolbar + SRL, the SRL steals the swipeDown before the Toolbar is able to appear.

Means: swipeRefresh gets activated before you can pull down the Toolbar which I think is not what a user expects. I'm looking forward to get some kind of listener attached to the Coordinatorlayout to indicate whether Toolbar is visible or not. I'd then activate/deactivate SwipeRefresh according to the ToolbarVisibilityState.

Unfortunately I've not yet figured out what to listen to. I'd be very glad if anyone has an idea. I have not yet found any solution on Stackoverflow.

jensneuse avatar Jul 02 '15 08:07 jensneuse

You need to extend your activity from AppBarLayout.OnOffsetChangedListener and then add the following code

 int index = 0;

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    index = i;
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    switch (action) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            BasePagedListFragment basePagedListFragment = viewPagerAdapter.getFragment(pager.getCurrentItem());
            if (basePagedListFragment != null) {
                if (index == 0) {
                    basePagedListFragment.setSwipeToRefreshEnabled(true);
                } else {
                    basePagedListFragment.setSwipeToRefreshEnabled(false);
                }
            }
            break;
    }
    return super.dispatchTouchEvent(ev);
}

pochadri avatar Aug 11 '15 05:08 pochadri

With the current support library I believe it works without changes. I'd suggest closing this issue.

ackushiw avatar Jul 21 '16 21:07 ackushiw