Skip to content

Commit 0fbcdd0

Browse files
author
heaven7
committed
opt pull to refresh
1 parent d7dd1f6 commit 0fbcdd0

File tree

9 files changed

+181
-49
lines changed

9 files changed

+181
-49
lines changed

PullToRefesh/android-pullrefreshview2/build.gradle

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
apply plugin: 'com.android.library'
22
//apply plugin: 'com.novoda.bintray-release'
3+
apply plugin: 'com.github.dcendents.android-maven'
4+
group='com.github.LightSun'
35

46
android {
5-
compileSdkVersion 25
6-
buildToolsVersion "25.0.2"
7+
compileSdkVersion 28
8+
buildToolsVersion "28.0.3"
79

810
defaultConfig {
9-
minSdkVersion 11
10-
targetSdkVersion 25
11+
minSdkVersion 16
12+
targetSdkVersion 28
1113
versionCode 10
1214
versionName "1.0"
1315

@@ -26,14 +28,16 @@ android {
2628
}
2729

2830
dependencies {
29-
compile fileTree(dir: 'libs', include: ['*.jar'])
30-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31+
implementation fileTree(dir: 'libs', include: ['*.jar'])
32+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
3133
exclude group: 'com.android.support', module: 'support-annotations'
3234
})
33-
compile 'com.android.support:appcompat-v7:25.3.1'
34-
testCompile 'junit:junit:4.12'
35+
implementation 'com.android.support:appcompat-v7:28.0.0'
36+
implementation "com.android.support:recyclerview-v7:28.0.0"
37+
testImplementation 'junit:junit:4.12'
3538

36-
compile 'com.heaven7.core.adapter:adapter:1.8.8'
39+
//implementation 'com.heaven7.core.adapter:adapter:1.8.8'
40+
implementation 'com.github.LightSun:SuperAdapter:2.0.6'
3741
//compile 'com.heaven7.android.component:android-app-components:1.0.1'
3842
}
3943

