From 83a0b96aebbaa715b7c9d24c76774e83cf51520d Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Wed, 1 Mar 2017 15:24:39 +0530 Subject: [PATCH] Add RecyclerView module --- demo/build.gradle | 1 + .../android/proteus/demo/ProteusActivity.java | 2 + recyclerview-v7/.gitignore | 1 + recyclerview-v7/build.gradle | 78 +++++++++++++++++++ recyclerview-v7/proguard-rules.pro | 33 ++++++++ recyclerview-v7/src/main/AndroidManifest.xml | 20 +++++ .../v7/RecyclerViewCollection.java | 43 ++++++++++ .../recyclerview/v7/RecyclerViewParser.java | 64 +++++++++++++++ .../v7/widget/ProteusRecyclerView.java | 56 +++++++++++++ settings.gradle | 2 +- 10 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 recyclerview-v7/.gitignore create mode 100644 recyclerview-v7/build.gradle create mode 100644 recyclerview-v7/proguard-rules.pro create mode 100644 recyclerview-v7/src/main/AndroidManifest.xml create mode 100644 recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewCollection.java create mode 100644 recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewParser.java create mode 100644 recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/widget/ProteusRecyclerView.java diff --git a/demo/build.gradle b/demo/build.gradle index 2dd5961b..f8ce878b 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -74,6 +74,7 @@ android { compile project(':proteus-core') compile project(':gson-adapter') compile project(':support-v4') + compile project(':recyclerview-v7') } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java b/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java index 129f7e83..300df6b9 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java @@ -48,6 +48,7 @@ import com.flipkart.android.proteus.demo.converter.GsonConverterFactory; import com.flipkart.android.proteus.demo.models.JsonResource; import com.flipkart.android.proteus.gson.ProteusTypeAdapterFactory; +import com.flipkart.android.proteus.recyclerview.v7.RecyclerViewCollection; import com.flipkart.android.proteus.support.v4.SupportV4Collection; import com.flipkart.android.proteus.toolbox.EventType; import com.flipkart.android.proteus.value.DrawableValue; @@ -184,6 +185,7 @@ protected void onStart() { Proteus proteus = new ProteusBuilder() .register(SupportV4Collection.create()) + .register(RecyclerViewCollection.create()) .register(new CircleViewParser()) .build(); diff --git a/recyclerview-v7/.gitignore b/recyclerview-v7/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/recyclerview-v7/.gitignore @@ -0,0 +1 @@ +/build diff --git a/recyclerview-v7/build.gradle b/recyclerview-v7/build.gradle new file mode 100644 index 00000000..53e1bb38 --- /dev/null +++ b/recyclerview-v7/build.gradle @@ -0,0 +1,78 @@ +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * Copyright (c) 2017 Flipkart Internet Pvt. Ltd. + * + * 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. + */ + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.1" + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) +} + +afterEvaluate { + javadoc.classpath += files(android.libraryVariants.collect { variant -> + variant.javaCompile.classpath.files + }) +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives javadocJar + archives sourcesJar +} + +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' + }) + compile 'com.android.support:recyclerview-v7:25.1.0' + compile 'com.android.support:appcompat-v7:25.1.0' + testCompile 'junit:junit:4.12' + compile project(path: ':proteus-core') +} diff --git a/recyclerview-v7/proguard-rules.pro b/recyclerview-v7/proguard-rules.pro new file mode 100644 index 00000000..fc826501 --- /dev/null +++ b/recyclerview-v7/proguard-rules.pro @@ -0,0 +1,33 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/aditya.sharat/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 *; +#} +-dontobfuscate +-printmapping out.map +-keepparameternames +-renamesourcefileattribute SourceFile +-keepattributes Exceptions,InnerClasses,Signature,Deprecated + +# Preserve all annotations. + +-keepattributes *Annotation* + +# Preserve all public classes, and their public and protected fields and +# methods. + +-keep public class * { + public protected *; +} \ No newline at end of file diff --git a/recyclerview-v7/src/main/AndroidManifest.xml b/recyclerview-v7/src/main/AndroidManifest.xml new file mode 100644 index 00000000..3305a38f --- /dev/null +++ b/recyclerview-v7/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewCollection.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewCollection.java new file mode 100644 index 00000000..b023c280 --- /dev/null +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewCollection.java @@ -0,0 +1,43 @@ +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * Copyright (c) 2017 Flipkart Internet Pvt. Ltd. + * + * 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.flipkart.android.proteus.recyclerview.v7; + +import com.flipkart.android.proteus.ProteusBuilder; + +/** + * RecyclerViewCollection + * + * @author adityasharat + */ +public class RecyclerViewCollection implements ProteusBuilder.Collection { + + private RecyclerViewCollection() { + + } + + public static RecyclerViewCollection create() { + return new RecyclerViewCollection(); + } + + @Override + public void registerWith(ProteusBuilder builder) { + builder.register(new RecyclerViewParser()); + } +} diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewParser.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewParser.java new file mode 100644 index 00000000..9a4024a8 --- /dev/null +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/RecyclerViewParser.java @@ -0,0 +1,64 @@ +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * Copyright (c) 2017 Flipkart Internet Pvt. Ltd. + * + * 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.flipkart.android.proteus.recyclerview.v7; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; +import android.view.ViewGroup; + +import com.flipkart.android.proteus.ProteusContext; +import com.flipkart.android.proteus.ProteusView; +import com.flipkart.android.proteus.ViewTypeParser; +import com.flipkart.android.proteus.recyclerview.v7.widget.ProteusRecyclerView; +import com.flipkart.android.proteus.value.Layout; +import com.flipkart.android.proteus.value.ObjectValue; + +/** + * RecyclerViewParser + * + * @author adityasharat + */ + +public class RecyclerViewParser extends ViewTypeParser { + + @NonNull + @Override + public String getType() { + return "RecyclerView"; + } + + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusRecyclerView(context); + } + + @Override + protected void addAttributeProcessors() { + + } +} diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/widget/ProteusRecyclerView.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/widget/ProteusRecyclerView.java new file mode 100644 index 00000000..ce2ab93c --- /dev/null +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/recyclerview/v7/widget/ProteusRecyclerView.java @@ -0,0 +1,56 @@ +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * Copyright (c) 2017 Flipkart Internet Pvt. Ltd. + * + * 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.flipkart.android.proteus.recyclerview.v7.widget; + +import android.support.v7.widget.RecyclerView; +import android.view.View; + +import com.flipkart.android.proteus.ProteusContext; +import com.flipkart.android.proteus.ProteusView; + +/** + * ProteusRecyclerView + * + * @author adityasharat + */ + +public class ProteusRecyclerView extends RecyclerView implements ProteusView { + + Manager manager; + + public ProteusRecyclerView(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(Manager manager) { + this.manager = manager; + } + + @Override + public View getAsView() { + return this; + } +} diff --git a/settings.gradle b/settings.gradle index 52a57c46..339430a8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,4 +17,4 @@ * specific language governing permissions and limitations under the License. */ -include ':demo', ':proteus-core', ':gson-adapter', ':support-v4' \ No newline at end of file +include ':demo', ':proteus-core', ':gson-adapter', ':support-v4', ':recyclerview-v7' \ No newline at end of file