Skip to content

Commit 86318b8

Browse files
committed
initial commit
0 parents  commit 86318b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2612
-0
lines changed

.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/build
7+
/captures
8+
9+
# Built application files
10+
*.apk
11+
*.ap_
12+
bin/
13+
gen/
14+
classes/
15+
gen-external-apklibs/
16+
17+
# Eclipse project files
18+
.classpath
19+
.project
20+
.metadata
21+
.settings
22+
23+
# IntelliJ files
24+
.idea
25+
*.iml
26+
27+
# OSX files
28+
.DS_Store
29+
30+
# Windows files
31+
Thumbs.db
32+
33+
# vi swap files
34+
*.swp
35+
36+
# backup files
37+
*.bak
38+
39+
40+
# Files for the Dalvik VM
41+
*.dex
42+
43+
# Java class files
44+
*.class
45+
46+
# Generated files
47+
bin/
48+
gen/
49+
50+
# Gradle files
51+
.gradle/
52+
build/
53+
.gradle
54+
55+
#maven files
56+
target/
57+
/null
58+
59+
# Local configuration file (sdk path, etc)
60+
61+
local.properties
62+
63+
# Proguard folder generated by Eclipse
64+
proguard/
65+
66+
#Log Files
67+
*.log
68+
69+
70+
#crashlytics
71+
app/src/main/res/values/com_crashlytics_export_strings.xml
72+
73+
#infer
74+
infer-out/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# AdapterDelegates
2+
Read more about this project in my blog post.
3+
4+
5+
## Idea
6+
The idea of this library is to build your adapters by composing reusable components like `AdapterDelegates`

app/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
bin/
5+
gen/
6+
classes/
7+
gen-external-apklibs/
8+
9+
# Eclipse project files
10+
.classpath
11+
.project
12+
.metadata
13+
.settings
14+
15+
# IntelliJ files
16+
.idea
17+
*.iml
18+
19+
# OSX files
20+
.DS_Store
21+
22+
# Windows files
23+
Thumbs.db
24+
25+
# vi swap files
26+
*.swp
27+
28+
# backup files
29+
*.bak
30+
31+
32+
# Files for the Dalvik VM
33+
*.dex
34+
35+
# Java class files
36+
*.class
37+
38+
# Generated files
39+
bin/
40+
gen/
41+
42+
# Gradle files
43+
.gradle/
44+
build/
45+
.gradle
46+
47+
#maven files
48+
target/
49+
/null
50+
51+
# Local configuration file (sdk path, etc)
52+
53+
local.properties
54+
55+
# Proguard folder generated by Eclipse
56+
proguard/
57+
58+
#Log Files
59+
*.log
60+
61+
62+
#crashlytics
63+
app/src/main/res/values/com_crashlytics_export_strings.xml
64+
65+
#infer
66+
infer-out/

