Skip to content

Commit 30c87d2

Browse files
author
imkarl
committed
first commit
1 parent 0ad7ec2 commit 30c87d2

37 files changed

+1901
-7
lines changed

.gitignore

+2-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ captures/
3434

3535
# IntelliJ
3636
*.iml
37-
.idea/workspace.xml
38-
.idea/tasks.xml
39-
.idea/gradle.xml
40-
.idea/assetWizardSettings.xml
41-
.idea/dictionaries
42-
.idea/libraries
43-
.idea/caches
37+
.idea/
38+
.DS_Store
4439

4540
# Keystore files
4641
# Uncomment the following line if you do not want to check your keystore files in.

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# 注意事项
3+
- AdapterData 不支持 null
4+

app/build.gradle

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 27
5+
6+
defaultConfig {
7+
applicationId "cn.imkarl.multipletype.demo"
8+
minSdkVersion 15
9+
targetSdkVersion 27
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
implementation 'com.android.support:appcompat-v7:27.1.1'
24+
implementation 'com.android.support:recyclerview-v7:27.1.1'
25+
26+
implementation project(':library')
27+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cn.imkarl.multipletype.demo">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cn.imkarl.multipletype.demo;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import cn.imkarl.multipletype.AdapterItem;
6+
import cn.imkarl.multipletype.BasicViewHelper;
7+
8+
public class IntegerAdapterItem extends AdapterItem<Integer> {
9+
@Override
10+
public int getLayoutResId(@NonNull Integer item) {
11+
return R.layout.item_layout_integer;
12+
}
13+
@Override
14+
public void convert(@NonNull BasicViewHelper helper, @NonNull Integer item, int position) {
15+
helper.setText(R.id.tv_integer, "item: "+item+" position: "+position);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cn.imkarl.multipletype.demo;
2+
3+
import android.support.annotation.NonNull;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.support.v7.widget.DividerItemDecoration;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
9+
import android.widget.LinearLayout;
10+
11+
import cn.imkarl.multipletype.AdapterItem;
12+
import cn.imkarl.multipletype.BasicViewHelper;
13+
import cn.imkarl.multipletype.MultipleTypeAdapter;
14+
import cn.imkarl.multipletype.MultipleTypeAdapterBuilder;
15+
16+
public class MainActivity extends AppCompatActivity {
17+
18+
private RecyclerView recyclerView;
19+
private MultipleTypeAdapter multipleAdapter;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_main);
25+
26+
recyclerView = findViewById(R.id.recyclerView);
27+
recyclerView.setLayoutManager(new LinearLayoutManager(this));
28+
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
29+
30+
multipleAdapter = new MultipleTypeAdapterBuilder()
31+
.register(new IntegerAdapterItem())
32+
.register(new AdapterItem<Long>() {
33+
@Override
34+
public int getLayoutResId(@NonNull Long item) {
35+
return R.layout.item_layout_long;
36+
}
37+
@Override
38+
public void convert(@NonNull BasicViewHelper helper, @NonNull Long item, int position) {
39+
helper.setText(R.id.tv_long, "item: "+item+" position: "+position);
40+
}
41+
})
42+
.bind(recyclerView);
43+
44+
for (int i = 10; i < 20; i++) {
45+
multipleAdapter.getContents().add(i);
46+
}
47+
for (int i = 30; i < 40; i++) {
48+
multipleAdapter.getContents().add((long)i);
49+
}
50+
multipleAdapter.notifyDataSetChanged();
51+
}
52+
53+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
8+
9+
<android.support.v7.widget.RecyclerView
10+
android:id="@+id/recyclerView"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
/>
14+
15+
</RelativeLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="60dp"
6+
android:orientation="horizontal"
7+
android:background="#FFF">
8+
9+
<TextView
10+
android:id="@+id/tv_integer"
11+
android:layout_width="0dp"
12+
android:layout_height="match_parent"
13+
android:layout_weight="2"
14+
android:gravity="right|center_vertical"
15+
android:textColor="#666"
16+
android:textSize="20sp"
17+
android:text="data"
18+
/>
19+
<TextView
20+
android:layout_width="0dp"
21+
android:layout_height="match_parent"
22+
android:layout_weight="1"
23+
android:layout_marginLeft="10dp"
24+
android:gravity="left|center_vertical"
25+
android:textSize="16sp"
26+
android:text="[ integer ]"
27+
/>
28+
29+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="60dp"
6+
android:orientation="horizontal"
7+
android:background="#ccc">
8+
9+
<TextView
10+
android:id="@+id/tv_long"
11+
android:layout_width="0dp"
12+
android:layout_height="match_parent"
13+
android:layout_weight="2"
14+
android:gravity="right|center_vertical"
15+
android:textColor="#666"
16+
android:textSize="20sp"
17+
android:text="data"
18+
/>
19+
<TextView
20+
android:layout_width="0dp"
21+
android:layout_height="match_parent"
22+
android:layout_weight="1"
23+
android:layout_marginLeft="10dp"
24+
android:gravity="left|center_vertical"
25+
android:textSize="16sp"
26+
android:text="[ long ]"
27+
/>
28+
29+
</LinearLayout>
4.46 KB
Loading
Loading

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

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>

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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">MultipleTypeAdapter</string>
3+
</resources>

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

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
10+
11+
</resources>

build.gradle

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:3.1.3'
11+
12+
13+
// NOTE: Do not place your application dependencies here; they belong
14+
// in the individual module build.gradle files
15+
}
16+
}
17+
18+
allprojects {
19+
repositories {
20+
google()
21+
jcenter()
22+
}
23+
}
24+
25+
task clean(type: Delete) {
26+
delete rootProject.buildDir
27+
}

gradle.properties

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx1536m
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true

gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Mon Jun 11 01:31:37 CST 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 commit comments

Comments
 (0)