Giter Club home page Giter Club logo

android-ultra-pull-to-refresh-with-load-more's Introduction

Ultra Pull To Refresh with Load More

This is a modification of the Ultra-Pull-to-Refresh library which supports load-more for any view.

Updates for 1.0.3

In order to add more features, I have separated some of configuration which was shared by header and footer before, like resistance and durationToClose. To avoid misunderstanding of variable and configuration names, there are some changes that you need to be aware.

  • in the old version, ptr_duration_to_close means the time to back to refreshing position when release and so as the function setDurationToClose. In the meanwhile, ptr_duration_to_close_header means the time to hide the header. This is a little bit confusing especially when add more features for footer. So, in the new version, there is no ptr_duration_to_close but ptr_duration_to_back_refresh instead. Also, the header and footer can separated by ptr_duration_to_back_header and ptr_duration_to_back_footer.
  • ptr_duration_to_close_either means the time to back to start position (which is invisible) when refreshing completed.
  • ptr_resistance can also be separated by ptr_resistance_header and ptr_resistance_footer.

Check the class FooterFeatures for some features I have added for footer. I'd like to receiver any feedback for improvement.

Load more

Ultra Pull to Refresh is a replacement for the deprecated pull to refresh solution. It can contain any view you want. It's easy to use and more powerful than SwipeRefreshLayout. It's well designed, you can customize the UI effect you want as easy as adding a headview to ListView.

It supports every view as well. All the logic is similar to the pull-to-refresh and the configurations(resistance, duration etc.) are shared for both load-more and pull-to-refresh. All the APIs for the origin branch are not modified. If you have used the origin Ultra-Pull-To-Refresh library, there will be no need to change your code if you move to this branch.

Currently, only the Home page(PtrDemoHomeFragment) and AutoRefresh(WithGridView) page in demo are modified to demonstrate how to use load-more.

Support API LEVEL >= 8, all snapshots are taken from Genymotion, 2.3.7.

New functions and classes

  • setFooterView: Corresponding to setHeaderView(). You may also need call addPtrUIHandler() after setting the footer view, which is the same mechanism as setting header.
  • PtrHandler2: A complementary of PtrHandler. When using load more function, you should call setPtrHandler(new PtrHandler2()), rather than setPtrHandler(new PtrHandler()).
  • PtrDefaultHandler2: Implemented a default checkCanDoLoadMore() logic. The same mechanism as PtrDefaultHandler.
  • PtrClassicDefaultFooter: Serve as a default footer which is the reverse of the default header.
  • setMode(Mode): The mode is a new feature of this library. By using setMode, you can enable or disable either header or footer. The argument is an enum, you should it like setMode(Mode.BOTH).

Usage

  • in gradle:
    compile 'in.srain.cube:ptr-load-more:1.0.6'
  • in maven:

<dependency>
	<groupId>in.srain.cube</groupId>
	<artifactId>ptr-load-more</artifactId>
	<version>1.0.6</version>
	<type>pom</type>
</dependency>

Contacts

If there is any suggestions or problems, please feel no hesitated to open an issue. I will keep responsing.


Build Status Android Arsenal

Ultra Pull To Refresh

Download APK

  • StoreHouse Style first! Thanks to CBStoreHouseRefreshControl.

  • Material Style, added @ 2014-12-09. There is a beautiful shadow which looks terrible in gif snapshot. Please Check out the DEMO.

  • Supports all of the views: ListView, GridView, ScrollView, FrameLayout, or Even a single TextView.

  • Supports all of the refresh types.

    • pull to refresh

    • release to refresh

    • keep header when refresh

    • hide header when refresh

    • auto refresh

Usage

Maven Central

This project has been pushed to Maven Central, both in aar and apklib.

The latest version: 1.0.11, has been published to: https://oss.sonatype.org/content/repositories/snapshots, in gradle:

maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
}

The stable version: 1.0.11, https://oss.sonatype.org/content/repositories/releases, in gradle:

mavenCentral()

pom.xml, latest version:

<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    <!-- or apklib format, if you want -->
    <!-- <type>apklib</type> -->
    <version>1.0.11</version>
</dependency>

pom.xml, stable version:

<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    <!-- or apklib format, if you want -->
    <!-- <type>apklib</type> -->
    <version>1.0.11</version>
</dependency>

gradle, latest version:

compile 'in.srain.cube:ultra-ptr:1.0.11'

gradle, stable version:

compile 'in.srain.cube:ultra-ptr:1.0.11'

Config

