Skip to content

Commit b6bc2f5

Browse files
committed
new advanced recycler view and adapter impl
1 parent 9bec3f6 commit b6bc2f5

File tree

12 files changed

+609
-22
lines changed

12 files changed

+609
-22
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.support_version = '27.1.0'
3+
ext.support_version = '27.1.1'
44

55
repositories {
66
jcenter()
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111

1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.1.0'
13+
classpath 'com.android.tools.build:gradle:3.1.3'
1414
}
1515
}
1616

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
dependencies {
44

55
testImplementation 'junit:junit:4.12'
6-
testImplementation 'org.mockito:mockito-core:1.10.19'
6+
testImplementation 'org.mockito:mockito-core:2.18.3'
77
}
88

99
apply from: '../base.gradle'

func/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ apply plugin: 'com.android.library'
22

33
dependencies {
44
// compile project(":core")
5-
testImplementation 'com.google.guava:guava:18.0'
5+
testImplementation 'com.google.guava:guava:22.0'
66
testImplementation 'junit:junit:4.12'
7-
testImplementation 'org.mockito:mockito-core:1.10.19'
7+
testImplementation 'org.mockito:mockito-core:2.18.3'
88
}
99

1010
apply from: '../base.gradle'

http/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ dependencies {
88

99
testImplementation 'com.google.code.gson:gson:2.8.2'
1010
testImplementation 'junit:junit:4.12'
11-
testImplementation 'org.mockito:mockito-core:1.10.19'
12-
androidTestImplementation 'com.android.support.test:runner:0.5'
11+
testImplementation 'org.mockito:mockito-core:2.18.3'
12+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
1313
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
1414
}
1515

samples/src/main/AndroidManifest.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@
5151
android:name="com.mcxiaoke.next.samples.AlertDialogSamples"
5252
android:label="@string/app_name" />
5353

54-
<activity
55-
android:name="com.mcxiaoke.next.samples.EndlessListViewSamples"
56-
android:label="@string/app_name" />
57-
58-
<activity
59-
android:name="com.mcxiaoke.next.samples.EndlessRecyclerViewSamples"
60-
android:label="@string/app_name" />
61-
6254
<activity
6355
android:name="com.mcxiaoke.next.samples.ListViewExtendSamples"
6456
android:label="@string/app_name" />
@@ -97,6 +89,9 @@
9789
<activity
9890
android:name=".http.NextClientSamples"
9991
android:label="@string/app_name" />
92+
<activity
93+
android:name=".RecyclerViewSample"
94+
android:label="@string/app_name" />
10095

