Skip to content

Commit 6f75958

Browse files
ZhantyZhanty
authored andcommitted
rename package
1 parent 67c7fdc commit 6f75958

31 files changed

Lines changed: 672 additions & 702 deletions

Library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

adapter.gif

-3.12 MB
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ android {
2424
}
2525

2626
dependencies {
27-
2827
implementation fileTree(dir: 'libs', include: ['*.jar'])
29-
implementation project(':Library')
28+
implementation project(':library')
3029
implementation 'com.android.support:appcompat-v7:28.0.0'
3130
implementation 'com.android.support:recyclerview-v7:28.0.0'
3231
implementation 'com.android.support:cardview-v7:28.0.0'
33-
//PullToRefresh
34-
implementation 'in.srain.cube:ultra-ptr:1.0.11'
35-
}
32+
}

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest package="com.ztiany.loadmore"
3-
xmlns:android="http://schemas.android.com/apk/res/android">
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools">
45

56
<application
6-
android:allowBackup="true"
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:supportsRtl="true"
10-
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
10+
android:theme="@style/AppTheme"
11+
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
12+
13+
<activity android:name="com.ztiany.loadmore.MainActivity">
1214
<intent-filter>
1315
<action android:name="android.intent.action.MAIN"/>
1416

1517
<category android:name="android.intent.category.LAUNCHER"/>
1618
</intent-filter>
1719
</activity>
20+
1821
</application>
1922

2023
</manifest>