There are 6 properties:

  • Resistence

    This is the resistence while you are moving the frame, default is: 1.7f.

  • Ratio of the Height of the Header to Refresh

    The ratio of the height of the header to trigger refresh, default is: 1.2f.

  • Duration to Close

    The duration for moving from the position you relase the view to the height of header, default is 200ms.

  • Duration to Close Header

    The default value is 1000ms

  • Keep Header while Refreshing

    The default value is true.

  • Pull to Refresh / Release to Refresh

    The default value is Release to Refresh.

Config in xml
<in.srain.cube.views.ptr.PtrFrameLayout
    android:id="@+id/store_house_ptr_frame"
    xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    cube_ptr:ptr_resistance="1.7"
    cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
    cube_ptr:ptr_duration_to_close="300"
    cube_ptr:ptr_duration_to_close_header="2000"
    cube_ptr:ptr_keep_header_when_refresh="true"
    cube_ptr:ptr_pull_to_fresh="false" >

    <LinearLayout
        android:id="@+id/store_house_ptr_image_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/cube_mints_333333"
        android:clickable="true"
        android:padding="10dp">

        <in.srain.cube.image.CubeImageView
            android:id="@+id/store_house_ptr_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

</in.srain.cube.views.ptr.PtrFrameLayout>

Or config in java code

// the following are default settings
mPtrFrame.setResistance(1.7f);
mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
mPtrFrame.setDurationToClose(200);
mPtrFrame.setDurationToCloseHeader(1000);
// default is false
mPtrFrame.setPullToRefresh(false);
// default is true
mPtrFrame.setKeepHeaderWhenRefresh(true);

Other Config

  • setPinContent. Pin the content, only the HeaderView will be moved.

    This's the the performance of material style in support package v19.

StoreHouse Style

  • Config using string:
// header
final StoreHouseHeader header = new StoreHouseHeader(getContext());
header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);

/**
 * using a string, support: A-Z 0-9 - .
 * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar}
 */
header.initWithString('Alibaba');
  • Config using string array from xml:
header.initWithStringArray(R.array.storehouse);

And in res/values/arrays.xml:

<resources>
    <string-array name="storehouse">
        <item>0,35,12,42,</item>
        <item>12,42,24,35,</item>
        <item>24,35,12,28,</item>
        <item>0,35,12,28,</item>
        <item>0,21,12,28,</item>
        <item>12,28,24,21,</item>
        <item>24,35,24,21,</item>
        <item>24,21,12,14,</item>
        <item>0,21,12,14,</item>
        <item>0,21,0,7,</item>
        <item>12,14,0,7,</item>
        <item>12,14,24,7,</item>
        <item>24,7,12,0,</item>
        <item>0,7,12,0,</item>
    </string-array>
</resources>

Process Refresh

There is a PtrHandler, by which you can refresh the data.

public interface PtrHandler {

    /**
     * Check can do refresh or not. For example the content is empty or the first child is in view.
     * <p/>
     * {@link in.srain.cube.views.ptr.PtrDefaultHandler#checkContentCanBePulledDown}
     */
    public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);

    /**
     * When refresh begin
     *
     * @param frame
     */
    public void onRefreshBegin(final PtrFrameLayout frame);
}

An example:

ptrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        frame.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrFrame.refreshComplete();
            }
        }, 1800);
    }

    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }
});

Customize

You can add a PtrUIHandler to PtrFrameLayout to implement any UI effect you want.

public interface PtrUIHandler {

    /**
     * When the content view has reached top and refresh has been completed, view will be reset.
     *
     * @param frame
     */
    public void onUIReset(PtrFrameLayout frame);

    /**
     * prepare for loading
     *
     * @param frame
     */
    public void onUIRefreshPrepare(PtrFrameLayout frame);

    /**
     * perform refreshing UI
     */
    public void onUIRefreshBegin(PtrFrameLayout frame);

    /**
     * perform UI after refresh
     */
    public void onUIRefreshComplete(PtrFrameLayout frame);

    public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, int oldPosition, int currentPosition, float oldPercent, float currentPercent);
}

Q & A

  • work with ViewPager: disableWhenHorizontalMove()

  • work with LongPressed, setInterceptEventWhileWorking()

Contact & Help

Please fell free to contact me if there is any problem when using the library.

android-ultra-pull-to-refresh-with-load-more's People

Contributors

captainbupt avatar fanturbo avatar vitess avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-ultra-pull-to-refresh-with-load-more's Issues

设置自定义底部时的一个Bug

PtrFrameLayout类中的setFooterView()方法有问题 会导致我一旦重新自定义一个底部view的话就会removeView(mHeaderView)把header给去掉了 实际上应该去掉的是默认的footer