10196
</application>
10297
</manifest>
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package com.mcxiaoke.next.samples;
2+
3+
import android.annotation.SuppressLint;
4+
import android.os.Bundle;
5+
import android.os.SystemClock;
6+
import android.support.annotation.NonNull;
7+
import android.support.annotation.Nullable;
8+
import android.support.v7.widget.RecyclerView.ViewHolder;
9+
import android.view.LayoutInflater;
10+
import android.view.View;
11+
import android.view.ViewGroup;
12+
import android.widget.TextView;
13+
import com.mcxiaoke.next.recycler.AdvancedRecyclerArrayAdapter;
14+
import com.mcxiaoke.next.recycler.AdvancedRecyclerView;
15+
import com.mcxiaoke.next.recycler.AdvancedRecyclerView.ItemViewHolder;
16+
import com.mcxiaoke.next.recycler.AdvancedRecyclerView.OnLoadDataListener;
17+
import com.mcxiaoke.next.recycler.AdvancedRecyclerView.ViewHolderCreator;
18+
import com.mcxiaoke.next.task.SimpleTaskCallback;
19+
import com.mcxiaoke.next.task.TaskBuilder;
20+
import com.mcxiaoke.next.utils.LogUtils;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import java.util.Random;
25+
import java.util.concurrent.Callable;
26+
27+
/**
28+
* User: mcxiaoke
29+
* Date: 2018/6/17
30+
* Time: 17:53
31+
*/
32+
public class RecyclerViewSample extends BaseActivity {
33+
public static final String TAG = "NextRecyclerViewSample";
34+
35+
private AdvancedRecyclerView recyclerView;
36+
private SampleAdapter arrayAdapter;
37+
private Random random = new Random();
38+
private static int sCounter = 0;
39+
40+
static class SimpleViewHolder extends ItemViewHolder {
41+
private TextView textView;
42+
43+
public SimpleViewHolder(final View itemView) {
44+
super(itemView);
45+
textView = itemView.findViewById(R.id.text1);
46+
}
47+
48+
@SuppressLint("SetTextI18n")
49+
@Override
50+
public void bind(final int position) {
51+
super.bind(position);
52+
textView.setText("Header Text " + position);
53+
}
54+
}
55+
56+
@Override
57+
protected void onCreate(final Bundle savedInstanceState) {
58+
super.onCreate(savedInstanceState);
59+
setContentView(R.layout.act_next_recycler_view);
60+
61+
arrayAdapter = new SampleAdapter();
62+
recyclerView = findViewById(R.id.recycler_view);
63+
recyclerView.setAdapter(arrayAdapter);
64+
recyclerView.setEnableHeaderLoading(true);
65+
recyclerView.setEnableFooterLoading(true);
66+
recyclerView.setOnLoadDataListener(new OnLoadDataListener() {
67+
@Override
68+
public void onHeaderLoading(final AdvancedRecyclerView recyclerView) {
69+
addHeaderDataAsync();
70+
}
71+
72+
73+
@Override
74+
public void onFooterLoading(final AdvancedRecyclerView recyclerView) {
75+
addFooterDataAsync();
76+
}
77+
});
78+
recyclerView.addHeader(R.layout.layout_simple_header);
79+
arrayAdapter.addAll(Data.TITLES);
80+
}
81+
82+
83+
private void addHeaderDataAsync() {
84+
TaskBuilder.create(new Callable<List<String>>() {
85+
@Override
86+
public List<String> call() throws Exception {
87+
SystemClock.sleep(random.nextInt(8) * 1000);
88+
return generateData(random.nextInt(30));
89+
}
90+
}).callback(new SimpleTaskCallback<List<String>>() {
91+
92+
@Override
93+
public void onTaskSuccess(final List<String> strings, final Bundle extras) {
94+
super.onTaskSuccess(strings, extras);
95+
LogUtils.i(TAG, "addHeaderDataAsync thread=" + Thread.currentThread());
96+
arrayAdapter.addAll(0, strings);
97+
recyclerView.setHeaderLoading(false);
98+
recyclerView.setEnableHeaderLoading(false);
99+
recyclerView.addHeader(new ViewHolderCreator<ViewHolder>() {
100+
@Override
101+
public ViewHolder create(final ViewGroup parent) {
102+
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
103+
View view = inflater.inflate(R.layout.layout_simple_header, parent, false);
104+
return new SimpleViewHolder(view);
105+
}
106+
107+
@Override
108+
public void bind(final ViewHolder holder, final int position) {
109+
110+
}
111+
});
112+
}
113+
114+
@Override
115+
public void onTaskFailure(final Throwable ex, final Bundle extras) {
116+
super.onTaskFailure(ex, extras);
117+
}
118+
}).with(this).start();
119+
}
120+
121+
122+
private void addFooterDataAsync() {
123+
TaskBuilder.create(new Callable<List<String>>() {
124+
@Override
125+
public List<String> call() throws Exception {
126+
SystemClock.sleep(random.nextInt(8) * 1000);
127+
return generateData(random.nextInt(30));
128+
}
129+
}).callback(new SimpleTaskCallback<List<String>>() {
130+
131+
@Override
132+
public void onTaskSuccess(final List<String> strings, final Bundle extras) {
133+
super.onTaskSuccess(strings, extras);
134+
LogUtils.i(TAG, "addFooterDataAsync thread=" + Thread.currentThread());
135+
arrayAdapter.addAll(strings);
136+
recyclerView.setFooterLoading(false);
137+
if (sCounter > 10) {
138+
recyclerView.addFooter(R.layout.layout_simple_header);
139+
recyclerView.setEnableFooterLoading(false);
140+
}
141+
}
142+
143+
@Override
144+
public void onTaskFailure(final Throwable ex, final Bundle extras) {
145+
super.onTaskFailure(ex, extras);
146+
}
147+
}).with(this).start();
148+
}
149+
150+
private List<String> generateData(int count) {
151+
sCounter++;
152+
final List<String> data = new ArrayList<>();
153+
for (int i = 0; i < 10 + count; i++) {
154+
data.add("List Item AAA " + sCounter + " - No. " + i);
155+
}
156+
return data;
157+
}
158+
159+
static class SampleAdapter extends AdvancedRecyclerArrayAdapter<String, ItemViewHolder> {
160+
161+
@NonNull
162+
@Override
163+
public ItemViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
164+
View view = LayoutInflater.from(parent.getContext())
165+
.inflate(android.R.layout.simple_list_item_1, parent, false);
166+
return new ItemViewHolder(view);
167+
}
168+
169+
@Override
170+
public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
171+
TextView textView = holder.itemView.findViewById(android.R.id.text1);
172+
textView.setText(getItem(position));
173+
}
174+
175+
@Nullable
176+
@Override
177+
public Object getItemId(@NonNull final String item) {
178+
return item;
179+
}
180+
}
181+
}

