-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.2" | ||
defaultConfig { | ||
applicationId "com.fbsum.android.adapterdelegates.sample" | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:26.1.0' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
compile 'com.android.support:design:26.1.0' | ||
compile 'com.android.support:recyclerview-v7:26.1.0' | ||
compile project(':library') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/xin/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...c/androidTest/java/com/fbsum/android/adapterdelegates/sample/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.fbsum.android.adapterdelegates.sample; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.fbsum.android.adapterdelegates.sample", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.fbsum.android.adapterdelegates.sample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/fbsum/android/adapterdelegates/sample/ComplexDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.fbsum.android.adapterdelegates.sample; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.fbsum.android.adapterdelegates.SimpleAdapterDelegate; | ||
import com.fbsum.android.adapterdelegates.sample.model.ComplexItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.Item; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by sum on 5/10/16. | ||
*/ | ||
public class ComplexDelegate extends SimpleAdapterDelegate<Item> { | ||
|
||
public ComplexDelegate(Activity activity) { | ||
super(activity, R.layout.layout_complex); | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(@NonNull Item item) { | ||
return item instanceof ComplexItem; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected RecyclerView.ViewHolder onCreateViewHolder(@NonNull View itemView) { | ||
final ComplexViewHolder viewHolder = new ComplexViewHolder(itemView); | ||
View.OnClickListener onClickListener = new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (onViewClickListener != null) { | ||
int position = viewHolder.getAdapterPosition(); | ||
onViewClickListener.onClick(v, position); | ||
} | ||
} | ||
}; | ||
viewHolder.tvContent.setOnClickListener(onClickListener); | ||
viewHolder.ivIcon.setOnClickListener(onClickListener); | ||
return viewHolder; | ||
} | ||
|
||
@Override | ||
protected void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @NonNull Item item, @NonNull List<Object> payloads) { | ||
ComplexViewHolder viewHolder = (ComplexViewHolder) holder; | ||
ComplexItem complexItem = (ComplexItem) item; | ||
|
||
viewHolder.tvContent.setText(complexItem.content != null ? complexItem.content : "Hello World!!!"); | ||
viewHolder.ivIcon.setImageResource(complexItem.imageRes != 0 ? complexItem.imageRes : R.mipmap.ic_launcher); | ||
} | ||
|
||
private static class ComplexViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private TextView tvContent; | ||
private ImageView ivIcon; | ||
|
||
ComplexViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
tvContent = (TextView) itemView.findViewById(R.id.tv_main_item_content); | ||
ivIcon = (ImageView) itemView.findViewById(R.id.iv_main_item_icon); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/fbsum/android/adapterdelegates/sample/ContentDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.fbsum.android.adapterdelegates.sample; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.fbsum.android.adapterdelegates.SimpleAdapterDelegate; | ||
import com.fbsum.android.adapterdelegates.sample.model.ContentItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.Item; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by sum on 5/10/16. | ||
*/ | ||
public class ContentDelegate extends SimpleAdapterDelegate<Item> { | ||
|
||
public ContentDelegate(Activity activity) { | ||
super(activity, R.layout.layout_content); | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(@NonNull Item item) { | ||
return item instanceof ContentItem; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected RecyclerView.ViewHolder onCreateViewHolder(@NonNull View itemView) { | ||
final ViewHolder viewHolder = new ViewHolder(itemView); | ||
View.OnClickListener onClickListener = new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (onViewClickListener != null) { | ||
int position = viewHolder.getAdapterPosition(); | ||
onViewClickListener.onClick(v, position); | ||
} | ||
} | ||
}; | ||
viewHolder.tvContent.setOnClickListener(onClickListener); | ||
return viewHolder; | ||
} | ||
|
||
@Override | ||
protected void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @NonNull Item item, @NonNull List<Object> payloads) { | ||
final ViewHolder viewHolder = (ViewHolder) holder; | ||
ContentItem contentItem = (ContentItem) item; | ||
|
||
viewHolder.tvContent.setText(contentItem.content != null ? contentItem.content : "Hello World!!!"); | ||
} | ||
|
||
private static class ViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private TextView tvContent; | ||
|
||
ViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
tvContent = (TextView) itemView.findViewById(R.id.tv_main_item_content); | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/fbsum/android/adapterdelegates/sample/ImageDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fbsum.android.adapterdelegates.sample; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
|
||
import com.fbsum.android.adapterdelegates.SimpleAdapterDelegate; | ||
import com.fbsum.android.adapterdelegates.sample.model.ImageItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.Item; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by sum on 5/10/16. | ||
*/ | ||
public class ImageDelegate extends SimpleAdapterDelegate<Item> { | ||
|
||
public ImageDelegate(Activity activity) { | ||
super(activity, R.layout.layout_image); | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(@NonNull Item item) { | ||
return item instanceof ImageItem; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected RecyclerView.ViewHolder onCreateViewHolder(@NonNull View itemView) { | ||
return new ViewHolder(itemView); | ||
} | ||
|
||
@Override | ||
protected void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @NonNull Item item, @NonNull List<Object> payloads) { | ||
ViewHolder viewHolder = (ViewHolder) holder; | ||
ImageItem imageItem = (ImageItem) item; | ||
|
||
viewHolder.ivIcon.setImageResource(imageItem.imageRes != 0 ? imageItem.imageRes : R.mipmap.ic_launcher); | ||
} | ||
|
||
private static class ViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private ImageView ivIcon; | ||
|
||
ViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
ivIcon = (ImageView) itemView.findViewById(R.id.iv_main_item_icon); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/fbsum/android/adapterdelegates/sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.fbsum.android.adapterdelegates.sample; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.fbsum.android.adapterdelegates.sample.model.ComplexItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.ContentItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.ImageItem; | ||
import com.fbsum.android.adapterdelegates.sample.model.Item; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private RecyclerView recyclerView; | ||
private MainAdapter mainAdapter; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
recyclerView = (RecyclerView) findViewById(R.id.recyclerView); | ||
recyclerView.setHasFixedSize(true); | ||
|
||
List<Item> items = new ArrayList<>(); | ||
items.add(new ContentItem("Content 1")); | ||
items.add(new ImageItem()); | ||
items.add(new ComplexItem("Content 2")); | ||
items.add(new ComplexItem("Content 3")); | ||
items.add(new ImageItem()); | ||
items.add(new ContentItem("Content 4")); | ||
|
||
mainAdapter = new MainAdapter(this, items); | ||
recyclerView.setAdapter(mainAdapter); | ||
} | ||
} |
Oops, something went wrong.