├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── easyadapter ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── mzule │ │ └── easyadapter │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── mzule │ │ │ └── easyadapter │ │ │ ├── EasyAdapter.java │ │ │ ├── MultiTypeAdapter.java │ │ │ ├── SingleTypeAdapter.java │ │ │ ├── TypePerEntityAdapter.java │ │ │ ├── TypeRegisteException.java │ │ │ └── ViewType.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── github │ └── mzule │ └── easyadapter │ └── ExampleUnitTest.java ├── easyadapterrecycler ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── mzule │ │ └── easyadapter │ │ └── recycler │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── mzule │ │ │ └── easyadapter │ │ │ └── recycler │ │ │ ├── MultiTypeAdapter.java │ │ │ ├── SingleTypeAdapter.java │ │ │ ├── TypePerEntityAdapter.java │ │ │ └── ViewTypeHolder.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── github │ └── mzule │ └── easyadapter │ └── recycler │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── mzule │ │ │ └── easyadapter │ │ │ └── sample │ │ │ ├── MainActivity.java │ │ │ ├── MultiTypeListActivity.java │ │ │ ├── SingleTypeListActivity.java │ │ │ ├── TypePerEntityListActivity.java │ │ │ ├── po │ │ │ ├── Ad.java │ │ │ ├── Article.java │ │ │ ├── Post.java │ │ │ ├── Recommend.java │ │ │ └── Repost.java │ │ │ └── viewtypes │ │ │ ├── AdViewType.java │ │ │ ├── ArticleBriefViewType.java │ │ │ ├── ArticleFullViewType.java │ │ │ ├── PostViewType.java │ │ │ ├── RecommendViewType.java │ │ │ ├── RepostViewType.java │ │ │ └── TipViewType.java │ └── res │ │ ├── drawable-xxhdpi │ │ └── placeholder.png │ │ ├── drawable │ │ └── divider.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_multi_type_list.xml │ │ ├── activity_single_type_list.xml │ │ ├── activity_type_per_entity_list.xml │ │ ├── item_ad.xml │ │ ├── item_article_brief.xml │ │ ├── item_article_full.xml │ │ ├── item_post.xml │ │ ├── item_recommend.xml │ │ ├── item_repost.xml │ │ ├── item_text.xml │ │ └── item_tip.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── github │ └── mzule │ └── easyadapter │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyAdapter 2 | 3 | 一种简单的 Adapter 解决方案,支持多种 ViewType,轻松创建 `ViewHolder` 模式 Adapter. 支持 `ListView` 和 `RecyclerView`. 4 | 5 | ## 安装 6 | 仅支持 `ListView` 7 | 8 | ``` groovy 9 | dependencies { 10 | compile 'com.github.mzule.easyadapter:easyadapter:1.1.3' 11 | } 12 | ``` 13 | 需要支持 `RecyclerView` 14 | ``` groovy 15 | dependencies { 16 | compile 'com.github.mzule.easyadapter:easyadapter:1.1.3' 17 | compile 'com.github.mzule.easyadapter:easyadapterrecycler:1.1.3' 18 | } 19 | ``` 20 | 21 | 22 | ## 使用步骤 23 | 24 | 项目包含四个类, `ViewType`, `SingleTypeAdapter`, `MultiTypeAdapter`, `TypePerEntityAdapter`, 其中 `ViewType` 负责创建、绑定( Hold )、渲染View; `SingleTypeAdapter` 支持单独一种样式类型的Adapter, `MultiTypeAdapter`, `TypePerEntityAdapter` 支持多种样式类型的Adapter;`TypePerEntityAdapter` 是 `MultiTypeAdapter` 的子类。 25 | 26 | ### 1. 编写`ViewType`(s) 27 | 28 | `ViewType` 负责创建、绑定、渲染View,每个 `ViewType` 对应传统模式下的一个 `ViewHolder`,一个典型的 `ViewType` 实现如下: 29 | 30 | ``` java 31 | public class TipViewType extends ViewType { 32 | private TextView tipView; 33 | 34 | @Override 35 | public void onCreate() { 36 | setContentView(R.layout.item_tip); 37 | this.tipView = findViewById(R.id.tip); 38 | } 39 | 40 | @Override 41 | public void onRender(int position, String tip) { 42 | tipView.setText(tip); 43 | } 44 | } 45 | ``` 46 | `ViewType` 提供了一个 `findViewById(int)` 方法,可以根据声明的类型进行强制转换。 47 | 48 | 1. `onCreate` 可以通过调用 `setContentView(int)` 或者 `setContentView(View)` 创建 View,初始化成员变量; 49 | 2. `onRender(int, T)` 负责渲染UI,绑定数据. 50 | 51 | `ViewType` 还提供了一个 `getAdapter()` 方法直接直接操作 Adapter.以及一个 `isEditMode()` 检查当前是否在编辑模式. 52 | 53 | ### 2. 选择合适的 `Adapter` 54 | 55 | 项目为 `ListView` , `RecyclerVIew` 个提供了 3 个 `Adapter` 基类,名字一样,只是包名略作区分,分别是 `com.github.mzule.easyadapter` , `com.github.mzule.easyadapter.recycler` 。下面一一说明。 56 | 57 | #### 1. SingleTypeAdapter 58 | 59 | `SingleTypeAdapter` 适合仅有一种类型View的 `ListView` ,典型实现如下: 60 | 61 | ``` java 62 | class PlainAdapter extends SingleTypeAdapter { 63 | 64 | public PlainAdapter(Context context) { 65 | super(context); 66 | } 67 | 68 | @Override 69 | protected Class singleViewType() { 70 | return TipViewType.class; 71 | } 72 | } 73 | ``` 74 | 75 | #### 2. MultiTypeAdapter 76 | 77 | 顾名思义,`MultiTypeAdapter` 适用于需要在 `ListView` 上显示多种类型 View 的时候,比如说微博客户端,一堆微博之间,夹杂几个广告,正好适用。典型实现: 78 | 79 | ``` java 80 | class ArticleAdapter extends MultiTypeAdapter
{ 81 | 82 | public ArticleAdapter(Context context) { 83 | super(context); 84 | } 85 | 86 | @Override 87 | protected void registerViewTypes() { 88 | registerViewType(ArticleBriefViewType.class); 89 | registerViewType(ArticleFullViewType.class); 90 | } 91 | 92 | @Override 93 | protected Class getViewType(int position, Article data) { 94 | switch (data.getStyle()) { 95 | case Article.STYLE_FULL: 96 | return ArticleFullViewType.class; 97 | case Article.STYLE_BRIEF: 98 | return ArticleBriefViewType.class; 99 | } 100 | return null; 101 | } 102 | } 103 | ``` 104 | 105 | #### 3.TypePerEntityAdapter 106 | 107 | `TypePerEntityAdapter` 是 `MultiTypeAdapter` 的子类,适用于每个数据实体 class 都对应不同的 `ViewType` 实现,例如: 108 | 109 | ``` java 110 | class TimelineAdapter extends TypePerEntityAdapter { 111 | 112 | public TimelineAdapter(Context context) { 113 | super(context); 114 | } 115 | 116 | @Override 117 | protected void mapEntityViewTypes() { 118 | mapEntityViewType(Post.class, PostViewType.class); 119 | mapEntityViewType(Repost.class, RepostViewType.class); 120 | mapEntityViewType(String.class, TipViewType.class); 121 | mapEntityViewType(Recommend.class, RecommendViewType.class); 122 | mapEntityViewType(Ad.class, AdViewType.class); 123 | } 124 | } 125 | ``` 126 | 127 | ### 3. 应用 `Adapter` 128 | 通过 `ListView#setAdapter(Adapter)` 使用 Adapter ,通过 `add(List)` / `addAndNotify(List)` / `clear()` / `clearAndNotify()` 添加或修改Adapter内的数据。`add(List)` 和 `addAndNotify(List)` 的区别在于是否自动调用 `notifyDataSetChanged()` , `clear` 亦然。 129 | 130 | ``` java 131 | ListView listView = (ListView) findViewById(R.id.listView); 132 | listView.setAdapter(adapter); 133 | List fake = new ArrayList<>(); 134 | for (int i = 0; i < 100; i++) { 135 | fake.add(UUID.randomUUID().toString()); 136 | } 137 | adapter.addAndNotify(fake); 138 | ``` 139 | 140 | ## 尽情享用 141 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.5.0' 7 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' 8 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /easyadapter/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /easyadapter/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | ext { 4 | bintrayRepo = 'maven' 5 | bintrayName = 'easy-adapter' 6 | 7 | publishedGroupId = 'com.github.mzule.easyadapter' 8 | libraryName = 'EasyAdapter' 9 | artifact = 'easyadapter' 10 | 11 | libraryDescription = 'Easy to use adaptes.' 12 | 13 | siteUrl = 'https://github.com/mzule/EasyAdapter/' 14 | gitUrl = 'https://github.com/mzule/EasyAdapter.git' 15 | 16 | libraryVersion = '1.1.3' 17 | 18 | developerId = 'mzule' 19 | developerName = 'Cao Dongping' 20 | developerEmail = 'mzule4j@gmail.com' 21 | 22 | licenseName = 'The Apache Software License, Version 2.0' 23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 24 | allLicenses = ["Apache-2.0"] 25 | } 26 | 27 | android { 28 | compileSdkVersion 15 29 | buildToolsVersion "23.0.2" 30 | 31 | defaultConfig { 32 | minSdkVersion 1 33 | targetSdkVersion 22 34 | versionCode 1 35 | versionName "1.1.2" 36 | } 37 | buildTypes { 38 | release { 39 | minifyEnabled false 40 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 41 | } 42 | } 43 | } 44 | 45 | dependencies { 46 | compile fileTree(dir: 'libs', include: ['*.jar']) 47 | } 48 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 49 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' 50 | -------------------------------------------------------------------------------- /easyadapter/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/baidu/Library/Android/sdk/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 | #} 18 | -------------------------------------------------------------------------------- /easyadapter/src/androidTest/java/com/github/mzule/easyadapter/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /easyadapter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/EasyAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by CaoDongping on 3/22/16. 7 | */ 8 | public interface EasyAdapter { 9 | 10 | void add(List data); 11 | 12 | void addAndNotify(List data); 13 | 14 | void clear(); 15 | 16 | void clearAndNotify(); 17 | 18 | void remove(int position); 19 | 20 | void removeAndNotify(int position); 21 | 22 | void remove(T item); 23 | 24 | void removeAndNotify(T item); 25 | 26 | List getData(); 27 | 28 | /** 29 | * Retrieve the raw viewType (value returned by `getItemViewType(int)`) at adapter. 30 | * 31 | * @param viewType ViewType class 32 | * @return 0, 1, 2... The raw viewType value. 33 | */ 34 | int getRawViewType(Class viewType); 35 | 36 | List> getViewTypes(); 37 | 38 | boolean isEditMode(); 39 | 40 | void setEditModeAndNotify(boolean editMode); 41 | } 42 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/MultiTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.BaseAdapter; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by CaoDongping on 3/17/16. 13 | */ 14 | public abstract class MultiTypeAdapter extends BaseAdapter implements EasyAdapter { 15 | private List data; 16 | private List> viewTypes; 17 | private Context context; 18 | private boolean editMode; 19 | 20 | public MultiTypeAdapter(Context context) { 21 | this.context = context; 22 | this.data = new ArrayList(); 23 | this.viewTypes = new ArrayList>(); 24 | registerViewTypes(); 25 | } 26 | 27 | protected void registerViewType(Class cls) { 28 | this.viewTypes.add(cls); 29 | } 30 | 31 | @Override 32 | public List> getViewTypes() { 33 | return viewTypes; 34 | } 35 | 36 | @Override 37 | public int getRawViewType(Class viewType) { 38 | return viewTypes.indexOf(viewType); 39 | } 40 | 41 | @Override 42 | public List getData() { 43 | return data; 44 | } 45 | 46 | @Override 47 | public int getCount() { 48 | return data.size(); 49 | } 50 | 51 | @Override 52 | public int getItemViewType(int position) { 53 | Class cls = getViewType(position, getItem(position)); 54 | if (cls == null) { 55 | throw new TypeRegisteException("No ViewType bind for [" + getItem(position).getClass() + "] at position " + position); 56 | } 57 | int type = viewTypes.indexOf(cls); 58 | if (type < 0) { 59 | throw new TypeRegisteException(String.format("ViewType not registered [%s]", cls.toString())); 60 | } 61 | return type; 62 | } 63 | 64 | @Override 65 | public int getViewTypeCount() { 66 | return viewTypes.size(); 67 | } 68 | 69 | @Override 70 | public T getItem(int position) { 71 | return data.get(position); 72 | } 73 | 74 | @Override 75 | public long getItemId(int position) { 76 | return position; 77 | } 78 | 79 | @Override 80 | @SuppressWarnings("unchecked") 81 | public View getView(int position, View convertView, ViewGroup parent) { 82 | if (convertView == null) { 83 | ViewType viewType = createViewType(getViewType(position, getItem(position))); 84 | viewType.with(context).onCreate(); 85 | viewType.setAdapter(this); 86 | convertView = viewType.getView(); 87 | convertView.setTag(viewType); 88 | } 89 | ViewType viewType = (ViewType) convertView.getTag(); 90 | viewType.onRender(position, getItem(position)); 91 | viewType.setEditMode(isEditMode()); 92 | return convertView; 93 | } 94 | 95 | @SuppressWarnings("unchecked") 96 | private ViewType createViewType(Class cls) { 97 | ViewType viewType; 98 | try { 99 | viewType = cls.newInstance(); 100 | } catch (Throwable e) { 101 | e.printStackTrace(); 102 | throw new RuntimeException("Error on instantiation class [" + cls.toString() + "], please make sure the class is `public` for others."); 103 | } 104 | return viewType; 105 | } 106 | 107 | @Override 108 | public void add(List data) { 109 | if (data != null) { 110 | this.data.addAll(data); 111 | } 112 | } 113 | 114 | @Override 115 | public void addAndNotify(List data) { 116 | add(data); 117 | notifyDataSetChanged(); 118 | } 119 | 120 | @Override 121 | public void clear() { 122 | data.clear(); 123 | } 124 | 125 | 126 | @Override 127 | public void clearAndNotify() { 128 | clear(); 129 | notifyDataSetChanged(); 130 | } 131 | 132 | @Override 133 | public void remove(int position) { 134 | data.remove(position); 135 | } 136 | 137 | @Override 138 | public void removeAndNotify(int position) { 139 | remove(position); 140 | notifyDataSetChanged(); 141 | } 142 | 143 | @Override 144 | public void remove(T item) { 145 | data.remove(item); 146 | } 147 | 148 | @Override 149 | public void removeAndNotify(T item) { 150 | remove(item); 151 | notifyDataSetChanged(); 152 | } 153 | 154 | @Override 155 | public boolean isEditMode() { 156 | return editMode; 157 | } 158 | 159 | @Override 160 | public void setEditModeAndNotify(boolean editMode) { 161 | this.editMode = editMode; 162 | notifyDataSetChanged(); 163 | } 164 | 165 | protected abstract void registerViewTypes(); 166 | 167 | protected abstract Class getViewType(int position, T data); 168 | } 169 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/SingleTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by CaoDongping on 1/4/16. 7 | */ 8 | public abstract class SingleTypeAdapter extends MultiTypeAdapter { 9 | public SingleTypeAdapter(Context context) { 10 | super(context); 11 | } 12 | 13 | @Override 14 | protected final void registerViewTypes() { 15 | registerViewType(singleViewType()); 16 | } 17 | 18 | protected abstract Class singleViewType(); 19 | 20 | @Override 21 | protected final Class getViewType(int position, T data) { 22 | return getViewTypes().get(0); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/TypePerEntityAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.Collection; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by CaoDongping on 3/18/16. 11 | */ 12 | public abstract class TypePerEntityAdapter extends MultiTypeAdapter { 13 | private Map> map; 14 | 15 | public TypePerEntityAdapter(Context context) { 16 | super(context); 17 | } 18 | 19 | @Override 20 | protected final void registerViewTypes() { 21 | map = new HashMap>(); 22 | mapEntityViewTypes(); 23 | Collection> values = map.values(); 24 | for (Class c : values) { 25 | registerViewType(c); 26 | } 27 | } 28 | 29 | protected final void mapEntityViewType(Class entityType, Class viewTypes) { 30 | map.put(entityType, viewTypes); 31 | } 32 | 33 | protected abstract void mapEntityViewTypes(); 34 | 35 | @Override 36 | protected final Class getViewType(int position, T data) { 37 | return map.get(data.getClass()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/TypeRegisteException.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | /** 4 | * Created by CaoDongping on 3/21/16. 5 | */ 6 | public class TypeRegisteException extends RuntimeException { 7 | public TypeRegisteException(String detailMessage) { 8 | super(detailMessage); 9 | } 10 | 11 | public TypeRegisteException(String detailMessage, Throwable throwable) { 12 | super(detailMessage, throwable); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /easyadapter/src/main/java/com/github/mzule/easyadapter/ViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | 7 | public abstract class ViewType { 8 | private Context context; 9 | private View view; 10 | private EasyAdapter adapter; 11 | private boolean editMode; 12 | 13 | protected void setContentView(int layoutId) { 14 | setContentView(LayoutInflater.from(context).inflate(layoutId, null, false)); 15 | } 16 | 17 | protected void setContentView(View view) { 18 | this.view = view; 19 | } 20 | 21 | public ViewType with(Context context) { 22 | this.context = context; 23 | return this; 24 | } 25 | 26 | public EasyAdapter getAdapter() { 27 | return adapter; 28 | } 29 | 30 | public void setAdapter(EasyAdapter adapter) { 31 | this.adapter = adapter; 32 | } 33 | 34 | protected Context getContext() { 35 | return context; 36 | } 37 | 38 | @SuppressWarnings("unchecked") 39 | protected V findViewById(int id) { 40 | return (V) view.findViewById(id); 41 | } 42 | 43 | public View getView() { 44 | return view; 45 | } 46 | 47 | 48 | public boolean isEditMode() { 49 | return editMode; 50 | } 51 | 52 | public void setEditMode(boolean editMode) { 53 | this.editMode = editMode; 54 | } 55 | 56 | public abstract void onCreate(); 57 | 58 | public abstract void onRender(int position, T data); 59 | } -------------------------------------------------------------------------------- /easyadapter/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /easyadapter/src/test/java/com/github/mzule/easyadapter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /easyadapterrecycler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /easyadapterrecycler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | ext { 4 | bintrayRepo = 'maven' 5 | bintrayName = 'easy-adapter-recycler' 6 | 7 | publishedGroupId = 'com.github.mzule.easyadapter' 8 | libraryName = 'EasyAdapterRecycler' 9 | artifact = 'easyadapterrecycler' 10 | 11 | libraryDescription = 'Easy to use adaptes.' 12 | 13 | siteUrl = 'https://github.com/mzule/EasyAdapter/' 14 | gitUrl = 'https://github.com/mzule/EasyAdapter.git' 15 | 16 | libraryVersion = '1.1.3' 17 | 18 | developerId = 'mzule' 19 | developerName = 'Cao Dongping' 20 | developerEmail = 'mzule4j@gmail.com' 21 | 22 | licenseName = 'The Apache Software License, Version 2.0' 23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 24 | allLicenses = ["Apache-2.0"] 25 | } 26 | 27 | android { 28 | compileSdkVersion 21 29 | buildToolsVersion "23.0.2" 30 | 31 | defaultConfig { 32 | minSdkVersion 15 33 | targetSdkVersion 21 34 | versionCode 1 35 | versionName "1.1.2" 36 | } 37 | buildTypes { 38 | release { 39 | minifyEnabled false 40 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 41 | } 42 | } 43 | } 44 | 45 | dependencies { 46 | compile fileTree(dir: 'libs', include: ['*.jar']) 47 | testCompile 'junit:junit:4.12' 48 | compile 'com.android.support:appcompat-v7:21.0.3' 49 | compile 'com.android.support:recyclerview-v7:21.0.3' 50 | compile 'com.github.mzule.easyadapter:easyadapter:1.1.2' 51 | } 52 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 53 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' 54 | -------------------------------------------------------------------------------- /easyadapterrecycler/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/baidu/Library/Android/sdk/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 | #} 18 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/androidTest/java/com/github/mzule/easyadapter/recycler/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/java/com/github/mzule/easyadapter/recycler/MultiTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.ViewGroup; 6 | 7 | import com.github.mzule.easyadapter.EasyAdapter; 8 | import com.github.mzule.easyadapter.TypeRegisteException; 9 | import com.github.mzule.easyadapter.ViewType; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by CaoDongping on 3/22/16. 16 | */ 17 | public abstract class MultiTypeAdapter extends RecyclerView.Adapter implements EasyAdapter { 18 | private List data; 19 | private List> viewTypes; 20 | private Context context; 21 | private boolean editMode; 22 | 23 | public MultiTypeAdapter(Context context) { 24 | this.context = context; 25 | this.data = new ArrayList(); 26 | this.viewTypes = new ArrayList>(); 27 | registerViewTypes(); 28 | } 29 | 30 | protected void registerViewType(Class cls) { 31 | this.viewTypes.add(cls); 32 | } 33 | 34 | @Override 35 | public List> getViewTypes() { 36 | return viewTypes; 37 | } 38 | 39 | @Override 40 | public int getRawViewType(Class viewType) { 41 | return viewTypes.indexOf(viewType); 42 | } 43 | 44 | @Override 45 | public List getData() { 46 | return data; 47 | } 48 | 49 | @Override 50 | public int getItemCount() { 51 | return data.size(); 52 | } 53 | 54 | @Override 55 | public long getItemId(int position) { 56 | return position; 57 | } 58 | 59 | @Override 60 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) { 61 | ViewType viewType = createViewType(viewTypes.get(type)); 62 | viewType.with(context).onCreate(); 63 | viewType.setAdapter(this); 64 | return new ViewTypeHolder(viewType); 65 | } 66 | 67 | @Override 68 | public int getItemViewType(int position) { 69 | Class cls = getViewType(position, data.get(position)); 70 | if (cls == null) { 71 | throw new TypeRegisteException("No ViewType bind for [" + data.get(position).getClass() + "] at position " + position); 72 | } 73 | int type = viewTypes.indexOf(cls); 74 | if (type < 0) { 75 | throw new TypeRegisteException(String.format("ViewType not registered [%s]", cls.toString())); 76 | } 77 | return type; 78 | } 79 | 80 | @Override 81 | @SuppressWarnings("unchecked") 82 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 83 | ViewTypeHolder viewTypeHolder = (ViewTypeHolder) holder; 84 | viewTypeHolder.viewType.onRender(position, data.get(position)); 85 | viewTypeHolder.viewType.setEditMode(isEditMode()); 86 | } 87 | 88 | @SuppressWarnings("unchecked") 89 | private ViewType createViewType(Class cls) { 90 | ViewType viewType; 91 | try { 92 | viewType = cls.newInstance(); 93 | } catch (Throwable e) { 94 | e.printStackTrace(); 95 | throw new RuntimeException("Error on instantiation class [" + cls.toString() + "], please make sure the class is `public` for others."); 96 | } 97 | return viewType; 98 | } 99 | 100 | @Override 101 | public void add(List data) { 102 | if (data != null) { 103 | this.data.addAll(data); 104 | } 105 | } 106 | 107 | @Override 108 | public void addAndNotify(List data) { 109 | add(data); 110 | notifyDataSetChanged(); 111 | } 112 | 113 | @Override 114 | public void clear() { 115 | data.clear(); 116 | } 117 | 118 | 119 | @Override 120 | public void clearAndNotify() { 121 | clear(); 122 | notifyDataSetChanged(); 123 | } 124 | 125 | 126 | @Override 127 | public void remove(int position) { 128 | data.remove(position); 129 | } 130 | 131 | @Override 132 | public void removeAndNotify(int position) { 133 | remove(position); 134 | notifyDataSetChanged(); 135 | } 136 | 137 | @Override 138 | public void remove(T item) { 139 | data.remove(item); 140 | } 141 | 142 | @Override 143 | public void removeAndNotify(T item) { 144 | remove(item); 145 | notifyDataSetChanged(); 146 | } 147 | 148 | @Override 149 | public boolean isEditMode() { 150 | return editMode; 151 | } 152 | 153 | @Override 154 | public void setEditModeAndNotify(boolean editMode) { 155 | this.editMode = editMode; 156 | notifyDataSetChanged(); 157 | } 158 | 159 | protected abstract void registerViewTypes(); 160 | 161 | protected abstract Class getViewType(int position, T data); 162 | } 163 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/java/com/github/mzule/easyadapter/recycler/SingleTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.mzule.easyadapter.ViewType; 6 | 7 | /** 8 | * Created by CaoDongping on 3/22/16. 9 | */ 10 | public abstract class SingleTypeAdapter extends MultiTypeAdapter { 11 | public SingleTypeAdapter(Context context) { 12 | super(context); 13 | } 14 | 15 | @Override 16 | protected final void registerViewTypes() { 17 | registerViewType(singleViewType()); 18 | } 19 | 20 | protected abstract Class singleViewType(); 21 | 22 | @Override 23 | protected final Class getViewType(int position, T data) { 24 | return getViewTypes().get(0); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/java/com/github/mzule/easyadapter/recycler/TypePerEntityAdapter.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.mzule.easyadapter.ViewType; 6 | 7 | import java.util.Collection; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * Created by CaoDongping on 3/18/16. 13 | */ 14 | public abstract class TypePerEntityAdapter extends MultiTypeAdapter { 15 | private Map> map; 16 | 17 | public TypePerEntityAdapter(Context context) { 18 | super(context); 19 | } 20 | 21 | @Override 22 | protected final void registerViewTypes() { 23 | map = new HashMap>(); 24 | mapEntityViewTypes(); 25 | Collection> values = map.values(); 26 | for (Class c : values) { 27 | registerViewType(c); 28 | } 29 | } 30 | 31 | protected final void mapEntityViewType(Class entityType, Class viewTypes) { 32 | map.put(entityType, viewTypes); 33 | } 34 | 35 | protected abstract void mapEntityViewTypes(); 36 | 37 | @Override 38 | protected final Class getViewType(int position, T data) { 39 | return map.get(data.getClass()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/java/com/github/mzule/easyadapter/recycler/ViewTypeHolder.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | 5 | import com.github.mzule.easyadapter.ViewType; 6 | 7 | /** 8 | * Created by CaoDongping on 3/22/16. 9 | */ 10 | class ViewTypeHolder extends RecyclerView.ViewHolder { 11 | ViewType viewType; 12 | 13 | public ViewTypeHolder(ViewType viewType) { 14 | super(viewType.getView()); 15 | this.viewType = viewType; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EasyAdapterRecycler 3 | 4 | -------------------------------------------------------------------------------- /easyadapterrecycler/src/test/java/com/github/mzule/easyadapter/recycler/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.recycler; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 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-2.8-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.github.mzule.easyadapter.sample" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "0.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 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.github.bumptech.glide:glide:3.7.0' 27 | compile project(':easyadapterrecycler') 28 | } 29 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/baidu/Library/Android/sdk/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 | #} 18 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 28 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | /** 9 | * Created by CaoDongping on 3/18/16. 10 | */ 11 | public class MainActivity extends Activity implements View.OnClickListener { 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | 17 | findViewById(R.id.singleTypeButton).setOnClickListener(this); 18 | findViewById(R.id.multiTypeButton).setOnClickListener(this); 19 | findViewById(R.id.typePerEntityButton).setOnClickListener(this); 20 | } 21 | 22 | @Override 23 | public void onClick(View v) { 24 | Intent intent = new Intent(); 25 | switch (v.getId()) { 26 | case R.id.singleTypeButton: 27 | intent.setClass(this, SingleTypeListActivity.class); 28 | break; 29 | case R.id.multiTypeButton: 30 | intent.setClass(this, MultiTypeListActivity.class); 31 | break; 32 | case R.id.typePerEntityButton: 33 | intent.setClass(this, TypePerEntityListActivity.class); 34 | break; 35 | default: 36 | return; 37 | } 38 | startActivity(intent); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/MultiTypeListActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | 10 | import com.github.mzule.easyadapter.ViewType; 11 | import com.github.mzule.easyadapter.recycler.MultiTypeAdapter; 12 | import com.github.mzule.easyadapter.sample.po.Article; 13 | import com.github.mzule.easyadapter.sample.viewtypes.ArticleBriefViewType; 14 | import com.github.mzule.easyadapter.sample.viewtypes.ArticleFullViewType; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by CaoDongping on 3/18/16. 21 | */ 22 | public class MultiTypeListActivity extends Activity { 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_multi_type_list); 27 | 28 | ArticleAdapter adapter = new ArticleAdapter(this); 29 | RecyclerView listView = (RecyclerView) findViewById(R.id.listView); 30 | listView.setLayoutManager(new LinearLayoutManager(this)); 31 | listView.setAdapter(adapter); 32 | 33 | adapter.addAndNotify(makeFakeData()); 34 | } 35 | 36 | @NonNull 37 | private List
makeFakeData() { 38 | List
fake = new ArrayList<>(); 39 | fake.add(new Article("http://t.cn/RGk1oGN", "中国电商巨人打算进击印度?先听听他们的总裁怎么说\n" + 40 | "\n" + 41 | "他们选择印度,是因为“商业基因”相同?", Article.STYLE_BRIEF)); 42 | fake.add(new Article("http://t.cn/RGk1RjJ", "备忘录:新增密码保护、条件排序和印象笔记导入功能\n" + 43 | "\n" + 44 | "本次 OS X 10.11.4 中,备忘录增加了密码保护功能。用户能够在备忘录中设置密码来保护内部信息。同时,它也增加了按照字母、创建日期、修改日期等条件排序更能,用户寻找起来会更加方便。", Article.STYLE_FULL)); 45 | fake.add(new Article("http://t.cn/RGk1K6n", "有人说,苹果新品会叫 iPad mini Pro Plus | 一周范评\n" + 46 | "\n" + 47 | "一周评论精华汇总,不看真的会后悔。", Article.STYLE_BRIEF)); 48 | fake.add(new Article("http://t.cn/RGk19JQ", "无人机“差点”撞上大飞机,这些人是怎么做到的\n" + 49 | "\n" + 50 | "“聪明”的人们总会通过各种方式让自己爽,但是等待着他们的或许是法律的制裁", Article.STYLE_BRIEF)); 51 | fake.add(new Article("http://t.cn/RGk1mA3", "口袋妖怪 Go》由 The Pokémon Company, 任天堂以及 Niantic 联手推出,是一款基于 GPS 的增强现实游戏,去年披露后就被寄予厚望。它将于 2016 年内登陆 iOS 和 Android 端,可免费下载,但有应用内购买项目。\n" + 52 | "\n" + 53 | "目前,测试玩家限定于日本用户,因此注册需要使用具有日本 IP 的 VPN。注册网址是:http://beta-access.com/pokemongobeta/。", Article.STYLE_FULL)); 54 | fake.add(new Article("http://t.cn/RGk1NJl", "机器人要来抢你的饭碗了?赶紧穿上这套装备击退它们\n" + 55 | "\n" + 56 | "但是,人类未必要和机器人站在水火不容的对立面上,两者相辅相成或者还会形成一种新的生产效果。", Article.STYLE_BRIEF)); 57 | fake.add(new Article("http://t.cn/RGk1pLk", "我一周戴三个表,告诉你 Apple Watch 和专业运动手表有什么区别\n" + 58 | "\n" + 59 | "春天到了,是时候为身上的赘肉担忧了。", Article.STYLE_BRIEF)); 60 | fake.add(new Article("http://t.cn/RGk13Yw", "F.lux 是一款多平台、免费的软件,特点在于到了晚上,它会自动帮你调整电脑屏幕的颜色,减少屏幕对眼睛的刺激,帮助人改善睡眠质量。\n" + 61 | "\n" + 62 | "一直以来,F.lux 寻求它的 iOS app 可以正常地在 App Store 上架的机会。实际上,如果去搜索社交网络,也会看到大量用户呼吁 F.lux 可以尽快发布 iOS 版本。\n" + 63 | "\n" + 64 | "的确让人感到奇怪,iOS 都已经发布那么久了,以 F.lux 团队的技术实力,拖再久,iOS 版的 app 至少也该有眉目了吧。\n" + 65 | "\n" + 66 | "在 2015 年 11 月,F.lux 最终利用苹果的开发工具 Xcode 的一个 API 接口,实现发布 iOS 版本的目标。然而,和其它的软件不一样的是,团队要求客户下载 Xcode 才可以安装试用版。\n" + 67 | "\n" + 68 | "得被逼到什么程度,开发者才会用非正常地方式,来邀请用户试用自己的产品?\n" + 69 | "\n" + 70 | "但更让人难以想象的是,苹果是会如此地“关照”F.lux——第二天,苹果强制 F.lux 下架,理由是公司非法利用了 Xcode 的接口。", Article.STYLE_FULL)); 71 | fake.add(new Article("http://t.cn/RGk104s", "这款 2048 里,你的任务是盖起一座城市 - City 2048 #iOS #Android\n" + 72 | "\n" + 73 | "它在原本 2048 的基础上加入了很多新的游戏元素,你化身成为一个市长,任务则是建立越来越多的住房和越来越高的高楼。", Article.STYLE_BRIEF)); 74 | fake.add(new Article("http://t.cn/RGk1r45", "爱范儿在 3 月 14 日报道过,小米将会联合骑记 iRiding 推出一款公路自行车 QiCYCLE。今天,这款公路自行车正式在小米公司官方微博、骑记 iRiding 官方微博中亮相,同时也公布了它的具体配置和价格。", Article.STYLE_FULL)); 75 | return fake; 76 | } 77 | } 78 | 79 | class ArticleAdapter extends MultiTypeAdapter
{ 80 | 81 | public ArticleAdapter(Context context) { 82 | super(context); 83 | } 84 | 85 | @Override 86 | protected void registerViewTypes() { 87 | registerViewType(ArticleBriefViewType.class); 88 | registerViewType(ArticleFullViewType.class); 89 | } 90 | 91 | @Override 92 | protected Class getViewType(int position, Article data) { 93 | switch (data.getStyle()) { 94 | case Article.STYLE_FULL: 95 | return ArticleFullViewType.class; 96 | case Article.STYLE_BRIEF: 97 | return ArticleBriefViewType.class; 98 | } 99 | return null; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/SingleTypeListActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import com.github.mzule.easyadapter.ViewType; 10 | import com.github.mzule.easyadapter.recycler.SingleTypeAdapter; 11 | import com.github.mzule.easyadapter.sample.viewtypes.TipViewType; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.UUID; 16 | 17 | /** 18 | * Created by CaoDongping on 3/17/16. 19 | */ 20 | public class SingleTypeListActivity extends Activity { 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_single_type_list); 25 | 26 | PlainAdapter adapter = new PlainAdapter(this); 27 | 28 | RecyclerView listView = (RecyclerView) findViewById(R.id.listView); 29 | listView.setLayoutManager(new LinearLayoutManager(this)); 30 | listView.setAdapter(adapter); 31 | 32 | List fake = new ArrayList<>(); 33 | for (int i = 0; i < 100; i++) { 34 | fake.add(UUID.randomUUID().toString()); 35 | } 36 | adapter.addAndNotify(fake); 37 | } 38 | } 39 | 40 | class PlainAdapter extends SingleTypeAdapter { 41 | 42 | public PlainAdapter(Context context) { 43 | super(context); 44 | } 45 | 46 | @Override 47 | protected Class singleViewType() { 48 | return TipViewType.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/TypePerEntityListActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import com.github.mzule.easyadapter.recycler.TypePerEntityAdapter; 10 | import com.github.mzule.easyadapter.sample.po.Ad; 11 | import com.github.mzule.easyadapter.sample.po.Post; 12 | import com.github.mzule.easyadapter.sample.po.Recommend; 13 | import com.github.mzule.easyadapter.sample.po.Repost; 14 | import com.github.mzule.easyadapter.sample.viewtypes.AdViewType; 15 | import com.github.mzule.easyadapter.sample.viewtypes.PostViewType; 16 | import com.github.mzule.easyadapter.sample.viewtypes.RecommendViewType; 17 | import com.github.mzule.easyadapter.sample.viewtypes.RepostViewType; 18 | import com.github.mzule.easyadapter.sample.viewtypes.TipViewType; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by CaoDongping on 3/17/16. 26 | */ 27 | public class TypePerEntityListActivity extends Activity { 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_type_per_entity_list); 33 | 34 | RecyclerView listView = (RecyclerView) findViewById(R.id.listView); 35 | listView.setLayoutManager(new LinearLayoutManager(this)); 36 | 37 | TimelineAdapter adapter = new TimelineAdapter(this); 38 | listView.setAdapter(adapter); 39 | 40 | adapter.addAndNotify(makeFakeData()); 41 | } 42 | 43 | private List makeFakeData() { 44 | List data = new ArrayList<>(); 45 | data.add(new Post("不狂能叫小青年@", "http://t.cn/RGKNTpx", "今天做了一个新项目,感觉真好。")); 46 | data.add(new Post("对你的依赖早已成(习惯", "http://t.cn/RGru8qh", "四月霸权番(雾)《甲铁城的卡巴内瑞》最新预告公布!讲述在虚构的岛国“日之本”,少年少女和僵尸作战谋生的故事。这真的不是【战国+蒸汽朋克】版的巨人吗")); 47 | data.add(new Post("奈何桥上吻别", "http://t.cn/RG6bKdx", "来上海出差,出于好奇租了个BYD的秦玩玩,结果到酒店发现,根本没法充电,不过也好,正好感觉一下他的混动系统的工作效率~")); 48 | data.add(new Post("脸皮厚", "http://t.cn/RGruRtE", "【微软“三屏一云”战略下的Xbox野心】微软依然在推行“三屏一云”的构想,但似乎仍有许多用户不理解,认为微软正在“搬起石头砸自己的脚”,用PC抢占了Xbox的地盘。其实微软根本没有让PC占据Xbox一丝一毫的领地,并且在Xbox擅长的领域,微软正准备利用这台主机实现更大的野心。")); 49 | data.add(new Post("狐媚", "http://t.cn/RGruEjF", "路人女主的养成方法第二季2017年4月开始播送,圣人惠正宫不可避!")); 50 | data.add(new Repost("正如其美", "http://t.cn/RGr3b0j", "23333333", (Post) data.get(1))); 51 | data.add(new Post("籹", "http://t.cn/RGruEFf", "之前周博讲12月机器学习班第10次课")); 52 | data.add(new Post("星辰", "http://t.cn/RGruntl", "第一个是真的!!第一个!!认准第一个!有认证的那个是山寨的……")); 53 | data.add(new Post("要疯", "http://t.cn/RGrumcS", "厉害 这都能找到原因 ")); 54 | data.add(new Repost("快到钱里来", "http://t.cn/RGr3cLy", "送你100个赞", (Post) data.get(3))); 55 | data.add(new Post("赏你", "http://t.cn/RGrumus", "除了下面所述的3.20第20期卷积神经网络之外,3.19第19期:程博士分享矩阵基础 →")); 56 | data.add(new Post("五指山", "http://t.cn/RGruufV", "本周日上午10点公开课第20期:卷积神经网络。想听加Q群:151888952")); 57 | data.add(new Post("﹌夏落", "http://t.cn/RGruuE5", "看起来是很体面的道歉,而截图是你删掉原博客。伪君子地,我希望你的公司将来会成功。坦诚地,对于你之前的暴行,我心里由衷希望你的公司走不远。公司名字是:Artand。大家敬而远之吧。")); 58 | data.add(new Repost("正如其美", "http://t.cn/RGr3b0j", "23333333", (Post) data.get(1))); 59 | data.add(new Post("卧龙", "http://t.cn/RGru3mj", "「399 美元的售价,是目前已公布售价的 VR 设备里最便宜的,相对 Oculus 的 599 刀和 HTC vive 的 799 刀,索尼的定价可谓业界良心,")); 60 | data.add(new Post("拿命宠自己", "http://t.cn/RGru1b8", "前一个微博是欢乐一下。其实,我们是多才多艺的。第二张是第一张的临摹。")); 61 | data.add(new Post("︶ㄣ撕吢", "http://t.cn/RGru1Q4", "前两天BAT中某一家电面题")); 62 | data.add(new Repost("正如其美", "http://t.cn/RGr3b0j", "23333333", (Post) data.get(1))); 63 | data.add(new Post("不伦不类", "http://t.cn/RGruBG4", "近日,朝鲜最高法院以阴谋颠覆国家罪,判处美国大学生瓦姆比尔15年劳动教养,不得上诉。据悉,瓦姆比尔于今年元旦参团来平壤旅游,在平壤羊角岛饭店住宿期间,将一幅标语布擅自撤下扔在地上,从而犯下阴谋颠覆国家罪。该犯在听到宣判后当庭大哭,精神接近崩溃。")); 64 | data.add(new Repost("正如其美", "http://t.cn/RGr3b0j", "23333333", (Post) data.get(1))); 65 | data.add(new Post("硬汉", "http://t.cn/RGruBTV", "崩下卡拉卡,明晚看小李子的荒野猎人")); 66 | data.add(new Post("GO awy", "http://t.cn/RGrurZi", "今天群里斗图了…")); 67 | data.add(new Post("o後", "http://t.cn/RGrurC1", "【美国 1929 年经济危机的根本原因是什么?】Kshir Sagar:大萧条的基本原因是信贷紧缩(credit tightening),也就是去杠杆(deleverage)。杠杆是万恶之源,贷款的扩张不可能是永恒的,因为世上的信用是有限的")); 68 | data.add(new Repost("正如其美", "http://t.cn/RGr3b0j", "23333333", (Post) data.get(1))); 69 | data.add(new Post("莪永遠", "http://t.cn/RGrureb", "我居然被《萝卜报告》的共重号给调戏了…")); 70 | data.add(new Post("冲动°", "http://t.cn/RGrud0J", "现在的漫画,主角名字都好明显啊")); 71 | Collections.reverse(data); 72 | data.add(2, new Ad("http://t.cn/RGre4fv")); 73 | data.add(6, new Ad("http://t.cn/RGreaLK")); 74 | data.add(4, new Recommend(new Recommend.User[]{ 75 | new Recommend.User("胡歌", "http://t.cn/RGrkHos"), 76 | new Recommend.User("王自如", "http://t.cn/RGrkQHN"), 77 | new Recommend.User("陈凯歌", "http://t.cn/RGrk83D"), 78 | new Recommend.User("胡军", "http://t.cn/RGrkRRf"), 79 | new Recommend.User("孙凯", "http://t.cn/RGrkEX7") 80 | })); 81 | data.add(12, "上次看到这里"); 82 | return data; 83 | } 84 | } 85 | 86 | class TimelineAdapter extends TypePerEntityAdapter { 87 | 88 | public TimelineAdapter(Context context) { 89 | super(context); 90 | } 91 | 92 | @Override 93 | protected void mapEntityViewTypes() { 94 | mapEntityViewType(Post.class, PostViewType.class); 95 | mapEntityViewType(Repost.class, RepostViewType.class); 96 | mapEntityViewType(String.class, TipViewType.class); 97 | mapEntityViewType(Recommend.class, RecommendViewType.class); 98 | mapEntityViewType(Ad.class, AdViewType.class); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/po/Ad.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.po; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by CaoDongping on 3/17/16. 7 | */ 8 | public class Ad implements Serializable { 9 | private String imageUrl; 10 | 11 | public Ad(String imageUrl) { 12 | this.imageUrl = imageUrl; 13 | } 14 | 15 | public String getImageUrl() { 16 | return imageUrl; 17 | } 18 | 19 | public void setImageUrl(String imageUrl) { 20 | this.imageUrl = imageUrl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/po/Article.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.po; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by CaoDongping on 3/22/16. 7 | */ 8 | public class Article implements Serializable { 9 | public static final int STYLE_BRIEF = 1; 10 | public static final int STYLE_FULL = 2; 11 | private String imageUrl; 12 | private String text; 13 | private int style; 14 | 15 | public Article(String imageUrl, String text, int style) { 16 | this.imageUrl = imageUrl; 17 | this.text = text; 18 | this.style = style; 19 | } 20 | 21 | public String getImageUrl() { 22 | return imageUrl; 23 | } 24 | 25 | public void setImageUrl(String imageUrl) { 26 | this.imageUrl = imageUrl; 27 | } 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public int getStyle() { 38 | return style; 39 | } 40 | 41 | public void setStyle(int style) { 42 | this.style = style; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/po/Post.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.po; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by CaoDongping on 3/17/16. 7 | */ 8 | public class Post implements Serializable { 9 | private String name; 10 | private String avatar; 11 | private String content; 12 | 13 | public Post(String name, String avatar, String content) { 14 | this.name = name; 15 | this.avatar = avatar; 16 | this.content = content; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getAvatar() { 28 | return avatar; 29 | } 30 | 31 | public void setAvatar(String avatar) { 32 | this.avatar = avatar; 33 | } 34 | 35 | public String getContent() { 36 | return content; 37 | } 38 | 39 | public void setContent(String content) { 40 | this.content = content; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/po/Recommend.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.po; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by CaoDongping on 3/17/16. 7 | */ 8 | public class Recommend implements Serializable { 9 | private User[] users; 10 | 11 | public Recommend(User[] users) { 12 | this.users = users; 13 | } 14 | 15 | public User[] getUsers() { 16 | return users; 17 | } 18 | 19 | public void setUsers(User[] users) { 20 | this.users = users; 21 | } 22 | 23 | public static class User { 24 | private String name; 25 | private String avatar; 26 | 27 | public User(String name, String avatar) { 28 | this.name = name; 29 | this.avatar = avatar; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getAvatar() { 41 | return avatar; 42 | } 43 | 44 | public void setAvatar(String avatar) { 45 | this.avatar = avatar; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/po/Repost.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.po; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by CaoDongping on 3/17/16. 7 | */ 8 | public class Repost implements Serializable { 9 | 10 | private String name; 11 | private String avatar; 12 | private String content; 13 | private Post post; 14 | 15 | public Repost(String name, String avatar, String content, Post post) { 16 | this.name = name; 17 | this.avatar = avatar; 18 | this.content = content; 19 | this.post = post; 20 | } 21 | 22 | public String getAvatar() { 23 | return avatar; 24 | } 25 | 26 | public void setAvatar(String avatar) { 27 | this.avatar = avatar; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getContent() { 39 | return content; 40 | } 41 | 42 | public void setContent(String content) { 43 | this.content = content; 44 | } 45 | 46 | public Post getPost() { 47 | return post; 48 | } 49 | 50 | public void setPost(Post post) { 51 | this.post = post; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/AdViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.ImageView; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.github.mzule.easyadapter.ViewType; 7 | import com.github.mzule.easyadapter.sample.R; 8 | import com.github.mzule.easyadapter.sample.po.Ad; 9 | 10 | /** 11 | * Created by CaoDongping on 3/18/16. 12 | */ 13 | public class AdViewType extends ViewType { 14 | private ImageView adView; 15 | 16 | @Override 17 | public void onCreate() { 18 | setContentView(R.layout.item_ad); 19 | this.adView = findViewById(R.id.adView); 20 | } 21 | 22 | @Override 23 | public void onRender(int position, Ad ad) { 24 | Glide.with(getContext()).load(ad.getImageUrl()).centerCrop().into(adView); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/ArticleBriefViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.ImageView; 4 | import android.widget.TextView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.github.mzule.easyadapter.ViewType; 8 | import com.github.mzule.easyadapter.sample.R; 9 | import com.github.mzule.easyadapter.sample.po.Article; 10 | 11 | /** 12 | * Created by CaoDongping on 3/22/16. 13 | */ 14 | public class ArticleBriefViewType extends ViewType
{ 15 | protected ImageView imageView; 16 | protected TextView textView; 17 | 18 | @Override 19 | public void onCreate() { 20 | setContentView(R.layout.item_article_brief); 21 | this.imageView = findViewById(R.id.imageView); 22 | this.textView = findViewById(R.id.textView); 23 | } 24 | 25 | @Override 26 | public void onRender(int position, Article data) { 27 | Glide.with(getContext()).load(data.getImageUrl()).centerCrop().placeholder(R.color.gray).into(imageView); 28 | textView.setText(data.getText()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/ArticleFullViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.ImageView; 4 | import android.widget.TextView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.github.mzule.easyadapter.ViewType; 8 | import com.github.mzule.easyadapter.sample.R; 9 | import com.github.mzule.easyadapter.sample.po.Article; 10 | 11 | /** 12 | * Created by CaoDongping on 3/22/16. 13 | */ 14 | public class ArticleFullViewType extends ViewType
{ 15 | protected ImageView imageView; 16 | protected TextView textView; 17 | 18 | @Override 19 | public void onCreate() { 20 | setContentView(R.layout.item_article_full); 21 | this.imageView = findViewById(R.id.imageView); 22 | this.textView = findViewById(R.id.textView); 23 | } 24 | 25 | @Override 26 | public void onRender(int position, Article data) { 27 | Glide.with(getContext()).load(data.getImageUrl()).centerCrop().placeholder(R.color.gray).into(imageView); 28 | textView.setText(data.getText()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/PostViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.ImageView; 4 | import android.widget.TextView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.github.mzule.easyadapter.ViewType; 8 | import com.github.mzule.easyadapter.sample.R; 9 | import com.github.mzule.easyadapter.sample.po.Post; 10 | 11 | /** 12 | * Created by CaoDongping on 3/18/16. 13 | */ 14 | public class PostViewType extends ViewType { 15 | private TextView nameView; 16 | private TextView contentView; 17 | private ImageView avatarView; 18 | 19 | @Override 20 | public void onCreate() { 21 | setContentView(R.layout.item_post); 22 | nameView = findViewById(R.id.nameView); 23 | contentView = findViewById(R.id.contentView); 24 | avatarView = findViewById(R.id.avatarView); 25 | } 26 | 27 | @Override 28 | public void onRender(int position, Post post) { 29 | nameView.setText(post.getName()); 30 | contentView.setText(post.getContent()); 31 | Glide.with(getContext()).load(post.getAvatar()).centerCrop().placeholder(R.drawable.placeholder).into(avatarView); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/RecommendViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.view.ViewGroup; 4 | import android.widget.ImageView; 5 | import android.widget.TextView; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.github.mzule.easyadapter.ViewType; 9 | import com.github.mzule.easyadapter.sample.R; 10 | import com.github.mzule.easyadapter.sample.po.Recommend; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by CaoDongping on 3/18/16. 17 | */ 18 | public class RecommendViewType extends ViewType { 19 | private List imageViews; 20 | private List textViews; 21 | 22 | @Override 23 | public void onCreate() { 24 | setContentView(R.layout.item_recommend); 25 | 26 | imageViews = new ArrayList<>(); 27 | textViews = new ArrayList<>(); 28 | 29 | ViewGroup imageContainer = findViewById(R.id.imageContainer); 30 | for (int i = 0; i < imageContainer.getChildCount(); i++) { 31 | if (imageContainer.getChildAt(i) instanceof ImageView) { 32 | imageViews.add((ImageView) imageContainer.getChildAt(i)); 33 | } 34 | } 35 | 36 | ViewGroup nameContainer = findViewById(R.id.nameContainer); 37 | for (int i = 0; i < nameContainer.getChildCount(); i++) { 38 | if (nameContainer.getChildAt(i) instanceof TextView) { 39 | textViews.add((TextView) nameContainer.getChildAt(i)); 40 | } 41 | } 42 | } 43 | 44 | @Override 45 | public void onRender(int position, Recommend recommend) { 46 | for (int i = 0; i < recommend.getUsers().length; i++) { 47 | Glide.with(getContext()).load(recommend.getUsers()[i].getAvatar()).centerCrop().placeholder(R.drawable.placeholder).into(imageViews.get(i)); 48 | textViews.get(i).setText(recommend.getUsers()[i].getName()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/RepostViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.ImageView; 4 | import android.widget.TextView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.github.mzule.easyadapter.ViewType; 8 | import com.github.mzule.easyadapter.sample.R; 9 | import com.github.mzule.easyadapter.sample.po.Repost; 10 | 11 | /** 12 | * Created by CaoDongping on 3/18/16. 13 | */ 14 | public class RepostViewType extends ViewType { 15 | private TextView nameView; 16 | private TextView contentView; 17 | private ImageView avatarView; 18 | private TextView quoteView; 19 | 20 | @Override 21 | public void onCreate() { 22 | setContentView(R.layout.item_repost); 23 | this.nameView = findViewById(R.id.nameView); 24 | this.contentView = findViewById(R.id.contentView); 25 | this.avatarView = findViewById(R.id.avatarView); 26 | this.quoteView = findViewById(R.id.quoteView); 27 | } 28 | 29 | @Override 30 | public void onRender(int position, Repost repost) { 31 | nameView.setText(repost.getName()); 32 | contentView.setText(repost.getContent()); 33 | quoteView.setText(String.format("%s: %s", repost.getPost().getName(), repost.getPost().getContent())); 34 | Glide.with(getContext()).load(repost.getAvatar()).centerCrop().placeholder(R.drawable.placeholder).into(avatarView); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/mzule/easyadapter/sample/viewtypes/TipViewType.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter.sample.viewtypes; 2 | 3 | import android.widget.TextView; 4 | 5 | import com.github.mzule.easyadapter.ViewType; 6 | import com.github.mzule.easyadapter.sample.R; 7 | 8 | /** 9 | * Created by CaoDongping on 3/18/16. 10 | */ 11 | public class TipViewType extends ViewType { 12 | private TextView tipView; 13 | 14 | @Override 15 | public void onCreate() { 16 | setContentView(R.layout.item_tip); 17 | this.tipView = findViewById(R.id.tip); 18 | } 19 | 20 | @Override 21 | public void onRender(int position, String tip) { 22 | tipView.setText(tip); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/drawable-xxhdpi/placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 25 | 26 | 36 | 37 | 47 | 48 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_multi_type_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_single_type_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_type_per_entity_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_ad.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_article_brief.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_article_full.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_post.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 21 | 22 | 29 | 30 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_recommend.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | 25 | 26 | 29 | 30 | 34 | 35 | 38 | 39 | 43 | 44 | 45 | 48 | 49 | 53 | 54 | 55 | 58 | 59 | 63 | 64 | 65 | 68 | 69 | 73 | 74 | 75 | 76 | 83 | 84 | 88 | 89 | 93 | 94 | 98 | 99 | 103 | 104 | 108 | 109 | 110 | 114 | 115 | 119 | 120 | 121 | 125 | 126 | 130 | 131 | 132 | 136 | 137 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_repost.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 21 | 22 | 29 | 30 | 39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_tip.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 26 | 27 | 33 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzule/EasyAdapter/3b4012624b623c7e3cec6326f6a3a676e4d2cf1d/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #EEEEEE 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EasyAdapter 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/test/java/com/github/mzule/easyadapter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mzule.easyadapter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':easyadapter', ':easyadapterrecycler' 2 | --------------------------------------------------------------------------------