@@ -50,7 +54,7 @@ dependencies {
5054

5155
//apply from: "publish_maven.gradle"
5256

53-
ext {
57+
/*ext {
5458
bintrayRepo = 'maven'
5559
bintrayName = 'android-pullrefreshview2' // Has to be same as your library module name
5660
@@ -77,5 +81,5 @@ ext {
7781
}
7882
7983
apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/installv1.gradle'
80-
apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/bintrayv1.gradle'
84+
apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/bintrayv1.gradle'*/
8185
//gradlew clean build install bintrayUpload
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.heaven7.android.pullrefresh;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
6+
/**
7+
* the default footer delegate
8+
* @author heaven7
9+
* @since 1.1.0
10+
*/
11+
/*public*/ class DefaultFooterDelegate implements FooterDelegate {
12+
13+
private LoadingFooterView mFooterView;
14+
15+
@Override
16+
public void prepareFooterView(Context context){
17+
if(mFooterView == null){
18+
mFooterView = new LoadingFooterView(context);
19+
}
20+
// mFooterView.setOnClickListener(new PullToRefreshLayout.OnClickFooterListenerImpl());
21+
}
22+
23+
@Override
24+
public View getView() {
25+
return mFooterView;
26+
}
27+
@Override
28+
public void setState(int state) {
29+
mFooterView.setState(state);
30+
}
31+
@Override
32+
public int getState() {
33+
return mFooterView.getState();
34+
}
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.heaven7.android.pullrefresh;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
6+
/**
7+
* the footer delegate .
8+
* @author heaven7
9+
* @since 1.1.0
10+
*/
11+
public interface FooterDelegate {
12+
13+
int STATE_NORMAL = 1;
14+
int STATE_THE_END = 2;
15+
int STATE_LOADING = 3;
16+
int STATE_NET_ERROR = 4;
17+
18+
/**
19+
* called on prepare footer view
20+
* @param context the context to create footer view
21+
*/
22+
void prepareFooterView(Context context);
23+
24+
/**
25+
* the footer view.
26+
* @return the footer view
27+
*/
28+
View getView();
29+
30+
/**
31+
* set the footer state
32+
* @param state the target state
33+
*/
34+
void setState(int state);
35+
36+
/**
37+
* get the footer state
38+
* @return the state.
39+
*/
40+
int getState();
41+
}

PullToRefesh/android-pullrefreshview2/src/main/java/com/heaven7/android/pullrefresh/LoadingFooterView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*/
1414
public class LoadingFooterView extends RelativeLayout {
1515

16-
public static final int STATE_NORMAL = 1;
17-
public static final int STATE_THE_END = 2;
18-
public static final int STATE_LOADING = 3;
19-
public static final int STATE_NET_ERROR = 4;
16+
public static final int STATE_NORMAL = FooterDelegate.STATE_NORMAL;
17+
public static final int STATE_THE_END = FooterDelegate.STATE_THE_END;
18+
public static final int STATE_LOADING = FooterDelegate.STATE_LOADING;
19+
public static final int STATE_NET_ERROR = FooterDelegate.STATE_NET_ERROR;
2020

2121
private int mState = STATE_NORMAL;
2222

PullToRefesh/android-pullrefreshview2/src/main/java/com/heaven7/android/pullrefresh/PullToRefreshLayout.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import android.widget.LinearLayout;
1717

1818
import com.heaven7.adapter.AbstractLoadMoreScrollListener;
19-
import com.heaven7.adapter.ISelectable;
20-
import com.heaven7.adapter.QuickRecycleViewAdapter;
19+
import com.heaven7.adapter.AdapterManager;
2120

2221

2322
/**
@@ -33,11 +32,12 @@ public class PullToRefreshLayout extends FrameLayout {
3332
private LinearLayout mPlaceHolderView;
3433

3534
private LoadMoreScrollListenerImpl mLoadMoreListenerImpl;
36-
private LoadingFooterView mFooterView;
3735

3836
private Callback mCallback;
3937
private PlaceHolderViewPerformer mHolderPerformer;
4038

39+
private FooterDelegate mFooterDelegate = new DefaultFooterDelegate();
40+
4141
/**
4242
* the callback of {@linkplain PullToRefreshLayout}
4343
*/
@@ -64,7 +64,19 @@ public void onLoadMore(PullToRefreshLayout layout) {
6464
* @param footer the footer view
6565
* @param state the state of footer
6666
*/
67+
@Deprecated
6768
public void onClickFooter(PullToRefreshLayout layout, LoadingFooterView footer, int state){
69+
onClickFooter(layout, (View)footer, state);
70+
}
71+
72+
/**
73+
* called on click footer
74+
* @param layout the layout
75+
* @param footer the footer view
76+
* @param state the state. see {@linkplain FooterDelegate#STATE_LOADING} and etc.
77+
* @since 1.1.0
78+
*/
79+
public void onClickFooter(PullToRefreshLayout layout, View footer, int state){
6880

6981
}
7082
}
@@ -125,11 +137,24 @@ public void onRefresh() {
125137
}
126138
});
127139
mRv.addOnScrollListener(mLoadMoreListenerImpl);
128-
//footer
129-
mFooterView = new LoadingFooterView(getContext());
130-
mFooterView.setOnClickListener(new OnClickFooterListenerImpl());
140+
}
141+
/**
142+
* set the footer delegate
143+
* @param delegate the footer delegate
144+
* @since 1.1.0
145+
*/
146+
public void setFooterDelegate(FooterDelegate delegate){
147+
mFooterDelegate = delegate;
131148
}
132149

150+
/**
151+
* get the footer delegate
152+
* @return the footer delegate
153+
* @since 1.1.0
154+
*/
155+
public FooterDelegate getFooterDelegate(){
156+
return mFooterDelegate;
157+
}
133158
/**
134159
* set the place holder view performer
135160
* @param performer the performer.
@@ -143,7 +168,11 @@ public void setPlaceHolderViewPerformer(PlaceHolderViewPerformer performer) {
143168
* @param performer the target state performer.
144169
*/
145170
public void setStatePerformer(LoadingFooterView.StatePerformer performer){
146-
mFooterView.setStatePerformer(performer);
171+
mFooterDelegate.prepareFooterView(getContext());
172+
View view = mFooterDelegate.getView();
173+
if(view instanceof LoadingFooterView){
174+
((LoadingFooterView)view).setStatePerformer(performer);
175+
}
147176
}
148177

149178
/**
@@ -155,15 +184,20 @@ public void setLayoutManager(RecyclerView.LayoutManager lm){
155184
}
156185

157186
/** set adapter .it will auto add loading footer .
158-
* @param <T> the data type
159187
* @param adapter the adapter to bind
160188
* */
161-
public <T extends ISelectable> void setAdapter(QuickRecycleViewAdapter<T> adapter){
189+
public void setAdapter(RecyclerView.Adapter adapter){
190+
mFooterDelegate.prepareFooterView(getContext());
191+
View view = mFooterDelegate.getView();
192+
view.setOnClickListener(new OnClickFooterListenerImpl());
193+
162194
final RecyclerView.Adapter preAdapter = getRecyclerView().getAdapter();
163-
if(preAdapter != null && preAdapter instanceof QuickRecycleViewAdapter){
164-
((QuickRecycleViewAdapter) preAdapter).removeFooterView(mFooterView);
195+
if(preAdapter instanceof AdapterManager.IHeaderFooterManager){
196+
((AdapterManager.IHeaderFooterManager) preAdapter).removeFooterView(view);
197+
}
198+
if(adapter instanceof AdapterManager.IHeaderFooterManager){
199+
((AdapterManager.IHeaderFooterManager) adapter).addFooterView(view);
165200
}
166-
adapter.addFooterView(mFooterView);
167201
getRecyclerView().setAdapter(adapter);
168202
}
169203

@@ -181,7 +215,9 @@ public void setLoadingComplete(){
181215
* @return the footer view.
182216
*/
183217
public LoadingFooterView getFooterView(){
184-
return mFooterView;
218+
mFooterDelegate.prepareFooterView(getContext());
219+
View view = mFooterDelegate.getView();
220+
return view instanceof LoadingFooterView ? (LoadingFooterView) view : null;
185221
}
186222

187223
/**
@@ -234,8 +270,12 @@ protected void onLoadMore(RecyclerView rv) {
234270
private class OnClickFooterListenerImpl implements OnClickListener{
235271
@Override
236272
public void onClick(View v) {
237-
LoadingFooterView view = (LoadingFooterView) v;
238-
mCallback.onClickFooter(PullToRefreshLayout.this, view, view.getState());
273+
if(v instanceof LoadingFooterView){
274+
LoadingFooterView view = (LoadingFooterView) v;
275+
mCallback.onClickFooter(PullToRefreshLayout.this, view, view.getState());
276+
}else {
277+
mCallback.onClickFooter(PullToRefreshLayout.this, v, mFooterDelegate.getState());
278+
}
239279
}
240280
}
241281

PullToRefesh/app/build.gradle

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'com.neenbedankt.android-apt'
2+
//apply plugin: 'com.neenbedankt.android-apt'
33

44
android {
5-
compileSdkVersion 25
6-
buildToolsVersion "25.0.2"
5+
compileSdkVersion 28
6+
buildToolsVersion "28.0.3"
77
defaultConfig {
88
applicationId "pulltorefresh.android.heaven7.com.pulltorefesh"
9-
minSdkVersion 15
10-
targetSdkVersion 25
9+
minSdkVersion 16
10+
targetSdkVersion 28
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -24,17 +24,24 @@ android {
2424
}
2525

2626
dependencies {
27-
compile fileTree(include: ['*.jar'], dir: 'libs')
28-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
implementation fileTree(include: ['*.jar'], dir: 'libs')
28+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
2929
exclude group: 'com.android.support', module: 'support-annotations'
3030
})
31-
compile 'com.android.support:appcompat-v7:25.3.1'
31+
implementation 'com.android.support:appcompat-v7:28.0.0'
32+
implementation "com.android.support:recyclerview-v7:28.0.0"
3233
// compile 'com.android.support.constraint:constraint-layout:1.0.2'
33-
testCompile 'junit:junit:4.12'
34-
compile 'com.jakewharton:butterknife:8.4.0'
35-
apt "com.jakewharton:butterknife-compiler:8.4.0"
34+
testImplementation 'junit:junit:4.12'
35+
implementation 'com.jakewharton:butterknife:8.4.0'
36+
annotationProcessor "com.jakewharton:butterknife-compiler:8.4.0"
3637
//compile 'com.heaven7.android.pullrefresh2:android-pullrefreshview2:1.0'
37-
compile project(':android-pullrefreshview2')
38+
implementation project(':android-pullrefreshview2')
3839
//compile 'com.heaven7.android.pullrefresh:android-pullrefreshview:1.0.1'
39-
compile files('libs/TestProcessor.jar')
40+
annotationProcessor files('libs/TestProcessor.jar')
41+
implementation files('libs/TestProcessor.jar')
42+
43+
implementation('com.github.LightSun:util-v1:1.1.4') {
44+
exclude group: 'com.android.support'
45+
}
46+
implementation 'com.github.LightSun:SuperAdapter:2.0.6'
4047
}

PullToRefesh/app/src/main/res/layout/item_test_pull_refresh.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:orientation="vertical"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="wrap_content">
66

77
<TextView
88
android:id="@+id/tv1"

PullToRefesh/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22

33
buildscript {
44
repositories {
5+
google()
56
jcenter()
7+
maven { url "https://jitpack.io" }
68
}
79
dependencies {
810
//classpath 'com.android.tools.build:gradle:2.3.1'
9-
classpath 'com.android.tools.build:gradle:2.3.3'
11+
classpath 'com.android.tools.build:gradle:3.4.1'
12+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1013
//classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
1114
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
13-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
15+
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
16+
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1417

1518
// NOTE: Do not place your application dependencies here; they belong
1619
// in the individual module build.gradle files
17-
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
20+
// classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1821
//classpath 'com.novoda:bintray-release:0.4.0'
1922

2023
}
2124
}
2225

2326
allprojects {
2427
repositories {
28+
google()
2529
jcenter()
30+
maven { url "https://jitpack.io" }
2631
}
2732
tasks.withType(Javadoc) {
2833
options.addStringOption('Xdoclint:none', '-quiet')

PullToRefesh/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 commit comments

Comments
 (0)