Nest Refresh

By this library, you can add Pull Refresh by behaviors for one groupview or view with nest child. You can add pull refresh for one top header and scroll top with sticky area. You can add CollapseToolbarLayout in the RefreshBarLayout to collapse when scroll up, pin tab layout on the top and pull refresh when pull down. You can add load more footer behavoir for your recyclerview. When you pull up at last of the recyclerview, the footer will be pull up with spring effect. You can set no more result when data have no more.

Screenshot

RefreshBar with Collapse Header Nest Scroll RefreshBar Single Refresh
nest_refresh_refreshbar_collapse nest_refresh_header_nest_scroll nest_refresh_refresh_bar nest_refresh_single

Installation

dependencies {
    implementation 'com.github.todou:nestrefresh:0.0.6'
}

AndroidX

dependencies {
    implementation 'com.github.todou:nestrefresh-androidx:0.0.6'
}

Usages

All behavoir as follows:

  • RefreshBarBehavior
    Defualt behavior for RefreshBarLayout
    
  • RefreshBarScrollBehavior
    @string/nest_refresh_bar_scroll_behavior
    
  • RefreshBehavior
    @string/nest_refresh_single_behavior
    
  • LoadMoreBehavior
    # default to LoadMoreFooterView
    @string/nest_refresh_load_more_behavior
    
  • RefreshScrollBehavior
    @string/nest_refresh_scroll_behavior
    

Single Nest Refresh with load more footer

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

    <com.todou.nestrefresh.RefreshHeaderView
        ...
        app:layout_behavior="@string/nest_refresh_single_behavior"/>

    <android.support.v7.widget.RecyclerView
        ...
        app:layout_behavior="@string/nest_refresh_scroll_behavior"/>

    <com.todou.nestrefresh.LoadMoreFooterView
        .../>

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

LoadMoreFooterView's default behavior is LoadMoreBehavior, so don't need to add behavior by yourself. And you can write your custom refresh header and custom load more footer with the behavior in the lib.

RefreshBarLayout Refresh with sticky

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

    <com.todou.nestrefresh.RefreshBarLayout
        ...>

        <com.todou.nestrefresh.RefreshHeaderView
            ...
            app:nr_layout_scrollFlags="flag_refresh_header"/>
 
        ...
        
        <android.support.design.widget.TabLayout
            ...
            app:nr_layout_scrollFlags="flag_sticky"/>
        
    </com.todou.nestrefresh.RefreshBarLayout>

    <android.support.v4.view.ViewPager
        ...
        app:layout_behavior="@string/nest_refresh_bar_scroll_behavior"/>

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

RefreshBarLayout Refresh with collapse toolbar

For inset status bar effect, you must add fitsSystemWindows true. And RefreshHeaderView in the default lib support compat inset

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

    <com.todou.nestrefresh.RefreshBarLayout
        android:fitsSystemWindows="true">

        <com.todou.nestrefresh.RefreshHeaderView
            app:nr_layout_scrollFlags="flag_refresh_header"/>

        <com.todou.nestrefresh.NRCollapsingToolbarLayout
            android:fitsSystemWindows="true"
            app:nr_layout_scrollFlags="flag_collapse">

            <ImageView
                ...
                android:fitsSystemWindows="true"
                app:nr_layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                app:nr_layout_collapseMode="pin"/>

        </com.todou.nestrefresh.NRCollapsingToolbarLayout>

    </com.todou.nestrefresh.RefreshBarLayout>

    <android.support.v4.widget.NestedScrollView
        ...
        app:layout_behavior="@string/nest_refresh_bar_scroll_behavior">

        ...

    </android.support.v4.widget.NestedScrollView>

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

Load More Footer

If you want to add load more footer for whole scroll child such as viewpager. You can add LoadMoreBehavior directly. If you want add load more footer for recyclerview in fragment of ViewPager, you must wrapper every recyclerview with ChildCoordinatorLayout. ChildCoordinatorLayout will send unconsumeY to parent and then send to child behavior to itself.
Like this in fragment layout of viewpager:

<com.todou.nestrefresh.ChildCoordinatorLayout
    ...>

    <android.support.v7.widget.RecyclerView
        ...
        app:layout_behavior="@string/nest_refresh_scroll_behavior"/>

    <com.todou.nestrefresh.LoadMoreFooterView
        .../>

</com.todou.nestrefresh.ChildCoordinatorLayout>

Because of onNestedScroll can't return consumes, I calculate that by target offsetInWindow. So if CoordinatorLayout's child consume some 'y' and has move with offset. The ChildCoordinatorLayout can get the consume from that and then send unconsume 'y' to child of ChildCoordinatorLayout to consume value.

Add refresh callback

view_refresh_header.setOnRefreshListener(object : OnRefreshListener {
    override fun onRefresh() {
        //Todo test code when network finish, you muast stop refresh by view_refresh_header.stopRefresh()
        view_refresh_header.postDelayed({
            view_refresh_header.stopRefresh()
        }, 2000)
    }
})
        

Add load more callback

view_footer.setOnLoadMoreListener(object : OnLoadMoreListener {
    override fun onLoadMore() {
        //Todo test code when network finish stop load more
        view_footer.postDelayed({
            view_footer.stopLoadMore()
        }, 2000)
    }
})

//Set has more 
view_footer.setHasMore(hasMore)

GitHub