app/src/main/java/com/ztiany/loadmore/BaseAdapter.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ztiany.loadmore;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import android.support.annotation.UiThread;
56
import android.support.v7.widget.RecyclerView;
67
import android.view.LayoutInflater;
@@ -16,13 +17,11 @@
1617
*/
1718
public abstract class BaseAdapter<T, VH extends ViewHolder> extends RecyclerView.Adapter<VH> {
1819

19-
protected List<T> mData;
20-
protected Context mContext;
21-
protected LayoutInflater mLayoutInflater;
20+
List<T> mData;
21+
LayoutInflater mLayoutInflater;
2222

23-
public BaseAdapter(Context context, List<T> data) {
23+
BaseAdapter(Context context, List<T> data) {
2424
this.mData = data;
25-
this.mContext = context;
2625
mLayoutInflater = LayoutInflater.from(context);
2726
}
2827

@@ -34,11 +33,8 @@ public List<T> getData() {
3433
return mData;
3534
}
3635

37-
3836
/**
3937
* 添加一条数据,这里需要注意的是,如果使用type来实现多个条目。在notify的时候,可能需要写此方法
40-
*
41-
* @param t
4238
*/
4339
@UiThread
4440
public void addItem(T t) {
@@ -58,11 +54,9 @@ public void addItem(T t) {
5854

5955
/**
6056
* 添加数据集合,这里需要注意的是,如果使用type来实现多个条目。在notify的时候,可能需要写此方法
61-
*
62-
* @param data
6357
*/
6458
@UiThread
65-
public void addAll(List<T> data) {
59+
void addAll(List<T> data) {
6660
if (data == null || data.isEmpty()) {
6761
return;
6862
}
@@ -126,17 +120,16 @@ public boolean isEmpty() {
126120
return getDataSize() == 0;
127121
}
128122

129-
public int getDataSize() {
123+
private int getDataSize() {
130124
return mData == null ? 0 : mData.size();
131125
}
132126

133127

128+
@NonNull
134129
@Override
135-
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
130+
public abstract VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType);
136131

137132
@Override
138-
public abstract void onBindViewHolder(VH viewHolder, int position);
139-
140-
141-
}
133+
public abstract void onBindViewHolder(@NonNull VH viewHolder, int position);
142134

135+
}

app/src/main/java/com/ztiany/loadmore/BaseLayoutFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.LayoutRes;
5+
import android.support.annotation.NonNull;
56
import android.support.annotation.Nullable;
67
import android.support.v4.app.Fragment;
78
import android.view.LayoutInflater;
@@ -19,7 +20,7 @@ public abstract class BaseLayoutFragment extends Fragment {
1920

2021
@Nullable
2122
@Override
22-
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
23+
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
2324
int layoutId = provideLayoutRes();
2425
if (layoutId > 0) {
2526
return inflater.inflate(provideLayoutRes(), container, false);

app/src/main/java/com/ztiany/loadmore/DemoFragment.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import android.graphics.Rect;
44
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
56
import android.support.annotation.Nullable;
7+
import android.support.v4.widget.SwipeRefreshLayout;
68
import android.support.v7.widget.GridLayoutManager;
79
import android.support.v7.widget.LinearLayoutManager;
810
import android.support.v7.widget.PopupMenu;
@@ -16,17 +18,14 @@
1618
import android.widget.TextView;
1719
import android.widget.Toast;
1820

19-
import com.ztiany.adapter.LoadMode;
20-
import com.ztiany.adapter.OnLoadMoreListener;
21-
import com.ztiany.adapter.WrapperAdapter;
21+
import com.ztiany.loadmore.adapter.LoadMode;
22+
import com.ztiany.loadmore.adapter.OnLoadMoreListener;
23+
import com.ztiany.loadmore.adapter.WrapperAdapter;
2224

2325
import java.util.ArrayList;
2426
import java.util.Arrays;
2527
import java.util.List;
2628

27-
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
28-
import in.srain.cube.views.ptr.PtrDefaultHandler;
29-
import in.srain.cube.views.ptr.PtrFrameLayout;
3029

3130
public class DemoFragment extends BaseLayoutFragment {
3231

@@ -38,7 +37,7 @@ public class DemoFragment extends BaseLayoutFragment {
3837
private List<String> mData;
3938
protected WrapperAdapter mWrapperAdapter;
4039
protected RecyclerView mRecyclerView;
41-
protected PtrClassicFrameLayout mPtrClassicFrameLayout;
40+
protected SwipeRefreshLayout mRefreshLayout;
4241

4342
private static final String LAYOUT_TYPE = "layout_type";
4443
private static final String CLICK_LOAD_MORE = "isClickLoadMore";
@@ -114,7 +113,7 @@ public void onClick(View v) {
114113
}
115114
});
116115
mRecyclerView = view.findViewById(R.id.fragment_recycler_rv);
117-
mPtrClassicFrameLayout = view.findViewById(R.id.fragment_recycler_ptr);
116+
mRefreshLayout = view.findViewById(R.id.fragment_recycler_ptr);
118117
}
119118

120119
@Override
@@ -145,33 +144,28 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
145144

146145
setOnLoadMoreListener();
147146

148-
mPtrClassicFrameLayout.setPtrHandler(new PtrDefaultHandler() {
147+
mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
149148
@Override
150-
public void onRefreshBegin(final PtrFrameLayout frame) {
149+
public void onRefresh() {
151150
if (mWrapperAdapter.isLoadingMore()) {
152-
frame.refreshComplete();
151+
mRefreshLayout.setRefreshing(false);
153152
return;
154153
}
155154

156-
frame.postDelayed(new Runnable() {
155+
mRefreshLayout.postDelayed(new Runnable() {
157156
@Override
158157
public void run() {
159158
mData.clear();
160159
for (int i = 0; i < 20; i++) {
161160
mData.add("我是Item " + i);
162161
}
163162
mRecyclerAdapter.notifyDataSetChanged();
164-
frame.refreshComplete();
163+
mRefreshLayout.setRefreshing(false);
165164
mWrapperAdapter.loadCompleted(true);
166165
Toast.makeText(getContext(), "刷新完毕", Toast.LENGTH_SHORT).show();
167166
}
168167
}, 1000);
169168
}
170-
171-
@Override
172-
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
173-
return super.checkCanDoRefresh(frame, mRecyclerView, header);
174-
}
175169
});
176170
}
177171

@@ -186,7 +180,7 @@ public boolean canLoadMore() {
186180
@Override
187181
public void onLoadMore() {
188182

189-
mPtrClassicFrameLayout.postDelayed(new Runnable() {
183+
mRefreshLayout.postDelayed(new Runnable() {
190184
@Override
191185
public void run() {
192186

@@ -231,8 +225,9 @@ public void run() {
231225

232226
private void initAdapter() {
233227
mRecyclerAdapter = new BaseAdapter<String, ViewHolder<String>>(getContext(), mData) {
228+
@NonNull
234229
@Override
235-
public ViewHolder<String> onCreateViewHolder(ViewGroup parent, int viewType) {
230+
public ViewHolder<String> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
236231
View inflate = mLayoutInflater.inflate(R.layout.item, parent, false);
237232
return new ViewHolder<String>(inflate) {
238233
private TextView mTextView;
@@ -256,7 +251,7 @@ public void onClick(View v) {
256251
}
257252

258253
@Override
259-
public void onBindViewHolder(ViewHolder<String> viewHolder, final int position) {
254+
public void onBindViewHolder(@NonNull ViewHolder<String> viewHolder, final int position) {
260255
viewHolder.bindData(mData.get(position));
261256
}
262257
};
@@ -266,4 +261,4 @@ protected void onBindData(TextView textView, String data) {
266261
textView.setText(data);
267262
}
268263

269-
}
264+
}

app/src/main/java/com/ztiany/loadmore/DensityUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class DensityUtils {
2424

2525
private static final float DOT_FIVE = 0.5f;
2626

27-
2827
/**
2928
* dip to px
3029
*
@@ -119,7 +118,6 @@ private static synchronized void initDisplayMetrics(Context context) {
119118
}
120119

121120

122-
123121
/**
124122
* is landscape
125123
*

app/src/main/res/layout/fragment_recycler_load.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:text="showOption"
1313
android:textAllCaps="false"/>
1414

15-
<in.srain.cube.views.ptr.PtrClassicFrameLayout
15+
<android.support.v4.widget.SwipeRefreshLayout
1616
android:id="@+id/fragment_recycler_ptr"
1717
android:layout_width="match_parent"
1818
android:layout_height="match_parent">
@@ -22,6 +22,6 @@
2222
android:layout_width="match_parent"
2323
android:layout_height="match_parent"/>
2424

25-
</in.srain.cube.views.ptr.PtrClassicFrameLayout>
25+
</android.support.v4.widget.SwipeRefreshLayout>
2626

2727
</LinearLayout>

build.gradle

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
31
buildscript {
42
repositories {
53
jcenter()
64
maven { url 'https://dl.google.com/dl/android/maven2/' }
75
maven { url 'https://jitpack.io' }
8-
maven { url uri('repo') }
96
google()
107
}
118
dependencies {
129
classpath 'com.android.tools.build:gradle:3.2.1'
13-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1410
}
1511
}
1612

1713
allprojects {
1814

1915
repositories {
2016
jcenter()
21-
maven{
22-
url 'https://dl.bintray.com/ztiany/maven'
23-
}
17+
maven { url 'https://dl.google.com/dl/android/maven2/' }
18+
maven { url 'https://jitpack.io' }
2419
google()
2520
}
2621

@@ -34,4 +29,4 @@ allprojects {
3429

3530
task clean(type: Delete) {
3631
delete rootProject.buildDir
37-
}
32+
}

0 commit comments

Comments
 (0)