samples/src/main/java/com/mcxiaoke/next/samples/Samples.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mcxiaoke.next.samples;
22

3-
import android.app.TaskStackBuilder;
43
import android.content.Context;
54
import android.content.Intent;
65
import android.os.Bundle;
@@ -84,12 +83,11 @@ private void someTest() {
8483

8584
private void initSamples() {
8685
mSampleListData = new ArrayList<>();
86+
mSampleListData.add(new SampleInfo(RecyclerViewSample.TAG, RecyclerViewSample.class));
8787
mSampleListData.add(new SampleInfo(ViewGroupSample.TAG, ViewGroupSample.class));
8888
mSampleListData.add(new SampleInfo(LineLayoutSample.TAG, LineLayoutSample.class));
8989
mSampleListData.add(new SampleInfo(BasicBusSample.TAG, BasicBusSample.class));
9090
mSampleListData.add(new SampleInfo(BasicBusSample2.TAG, BasicBusSample2.class));
91-
mSampleListData.add(new SampleInfo(EndlessRecyclerViewSamples.TAG, EndlessRecyclerViewSamples.class));
92-
mSampleListData.add(new SampleInfo(EndlessListViewSamples.TAG, EndlessListViewSamples.class));
9391
mSampleListData.add(new SampleInfo(ListViewExtendSamples.TAG, ListViewExtendSamples.class));
9492
mSampleListData.add(new SampleInfo(StickyHeaderSamples.TAG, StickyHeaderSamples.class));
9593
mSampleListData.add(new SampleInfo(AlertDialogSamples.TAG, AlertDialogSamples.class));
@@ -98,8 +96,6 @@ private void initSamples() {
9896

9997
mSampleListData.add(new SampleInfo(BasicBusSample.TAG, BasicBusSample.class));
10098
mSampleListData.add(new SampleInfo(BasicBusSample2.TAG, BasicBusSample2.class));
101-
mSampleListData.add(new SampleInfo(EndlessRecyclerViewSamples.TAG, EndlessRecyclerViewSamples.class));
102-
mSampleListData.add(new SampleInfo(EndlessListViewSamples.TAG, EndlessListViewSamples.class));
10399
mSampleListData.add(new SampleInfo(ListViewExtendSamples.TAG, ListViewExtendSamples.class));
104100
mSampleListData.add(new SampleInfo(StickyHeaderSamples.TAG, StickyHeaderSamples.class));
105101
mSampleListData.add(new SampleInfo(AlertDialogSamples.TAG, AlertDialogSamples.class));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.mcxiaoke.next.recycler.AdvancedRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/recycler_view"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
</com.mcxiaoke.next.recycler.AdvancedRecyclerView>

samples/src/main/res/layout/act_recycler.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:layout_width="match_parent"
55
android:layout_height="match_parent">
66

7-
<com.mcxiaoke.next.recycler.EndlessRecyclerView
7+
<com.mcxiaoke.next.recycler.AdvancedRecyclerView
88
android:id="@android:id/list"
99
android:layout_height="match_parent"
1010
android:layout_width="match_parent" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:padding="15dp"
7+
android:gravity="center_vertical">
8+
9+
<TextView
10+
android:id="@+id/text1"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:textSize="17sp"
14+
android:textStyle="bold"
15+
android:text="@string/share_action_provider_target_not_found" />
16+
17+
</LinearLayout>

0 commit comments

Comments
 (0)