应该改为 public void setFooterView(View footer) {
if (mFooterView != null && footer != null && mFooterView != footer) {
removeView(mFooterView);
}
ViewGroup.LayoutParams lp = footer.getLayoutParams();
if (lp == null) {
lp = new LayoutParams(-1, -2);
footer.setLayoutParams(lp);
}
mFooterView = footer;
addView(footer);
}

源代码 是这样的 你看看
public void setFooterView(View footer) {
if (mFooterView != null && footer != null && mHeaderView != footer) {
removeView(mHeaderView);
}
ViewGroup.LayoutParams lp = footer.getLayoutParams();
if (lp == null) {
lp = new LayoutParams(-1, -2);
footer.setLayoutParams(lp);
}
mFooterView = footer;
addView(footer);
}g

作者您好,您的这个封装十分好,但是感觉就是少了一种模式

现在你只有2个模式,单独下拉刷新模式PtrDefaultHandler,下拉,上拉模式PtrDefaultHandler2,但是仔细想想,诸如搜索记录这种使用场景,是个单独上拉刷新模式,所以,现在差一种使用场景,希望作者可以加上这最后一种使用场景,我是使用您的源码自己封装了下,但是我感觉您封装出来一个额外的接口,供给大家使用更好,麻烦您阅读了!

作者你好,今天遇到一个问题

用这个控件里面是recyclerview,recyclerview的第一个条目是viewpager,当我滑动viewpager的时候会很容易触发下拉效果,这样会导致viewpager很难翻页,应该是廖虎秋的下拉在顶部的时候太灵敏了,能有解决方案吗

setPinContent()

1.setPinContent() 上拉 和 下拉 能不能区分开啊!
2.上拉加载的时候能不能控制 不能下拉 反之!

使用setMode() 方法没有效果??demo中也没使用栗子,如何用?

。。。。
recycleViewAdapter = new ArtRecycleViewAdapter(this);
recycleView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recycleView.addItemDecoration(new DividerItemDecoration(this));
recycleView.setAdapter(recycleViewAdapter);
mPtrFrame.setPtrHandler(new PtrDefaultHandler() {
@OverRide
public void onRefreshBegin(PtrFrameLayout frame) {
page=1;
isRefresh=true;
hasMore = true;
loadData(page, mode, "0", deviceId, "0");
}
});
mPtrFrame.setMode(PtrFrameLayout.Mode.REFRESH); //setmode()????
mPtrFrame.setOffsetToRefresh(200);
mPtrFrame.autoRefresh(true);
CustomPtrHeader header = new CustomPtrHeader(this,mode);
mPtrFrame.setHeaderView(header);
mPtrFrame.addPtrUIHandler(header);
。。。
setMode()方法在哪里调用,如何用

scrollView 顶部viewpager 滑动和下拉有点冲突

嵌套scrollView 顶部如果是viewpager的话,滑动viewpager会跟下拉刷新冲突;
只有当水平滑动或者水平偏上滑动viewpager才能滑动viewpager,只要有一点点水平偏下滑动viewpager的话,就会触发下拉。

gradle

1.0.6的 gradle引用不了
1.0.11的两个版本 也按文档添加了也引用不了 咋回事诶

加载更多

加载更多.在加载完成后,“加载完成.”四个字没有消失。出现的几率不大,偶尔会出现这种情况
image;正常加载完是:
image

自动显示“正在加载”可以实现吗?

现在好多App,都是滚动到底部以后,就自动显示一条“正在加载”的内容,请问现有的代码通过设置属性可以实现吗? 我看现在是到底以后,再要pull一下才能显示。

loadmore时的bug

1、连续loadmore的时候,会一直显示加载完成。
2、loadmore之后,必须再向上滑动一下才能看到新的内容。

连续向上滑动受阻

谢谢你加入了加载更多的功能,但是连续向上滑动的时候,好像有时不能滑动,或者有助力

scrollview 嵌套问题

Scrollview嵌套 重写 的(ListView)MyListView 上拉 加载 无法 实现 改功能

if a view height is wrap_content

if a view height is wrap_content, then it will display loadmore view.
such as EvenOnlyATextView Fragment, set TextView height wrap_content.

使用Scrollview上拉加载问题

使用in.srain.cube.views.ptr.PtrClassicFrameLayout包含ScrollView,当内容不足一屏时,设置Mode为Refresh时,刷新时,尾部布局自动出现,并出现而且布局没有移动,刷新完后显示更新完成,不能消失