app/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "23.0.0 rc2"
6+
7+
defaultConfig {
8+
applicationId "com.hannesdorfmann.adapterdelegates.sample"
9+
minSdkVersion 8
10+
targetSdkVersion 22
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile rootProject.ext.appCompat
25+
compile rootProject.ext.recyclerView
26+
27+
compile project(':library')
28+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/hannes/android-sdks/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hannesdorfmann.adapterdelegates.sample"
4+
>
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:theme="@style/AppTheme"
11+
>
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
>
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN"/>
18+
19+
<category android:name="android.intent.category.LAUNCHER"/>
20+
</intent-filter>
21+
</activity>
22+
23+
<activity
24+
android:name=".ReptilesActivity"
25+
android:label="Reptiels"
26+
/>
27+
</application>
28+
29+
</manifest>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.hannesdorfmann.adapterdelegates.sample;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.widget.LinearLayoutManager;
7+
import android.support.v7.widget.RecyclerView;
8+
import android.view.View;
9+
import com.hannesdorfmann.adapterdelegates.sample.model.Advertisement;
10+
import com.hannesdorfmann.adapterdelegates.sample.model.Cat;
11+
import com.hannesdorfmann.adapterdelegates.sample.model.DisplayableItem;
12+
import com.hannesdorfmann.adapterdelegates.sample.model.Dog;
13+
import com.hannesdorfmann.adapterdelegates.sample.model.Gecko;
14+
import com.hannesdorfmann.adapterdelegates.sample.model.Snake;
15+
import java.util.ArrayList;
16+
import java.util.Collections;
17+
import java.util.List;
18+
19+
public class MainActivity extends AppCompatActivity {
20+
21+
@Override protected void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setContentView(R.layout.activity_main);
24+
25+
RecyclerView rv = (RecyclerView) findViewById(R.id.recyclerView);
26+
rv.setLayoutManager(new LinearLayoutManager(this));
27+
MainAdapter adapter = new MainAdapter(this, getAnimals());
28+
rv.setAdapter(adapter);
29+
30+
31+
findViewById(R.id.reptielsActivity).setOnClickListener(new View.OnClickListener() {
32+
@Override public void onClick(View v) {
33+
startActivity(new Intent(MainActivity.this, ReptilesActivity.class));
34+
}
35+
});
36+
}
37+
38+
private List<DisplayableItem> getAnimals() {
39+
List<DisplayableItem> animals = new ArrayList<>();
40+
41+
animals.add(new Cat("American Curl"));
42+
animals.add(new Cat("Baliness"));
43+
animals.add(new Cat("Bengal"));
44+
animals.add(new Cat("Corat"));
45+
animals.add(new Cat("Manx"));
46+
animals.add(new Cat("Nebelung"));
47+
animals.add(new Dog("Aidi"));
48+
animals.add(new Dog("Chinook"));
49+
animals.add(new Dog("Appenzeller"));
50+
animals.add(new Dog("Collie"));
51+
animals.add(new Snake("Mub Adder", "Adder"));
52+
animals.add(new Snake("Texas Blind Snake", "Blind snake"));
53+
animals.add(new Snake("Tree Boa", "Boa"));
54+
animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
55+
animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
56+
animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
57+
animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
58+
animals.add(new Advertisement());
59+
animals.add(new Advertisement());
60+
animals.add(new Advertisement());
61+
animals.add(new Advertisement());
62+
animals.add(new Advertisement());
63+
64+
Collections.shuffle(animals);
65+
return animals;
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2015 Hannes Dorfmann.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hannesdorfmann.adapterdelegates.sample;
18+
19+
import android.app.Activity;
20+
import android.support.v7.widget.RecyclerView;
21+
import android.view.ViewGroup;
22+
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager;
23+
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.AdvertisementAdapterDelegate;
24+
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.CatAdapterDelegate;
25+
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.DogAdapterDelegate;
26+
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.GeckoAdapterDelegate;
27+
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.SnakeAdapterDelegate;
28+
import com.hannesdorfmann.adapterdelegates.sample.model.DisplayableItem;
29+
import java.util.List;
30+
31+
/**
32+
* @author Hannes Dorfmann
33+
*/
34+
public class MainAdapter extends RecyclerView.Adapter {
35+
36+
private AdapterDelegatesManager<List<DisplayableItem>> delegatesManager;
37+
private List<DisplayableItem> items;
38+
39+
public MainAdapter(Activity activity, List<DisplayableItem> items) {
40+
this.items = items;
41+
42+
// Delegates
43+
delegatesManager = new AdapterDelegatesManager<>();
44+
delegatesManager.addDelegate(new AdvertisementAdapterDelegate(activity, 0));
45+
delegatesManager.addDelegate(new CatAdapterDelegate(activity, 1));
46+
delegatesManager.addDelegate(new DogAdapterDelegate(activity, 2));
47+
delegatesManager.addDelegate(new GeckoAdapterDelegate(activity, 3));
48+
delegatesManager.addDelegate(new SnakeAdapterDelegate(activity, 4));
49+
50+
}
51+
52+
@Override public int getItemViewType(int position) {
53+
return delegatesManager.getItemViewType(items, position);
54+
}
55+
56+
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
57+
return delegatesManager.onCreateViewHolder(parent, viewType);
58+
}
59+
60+
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
61+
delegatesManager.onBindViewHolder(items, position, holder);
62+
}
63+
64+
@Override public int getItemCount() {
65+
return items.size();
66+
}
67+
}

0 commit comments

Comments
 (0)