Skip to content

Commit b148932

Browse files
author
fengjian
committed
fix the AdapterLess $recycle() to $recycler() and upgrade the support and recycler library
1 parent 90e78d8 commit b148932

File tree

11 files changed

+101
-7
lines changed

11 files changed

+101
-7
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<activity
3535
android:name=".activity.adapterless.PagerAdapterActivity"
3636
android:label="@string/title_activity_adapter_pager" />
37+
<activity
38+
android:name=".activity.adapterless.RecyclerAdapterActivity"
39+
android:label="@string/title_activity_adapter_recycler" />
3740
<activity
3841
android:name=".activity.UpdateActivity"
3942
android:label="@string/title_activity_update" />

app/src/main/java/com/jayfeng/lesscode/app/activity/AdapterActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ private void initData() {
6464
lessItem.setName("AdapterLess.$pager的使用");
6565
lessItem.setClassName("PagerAdapterActivity");
6666
list.add(lessItem);
67+
68+
lessItem = new LessItem();
69+
lessItem.setName("AdapterLess.$recycler的使用");
70+
lessItem.setClassName("RecyclerAdapterActivity");
71+
list.add(lessItem);
6772
}
6873

6974
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.jayfeng.lesscode.app.activity.adapterless;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.widget.TextView;
8+
9+
import com.jayfeng.lesscode.app.R;
10+
import com.jayfeng.lesscode.app.model.Person;
11+
import com.jayfeng.lesscode.core.AdapterLess;
12+
import com.jayfeng.lesscode.core.ViewLess;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
public class RecyclerAdapterActivity extends Activity {
18+
19+
List<Person> list;
20+
RecyclerView recyclerView;
21+
private RecyclerView.LayoutManager layoutManager;
22+
RecyclerView.Adapter<AdapterLess.RecyclerViewHolder> adapter;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_adapter_recycler);
28+
recyclerView = ViewLess.$(this, R.id.recycler);
29+
30+
layoutManager = new LinearLayoutManager(this);
31+
recyclerView.setLayoutManager(layoutManager);
32+
33+
initData();
34+
35+
adapter = AdapterLess.$recycler(this, list,
36+
R.layout.activity_main_list_item,
37+
new AdapterLess.RecyclerCallBack<Person>() {
38+
39+
@Override
40+
public void onBindViewHolder(int position, AdapterLess.RecyclerViewHolder recyclerViewHolder, Person person) {
41+
TextView nameView = recyclerViewHolder.$view(R.id.name);
42+
nameView.setText(person.getName());
43+
}
44+
});
45+
46+
recyclerView.setAdapter(adapter);
47+
}
48+
49+
private void initData() {
50+
list = new ArrayList<>();
51+
list.add(new Person("header"));
52+
list.add(new Person("jay"));
53+
list.add(new Person("bee"));
54+
list.add(new Person("header"));
55+
list.add(new Person("chras"));
56+
list.add(new Person("nichid"));
57+
}
58+
59+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<inset xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:insetLeft="16dp">
4+
5+
<shape android:shape="rectangle">
6+
<solid android:color="#f00" />
7+
</shape>
8+
9+
</inset>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
<ListView android:id="@+id/listview"
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent"></ListView>
9+
android:layout_height="match_parent"
10+
android:footerDividersEnabled="false"
11+
android:divider="@drawable/list_divider"
12+
android:dividerHeight="1dp"></ListView>
1013

1114
</RelativeLayout>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context="com.jayfeng.lesscode.app.activity.adapterless.RecyclerAdapterActivity">
6+
7+
<android.support.v7.widget.RecyclerView
8+
android:id="@+id/recycler"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"/>
11+
12+
</RelativeLayout>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
<ListView android:id="@+id/listview"
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent"></ListView>
9+
android:layout_height="wrap_content"
10+
android:divider="@drawable/list_divider"
11+
android:dividerHeight="1dp"></ListView>
1012

1113
</RelativeLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
22
android:layout_width="match_parent"
3-
android:layout_height="match_parent">
3+
android:layout_height="wrap_content">
44

55
<TextView
66
android:id="@+id/name"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<string name="title_activity_adapter">AdapterActivity</string>
1111
<string name="title_activity_adapter_base">BaseAdapterActivity</string>
1212
<string name="title_activity_adapter_pager">PagerAdapterActivity</string>
13+
<string name="title_activity_adapter_recycler">RecyclerAdapterActivity</string>
1314
<string name="title_activity_update">UpdateActivity</string>
1415
<string name="title_activity_">ActivityActivity</string>
1516
<string name="title_activity_cache">CacheActivity</string>

lesscode-core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424

2525
dependencies {
2626
compile fileTree(dir: 'libs', include: ['*.jar'])
27-
compile 'com.android.support:support-v4:23.1.1'
28-
compile 'com.android.support:recyclerview-v7:23.1.1'
27+
compile 'com.android.support:support-v4:23.2.0'
28+
compile 'com.android.support:recyclerview-v7:23.2.0'
2929
}
3030

3131
def siteUrl = 'https://github.com/openproject/LessCode' // #CONFIG# // project homepage

0 commit comments

Comments
 (0)