下拉刷新出现footer的信息(上拉加载)

我的根视图是<com.yyydjk.library.DropDownMenu/>;
在代码中动态的将PtrClassicFrameLayout 添加进DropDownMenu(条件筛选控件),设置ptrCFL.setPtrHandler(new PtrDefaultHandler2(){...}); 下拉刷新的时候就会出现footer.
请问这个该如何解决?

加载更多不消失

加载更多完成 然后本应该消失的view一直显示 需要点一下或者动他一下才会消失,请问这个怎么解决?

下拉刷新和Viewpager的左右滑动问题

在我布局中有viewpager,当我左右滑动的时候(向斜下方滑动),就会触发下拉刷新,这里能不能判断一下,如果是左右滑动,就不触发下拉刷新?

上拉刷新和下拉刷新是共用最后刷新时间的?

两个问题:

  1. 有无办法解决分开统计上拉时间和下拉时间
  2. 由于head和footer共用的一个xml,导致想修改下面的文字时发现修改到上面去了,或者说下方的加载更多一般不需要时间,这个如何修改?

是否在Release 1.0.1时没有执行Clean操作?

我的gradle依赖是这样写的:

compile 'in.srain.cube:ptr-load-more:1.0.1'

但是仍然存在Issue #2 的问题。起初以为是我的工程没有刷新,多次执行gradle clean后问题仍然存在,所以我在项目中使用Cmd+Shift+O,分别打开下面两个PtrFrameLayout文件:

  • {project}/build/intermediates/exploded-aar/in.srain.cube/ptr-load-more/1.0.1/jars/classes.jar!/in/srain/cube/views/ptr/PtrFrameLayout.class
  • {user}/.gradle/caches/modules-2/files-2.1/in.srain.cube/ptr-load-more/1.0.1/190d22489ebf866d83da715fe5a094648c3cf9ab/ptr-load-more-1.0.1-sources.jar!/in/srain/cube/views/ptr/PtrFrameLayout.java

在AS的提示里,第一个是ptr-load-more-1.0.1.jar, 另一个是ptr-load-more-1.0.1-sources.jar。问题出现了!
在第一个里,看到的是这样:

    private static final boolean DEBUG_LAYOUT = true;
    public static boolean DEBUG = true;

而另一个长这样:

    private static final boolean DEBUG_LAYOUT = false;
    public static final boolean DEBUG = false;

我将jcenter的aar文件单独下载解压,使用jd-gui反编译,看到的变量值也为true

所以,请允许我冒昧揣测一下,是不是在release的时候并没有clean操作?能否重新上传一个版本到jcenter,Thanks。

上拉加载更多体验不好

当上拉加载显示加载完成后,想马上看加载出来的更多的内容,显示不了,需要等大约半秒后才可以。

见意,加载更多显示加载完后成。主页面不要下移,直接隐掉footer,然后新内容直接显示填充到footer的位置。

发布Release应该关闭调试日志输出。

我在使用_ptr-load-more 1.0.0_时发现PtrFrameLayout类的View调试输出一直刷屏,类似这样:

03-21 17:06:34.199 21978-21978/com.example.app V/ptr-frame-4: updatePos: change: -2, current: 11 last: 13, top: 13, headerHeight: 211
03-21 17:06:34.214 21978-21978/com.example.app V/ptr-frame-4: scroll: false, start: 211, to: 0, currentPos: 11, current :-201, last: -200, delta: -1
03-21 17:06:34.214 21978-21978/com.example.app V/ptr-frame-4: updatePos: change: -1, current: 10 last: 11, top: 11, headerHeight: 211
03-21 17:06:34.231 21978-21978/com.example.app V/ptr-frame-4: scroll: false, start: 211, to: 0, currentPos: 10, current :-202, last: -201, delta: -1
03-21 17:06:34.231 21978-21978/com.example.app V/ptr-frame-4: updatePos: change: -1, current: 9 last: 10, top: 10, headerHeight: 211
03-21 17:06:34.248 21978-21978/com.example.app V/ptr-frame-4: scroll: false, start: 211, to: 0, currentPos: 9, current :-203, last: -202, delta: -1
03-21 17:06:34.248 21978-21978/com.example.app V/ptr-frame-4: updatePos: change: -1, current: 8 last: 9, top: 9, headerHeight: 211

查看源码发现下面两句:

    private static final boolean DEBUG_LAYOUT = true;
    public static boolean DEBUG = true;

我觉得应该对远程依赖方式关闭日志,毕竟使用远程依赖的方式就意味着将其视为一个稳定的library来使用。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.