-
Notifications
You must be signed in to change notification settings - Fork 313
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
0 parents
commit 86318b8
Showing
61 changed files
with
2,612 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,74 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
|
||
# Built application files | ||
*.apk | ||
*.ap_ | ||
bin/ | ||
gen/ | ||
classes/ | ||
gen-external-apklibs/ | ||
|
||
# Eclipse project files | ||
.classpath | ||
.project | ||
.metadata | ||
.settings | ||
|
||
# IntelliJ files | ||
.idea | ||
*.iml | ||
|
||
# OSX files | ||
.DS_Store | ||
|
||
# Windows files | ||
Thumbs.db | ||
|
||
# vi swap files | ||
*.swp | ||
|
||
# backup files | ||
*.bak | ||
|
||
|
||
# Files for the Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
.gradle | ||
|
||
#maven files | ||
target/ | ||
/null | ||
|
||
# Local configuration file (sdk path, etc) | ||
|
||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
#Log Files | ||
*.log | ||
|
||
|
||
#crashlytics | ||
app/src/main/res/values/com_crashlytics_export_strings.xml | ||
|
||
#infer | ||
infer-out/ |
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,6 @@ | ||
# AdapterDelegates | ||
Read more about this project in my blog post. | ||
|
||
|
||
## Idea | ||
The idea of this library is to build your adapters by composing reusable components like `AdapterDelegates` |
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,66 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
bin/ | ||
gen/ | ||
classes/ | ||
gen-external-apklibs/ | ||
|
||
# Eclipse project files | ||
.classpath | ||
.project | ||
.metadata | ||
.settings | ||
|
||
# IntelliJ files | ||
.idea | ||
*.iml | ||
|
||
# OSX files | ||
.DS_Store | ||
|
||
# Windows files | ||
Thumbs.db | ||
|
||
# vi swap files | ||
*.swp | ||
|
||
# backup files | ||
*.bak | ||
|
||
|
||
# Files for the Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
.gradle | ||
|
||
#maven files | ||
target/ | ||
/null | ||
|
||
# Local configuration file (sdk path, etc) | ||
|
||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
#Log Files | ||
*.log | ||
|
||
|
||
#crashlytics | ||
app/src/main/res/values/com_crashlytics_export_strings.xml | ||
|
||
#infer | ||
infer-out/ |
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,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 22 | ||
buildToolsVersion "23.0.0 rc2" | ||
|
||
defaultConfig { | ||
applicationId "com.hannesdorfmann.adapterdelegates.sample" | ||
minSdkVersion 8 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile rootProject.ext.appCompat | ||
compile rootProject.ext.recyclerView | ||
|
||
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/hannes/android-sdks/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 *; | ||
#} |
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,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.hannesdorfmann.adapterdelegates.sample" | ||
> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".ReptilesActivity" | ||
android:label="Reptiels" | ||
/> | ||
</application> | ||
|
||
</manifest> |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/hannesdorfmann/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,67 @@ | ||
package com.hannesdorfmann.adapterdelegates.sample; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.Advertisement; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.Cat; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.DisplayableItem; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.Dog; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.Gecko; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.Snake; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
RecyclerView rv = (RecyclerView) findViewById(R.id.recyclerView); | ||
rv.setLayoutManager(new LinearLayoutManager(this)); | ||
MainAdapter adapter = new MainAdapter(this, getAnimals()); | ||
rv.setAdapter(adapter); | ||
|
||
|
||
findViewById(R.id.reptielsActivity).setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
startActivity(new Intent(MainActivity.this, ReptilesActivity.class)); | ||
} | ||
}); | ||
} | ||
|
||
private List<DisplayableItem> getAnimals() { | ||
List<DisplayableItem> animals = new ArrayList<>(); | ||
|
||
animals.add(new Cat("American Curl")); | ||
animals.add(new Cat("Baliness")); | ||
animals.add(new Cat("Bengal")); | ||
animals.add(new Cat("Corat")); | ||
animals.add(new Cat("Manx")); | ||
animals.add(new Cat("Nebelung")); | ||
animals.add(new Dog("Aidi")); | ||
animals.add(new Dog("Chinook")); | ||
animals.add(new Dog("Appenzeller")); | ||
animals.add(new Dog("Collie")); | ||
animals.add(new Snake("Mub Adder", "Adder")); | ||
animals.add(new Snake("Texas Blind Snake", "Blind snake")); | ||
animals.add(new Snake("Tree Boa", "Boa")); | ||
animals.add(new Gecko("Fat-tailed", "Hemitheconyx")); | ||
animals.add(new Gecko("Stenodactylus", "Dune Gecko")); | ||
animals.add(new Gecko("Leopard Gecko", "Eublepharis")); | ||
animals.add(new Gecko("Madagascar Gecko", "Phelsuma")); | ||
animals.add(new Advertisement()); | ||
animals.add(new Advertisement()); | ||
animals.add(new Advertisement()); | ||
animals.add(new Advertisement()); | ||
animals.add(new Advertisement()); | ||
|
||
Collections.shuffle(animals); | ||
return animals; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/hannesdorfmann/adapterdelegates/sample/MainAdapter.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,67 @@ | ||
/* | ||
* Copyright (c) 2015 Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hannesdorfmann.adapterdelegates.sample; | ||
|
||
import android.app.Activity; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.ViewGroup; | ||
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager; | ||
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.AdvertisementAdapterDelegate; | ||
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.CatAdapterDelegate; | ||
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.DogAdapterDelegate; | ||
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.GeckoAdapterDelegate; | ||
import com.hannesdorfmann.adapterdelegates.sample.adapterdelegates.SnakeAdapterDelegate; | ||
import com.hannesdorfmann.adapterdelegates.sample.model.DisplayableItem; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Hannes Dorfmann | ||
*/ | ||
public class MainAdapter extends RecyclerView.Adapter { | ||
|
||
private AdapterDelegatesManager<List<DisplayableItem>> delegatesManager; | ||
private List<DisplayableItem> items; | ||
|
||
public MainAdapter(Activity activity, List<DisplayableItem> items) { | ||
this.items = items; | ||
|
||
// Delegates | ||
delegatesManager = new AdapterDelegatesManager<>(); | ||
delegatesManager.addDelegate(new AdvertisementAdapterDelegate(activity, 0)); | ||
delegatesManager.addDelegate(new CatAdapterDelegate(activity, 1)); | ||
delegatesManager.addDelegate(new DogAdapterDelegate(activity, 2)); | ||
delegatesManager.addDelegate(new GeckoAdapterDelegate(activity, 3)); | ||
delegatesManager.addDelegate(new SnakeAdapterDelegate(activity, 4)); | ||
|
||
} | ||
|
||
@Override public int getItemViewType(int position) { | ||
return delegatesManager.getItemViewType(items, position); | ||
} | ||
|
||
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return delegatesManager.onCreateViewHolder(parent, viewType); | ||
} | ||
|
||
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | ||
delegatesManager.onBindViewHolder(items, position, holder); | ||
} | ||
|
||
@Override public int getItemCount() { | ||
return items.size(); | ||
} | ||
} |
Oops, something went wrong.