├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wangjie │ │ └── seizerecyclerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wangjie │ │ │ └── seizerecyclerview │ │ │ └── example │ │ │ ├── MainActivity.java │ │ │ ├── basic │ │ │ ├── BasicActivity.java │ │ │ └── adapter │ │ │ │ ├── FeedAdapter.java │ │ │ │ ├── actor │ │ │ │ ├── FilmActorSeizeAdapter.java │ │ │ │ └── FilmActorSeizeViewHolder.java │ │ │ │ └── comment │ │ │ │ ├── FilmCommentSeizeAdapter.java │ │ │ │ └── FilmCommentSeizeViewHolder.java │ │ │ ├── multitype │ │ │ ├── MultiTypeActivity.java │ │ │ ├── adapter │ │ │ │ ├── actor │ │ │ │ │ ├── a │ │ │ │ │ │ ├── FilmActorAViewHolder.java │ │ │ │ │ │ └── FilmActorAViewHolderOwner.java │ │ │ │ │ └── b │ │ │ │ │ │ ├── FilmActorBViewHolder.java │ │ │ │ │ │ └── FilmActorBViewHolderOwner.java │ │ │ │ └── comment │ │ │ │ │ ├── a │ │ │ │ │ ├── FilmCommentAViewHolder.java │ │ │ │ │ └── FilmCommentAViewHolderOwner.java │ │ │ │ │ └── b │ │ │ │ │ ├── FilmCommentBViewHolder.java │ │ │ │ │ └── FilmCommentBViewHolderOwner.java │ │ │ └── vm │ │ │ │ ├── actor │ │ │ │ ├── ActorAVM.java │ │ │ │ └── ActorBVM.java │ │ │ │ └── comment │ │ │ │ ├── CommentAVM.java │ │ │ │ └── CommentBVM.java │ │ │ └── vm │ │ │ ├── VM.java │ │ │ ├── actor │ │ │ └── ActorVM.java │ │ │ └── comment │ │ │ └── CommentVM.java │ └── res │ │ ├── layout │ │ ├── activity_basic.xml │ │ ├── activity_main.xml │ │ ├── activity_multi_type.xml │ │ ├── footer_film.xml │ │ ├── footer_film_actor.xml │ │ ├── footer_film_comment.xml │ │ ├── header_film.xml │ │ ├── header_film_actor.xml │ │ ├── header_film_comment.xml │ │ ├── item_film_actor.xml │ │ └── item_film_comment.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── wangjie │ └── seizerecyclerview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── nexus_aar_center.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wangjie │ │ └── seizerecyclerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wangjie │ │ │ └── seizerecyclerview │ │ │ ├── BaseRecyclerAdapter.java │ │ │ ├── BaseSeizeAdapter.java │ │ │ ├── BaseViewHolder.java │ │ │ ├── EmptyViewHolder.java │ │ │ ├── SeizeAdapter.java │ │ │ ├── SeizePosition.java │ │ │ └── attacher │ │ │ ├── Func1R.java │ │ │ ├── MultiSeizeAdapter.java │ │ │ └── ViewHolderOwner.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── wangjie │ └── seizerecyclerview │ └── ExampleUnitTest.java ├── screenshot ├── basic.gif └── multi_type.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | gradle.properties 42 | nexus_aar_db.gradle -------------------------------------------------------------------------------- /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 | # SeizeRecyclerView 2 | 3 | ### Use multiple adapters for a single RecyclerView. 4 | 5 | 6 | 7 | ## How to use 8 | 9 | ```java 10 | feedRv = (RecyclerView) findViewById(R.id.activity_main_rv); 11 | 12 | // The whole origin adapter of RecyclerView 13 | adapter = new FeedAdapter(); 14 | // set header and footer for the whole origin adapter of RecyclerView 15 | adapter.setHeader(headerView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film)); 16 | adapter.setFooter(footerView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film)); 17 | 18 | // attach seize adapters to origin adapter of RecyclerView 19 | adapter.setSeizeAdapters( 20 | filmActorSeizeAdapter = new FilmActorSeizeAdapter(), 21 | filmCommentSeizeAdapter = new FilmCommentSeizeAdapter() 22 | ); 23 | 24 | // set header and footer for the film actor seize adapter 25 | filmActorSeizeAdapter.setOnFilmActorSeizeAdapterListener(this); 26 | filmActorSeizeAdapter.setHeader(actorHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_actor)); 27 | filmActorSeizeAdapter.setFooter(actorFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_actor)); 28 | 29 | // set header and footer for the film comment seize adapter 30 | filmCommentSeizeAdapter.setOnFilmCommentSeizeAdapterListener(this); 31 | filmCommentSeizeAdapter.setHeader(commentHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_comment)); 32 | filmCommentSeizeAdapter.setFooter(commentFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_comment)); 33 | 34 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 35 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 36 | feedRv.setLayoutManager(layoutManager); 37 | 38 | // set origin adapter to RecyclerView 39 | feedRv.setAdapter(adapter); 40 | ``` 41 | 42 | ```java 43 | public void onRequestActors(List list) { 44 | filmActorSeizeAdapter.addList(list); 45 | filmActorSeizeAdapter.notifyDataSetChanged(); 46 | } 47 | 48 | public void onRequestComment(List list) { 49 | filmCommentSeizeAdapter.addList(list); 50 | filmCommentSeizeAdapter.notifyDataSetChanged(); 51 | } 52 | ``` 53 | 54 | License 55 | ======= 56 | 57 | Copyright 2017 Wang Jie 58 | 59 | Licensed under the Apache License, Version 2.0 (the "License"); 60 | you may not use this file except in compliance with the License. 61 | You may obtain a copy of the License at 62 | 63 | http://www.apache.org/licenses/LICENSE-2.0 64 | 65 | Unless required by applicable law or agreed to in writing, software 66 | distributed under the License is distributed on an "AS IS" BASIS, 67 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 68 | See the License for the specific language governing blacklist and 69 | limitations under the License. 70 | 71 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "com.wangjie.seizerecyclerview.example" 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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 | androidTestCompile("com.android.support.test.espresso:espresso-core:$global_espressoVersion", { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile "com.android.support:appcompat-v7:$global_supportVersion" 28 | testCompile "junit:junit:$global_junitVersion" 29 | 30 | compile project(':library') 31 | } 32 | -------------------------------------------------------------------------------- /app/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/wangjie/work/java/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/wangjie/seizerecyclerview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.wangjie.seizerecyclerview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.wangjie.seizerecyclerview.example.basic.BasicActivity; 9 | import com.wangjie.seizerecyclerview.example.multitype.MultiTypeActivity; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | } 18 | 19 | public void toBasicMode(View view) { 20 | startActivity(new Intent(this, BasicActivity.class)); 21 | } 22 | 23 | public void toMultiTypeMode(View view) { 24 | startActivity(new Intent(this, MultiTypeActivity.class)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/BasicActivity.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Toast; 11 | 12 | import com.wangjie.seizerecyclerview.SeizePosition; 13 | import com.wangjie.seizerecyclerview.example.R; 14 | import com.wangjie.seizerecyclerview.example.basic.adapter.FeedAdapter; 15 | import com.wangjie.seizerecyclerview.example.basic.adapter.actor.FilmActorSeizeAdapter; 16 | import com.wangjie.seizerecyclerview.example.basic.adapter.comment.FilmCommentSeizeAdapter; 17 | import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM; 18 | import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * Author: wangjie 25 | * Email: tiantian.china.2@gmail.com 26 | * Date: 3/29/17. 27 | */ 28 | public class BasicActivity extends AppCompatActivity implements 29 | FilmActorSeizeAdapter.OnFilmActorSeizeAdapterListener, 30 | FilmCommentSeizeAdapter.OnFilmCommentSeizeAdapterListener, 31 | View.OnClickListener { 32 | 33 | private FeedAdapter adapter; 34 | private RecyclerView feedRv; 35 | private FilmActorSeizeAdapter filmActorSeizeAdapter; 36 | private FilmCommentSeizeAdapter filmCommentSeizeAdapter; 37 | private Toast toast; 38 | 39 | private View headerView; 40 | private View footerView; 41 | private View actorHeaderView; 42 | private View actorFooterView; 43 | private View commentHeaderView; 44 | private View commentFooterView; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.activity_basic); 50 | feedRv = (RecyclerView) findViewById(R.id.activity_basic_rv); 51 | 52 | // The whole origin adapter of RecyclerView 53 | adapter = new FeedAdapter(); 54 | // set header and footer for the whole origin adapter of RecyclerView 55 | adapter.setHeader(headerView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film)); 56 | adapter.setFooter(footerView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film)); 57 | 58 | // attach seize adapters to origin adapter of RecyclerView 59 | adapter.setSeizeAdapters( 60 | filmActorSeizeAdapter = new FilmActorSeizeAdapter(), 61 | filmCommentSeizeAdapter = new FilmCommentSeizeAdapter() 62 | ); 63 | 64 | // set header and footer for the film actor seize adapter 65 | filmActorSeizeAdapter.setOnFilmActorSeizeAdapterListener(this); 66 | filmActorSeizeAdapter.setHeader(actorHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_actor)); 67 | filmActorSeizeAdapter.setFooter(actorFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_actor)); 68 | 69 | // set header and footer for the film comment seize adapter 70 | filmCommentSeizeAdapter.setOnFilmCommentSeizeAdapterListener(this); 71 | filmCommentSeizeAdapter.setHeader(commentHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_comment)); 72 | filmCommentSeizeAdapter.setFooter(commentFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_comment)); 73 | 74 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 75 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 76 | feedRv.setLayoutManager(layoutManager); 77 | 78 | // set origin adapter to RecyclerView 79 | feedRv.setAdapter(adapter); 80 | 81 | initOtherComponents(); 82 | } 83 | 84 | public void addActors(View view) { 85 | List list = new ArrayList<>(); 86 | for (int i = 0; i < 2; i++) { 87 | long now = System.currentTimeMillis(); 88 | ActorVM actorVM = new ActorVM("actor_" + now); 89 | list.add(actorVM); 90 | } 91 | filmActorSeizeAdapter.addList(list); 92 | filmActorSeizeAdapter.notifyDataSetChanged(); 93 | } 94 | 95 | public void addComments(View view) { 96 | List list = new ArrayList<>(); 97 | for (int i = 0; i < 3; i++) { 98 | long now = System.currentTimeMillis(); 99 | CommentVM commentVM = new CommentVM("comment_" + now); 100 | list.add(commentVM); 101 | } 102 | filmCommentSeizeAdapter.addList(list); 103 | filmCommentSeizeAdapter.notifyDataSetChanged(); 104 | } 105 | 106 | @Override 107 | public void onFilmActorItemClick(ActorVM actorVM, SeizePosition seizePosition) { 108 | toast.setText(seizePosition.toString()); 109 | toast.show(); 110 | } 111 | 112 | @Override 113 | public void onFilmCommentItemClick(CommentVM commentVM, SeizePosition seizePosition) { 114 | toast.setText(seizePosition.toString()); 115 | toast.show(); 116 | } 117 | 118 | @Override 119 | public void onClick(View v) { 120 | if (v == headerView) { 121 | toast.setText("header clicked"); 122 | toast.show(); 123 | } else if (v == footerView) { 124 | toast.setText("footer clicked"); 125 | toast.show(); 126 | } else if (v == actorHeaderView) { 127 | toast.setText("actor header clicked"); 128 | toast.show(); 129 | } else if (v == actorFooterView) { 130 | toast.setText("actor footer clicked"); 131 | toast.show(); 132 | } else if (v == commentHeaderView) { 133 | toast.setText("comment header clicked"); 134 | toast.show(); 135 | } else if (v == commentFooterView) { 136 | toast.setText("comment footer clicked"); 137 | toast.show(); 138 | } 139 | } 140 | 141 | private void initOtherComponents() { 142 | toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); 143 | toast.setDuration(Toast.LENGTH_SHORT); 144 | } 145 | 146 | private View inflaterHeaderOrFooterAndBindClick(int resId) { 147 | View view = LayoutInflater.from(this).inflate(resId, null, false); 148 | view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 149 | view.setOnClickListener(this); 150 | return view; 151 | } 152 | } -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/adapter/FeedAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic.adapter; 2 | 3 | import com.wangjie.seizerecyclerview.BaseRecyclerAdapter; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/28/17. 9 | */ 10 | public class FeedAdapter extends BaseRecyclerAdapter { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/adapter/actor/FilmActorSeizeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic.adapter.actor; 2 | 3 | import android.view.ViewGroup; 4 | 5 | import com.wangjie.seizerecyclerview.BaseViewHolder; 6 | import com.wangjie.seizerecyclerview.BaseSeizeAdapter; 7 | import com.wangjie.seizerecyclerview.SeizePosition; 8 | import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/28/17. 17 | */ 18 | public class FilmActorSeizeAdapter extends BaseSeizeAdapter { 19 | public interface OnFilmActorSeizeAdapterListener { 20 | void onFilmActorItemClick(ActorVM actorVM, SeizePosition seizePosition); 21 | } 22 | 23 | private OnFilmActorSeizeAdapterListener onFilmActorSeizeAdapterListener; 24 | 25 | public void setOnFilmActorSeizeAdapterListener(OnFilmActorSeizeAdapterListener onFilmActorSeizeAdapterListener) { 26 | this.onFilmActorSeizeAdapterListener = onFilmActorSeizeAdapterListener; 27 | } 28 | 29 | public OnFilmActorSeizeAdapterListener getOnFilmActorSeizeAdapterListener() { 30 | return onFilmActorSeizeAdapterListener; 31 | } 32 | 33 | private List list = new ArrayList<>(); 34 | 35 | public void setList(List list) { 36 | this.list = list; 37 | } 38 | 39 | public void addList(List list) { 40 | this.list.addAll(list); 41 | } 42 | 43 | public List getList() { 44 | return list; 45 | } 46 | 47 | @Override 48 | public int getSourceItemViewType(int subSourcePosition) { 49 | return list.get(subSourcePosition).getViewType(); 50 | } 51 | 52 | @Override 53 | public BaseViewHolder onCreateTypeViewHolder(ViewGroup parent, int viewType) { 54 | switch (viewType) { 55 | case ActorVM.TYPE_ACTOR: 56 | return new FilmActorSeizeViewHolder(this, parent); 57 | default: 58 | return null; 59 | } 60 | } 61 | 62 | @Override 63 | public Object getItem(int subSourcePosition) { 64 | return list.get(subSourcePosition); 65 | } 66 | 67 | @Override 68 | public int getSourceItemCount() { 69 | return list.size(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/adapter/actor/FilmActorSeizeViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic.adapter.actor; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.TextView; 7 | 8 | import com.wangjie.seizerecyclerview.BaseViewHolder; 9 | import com.wangjie.seizerecyclerview.SeizePosition; 10 | import com.wangjie.seizerecyclerview.example.R; 11 | 12 | /** 13 | * Author: wangjie 14 | * Email: tiantian.china.2@gmail.com 15 | * Date: 3/28/17. 16 | */ 17 | public class FilmActorSeizeViewHolder extends BaseViewHolder { 18 | TextView actorTv; 19 | private FilmActorSeizeAdapter seizeAdapter; 20 | 21 | public FilmActorSeizeViewHolder(final FilmActorSeizeAdapter seizeAdapter, ViewGroup parent) { 22 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_actor, parent, false)); 23 | this.seizeAdapter = seizeAdapter; 24 | 25 | actorTv = (TextView) itemView.findViewById(R.id.item_film_actor_tv); 26 | 27 | actorTv.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | seizeAdapter.getOnFilmActorSeizeAdapterListener().onFilmActorItemClick(seizeAdapter.getList().get(getSeizePosition().getSubSourcePosition()), getSeizePosition()); 31 | } 32 | }); 33 | 34 | } 35 | 36 | @Override 37 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 38 | int subSourcePosition = seizePosition.getSubSourcePosition(); 39 | int seizeAdapterIndex = seizePosition.getSeizeAdapterIndex(); 40 | actorTv.setText(seizeAdapterIndex + ", " + subSourcePosition + " / " + seizeAdapter.getList().get(subSourcePosition).getObj()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/adapter/comment/FilmCommentSeizeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic.adapter.comment; 2 | 3 | import android.view.ViewGroup; 4 | 5 | import com.wangjie.seizerecyclerview.BaseViewHolder; 6 | import com.wangjie.seizerecyclerview.BaseSeizeAdapter; 7 | import com.wangjie.seizerecyclerview.SeizePosition; 8 | import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/28/17. 17 | */ 18 | public class FilmCommentSeizeAdapter extends BaseSeizeAdapter { 19 | public interface OnFilmCommentSeizeAdapterListener { 20 | void onFilmCommentItemClick(CommentVM commentVM, SeizePosition seizePosition); 21 | } 22 | 23 | private OnFilmCommentSeizeAdapterListener onFilmCommentSeizeAdapterListener; 24 | 25 | public void setOnFilmCommentSeizeAdapterListener(OnFilmCommentSeizeAdapterListener onFilmCommentSeizeAdapterListener) { 26 | this.onFilmCommentSeizeAdapterListener = onFilmCommentSeizeAdapterListener; 27 | } 28 | 29 | public OnFilmCommentSeizeAdapterListener getOnFilmCommentSeizeAdapterListener() { 30 | return onFilmCommentSeizeAdapterListener; 31 | } 32 | 33 | private List list = new ArrayList<>(); 34 | 35 | public void setList(List list) { 36 | this.list = list; 37 | } 38 | 39 | public void addList(List list) { 40 | this.list.addAll(list); 41 | } 42 | 43 | public List getList() { 44 | return list; 45 | } 46 | 47 | @Override 48 | public int getSourceItemViewType(int subSourcePosition) { 49 | return list.get(subSourcePosition).getViewType(); 50 | } 51 | 52 | @Override 53 | public BaseViewHolder onCreateTypeViewHolder(ViewGroup parent, int viewType) { 54 | switch (viewType) { 55 | case CommentVM.TYPE_COMMENT: 56 | return new FilmCommentSeizeViewHolder(this, parent); 57 | default: 58 | return null; 59 | } 60 | } 61 | 62 | @Override 63 | public Object getItem(int subSourcePosition) { 64 | return list.get(subSourcePosition); 65 | } 66 | 67 | @Override 68 | public int getSourceItemCount() { 69 | return list.size(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/basic/adapter/comment/FilmCommentSeizeViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.basic.adapter.comment; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.TextView; 7 | 8 | import com.wangjie.seizerecyclerview.BaseViewHolder; 9 | import com.wangjie.seizerecyclerview.SeizePosition; 10 | import com.wangjie.seizerecyclerview.example.R; 11 | 12 | /** 13 | * Author: wangjie 14 | * Email: tiantian.china.2@gmail.com 15 | * Date: 3/28/17. 16 | */ 17 | public class FilmCommentSeizeViewHolder extends BaseViewHolder { 18 | private FilmCommentSeizeAdapter seizeAdapter; 19 | TextView commentTv; 20 | 21 | public FilmCommentSeizeViewHolder(final FilmCommentSeizeAdapter seizeAdapter, ViewGroup parent) { 22 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_comment, parent, false)); 23 | this.seizeAdapter = seizeAdapter; 24 | commentTv = (TextView) itemView.findViewById(R.id.item_film_comment_tv); 25 | 26 | commentTv.setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | seizeAdapter.getOnFilmCommentSeizeAdapterListener().onFilmCommentItemClick(seizeAdapter.getList().get(getSeizePosition().getSubSourcePosition()), getSeizePosition()); 30 | } 31 | }); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 36 | int subSourcePosition = seizePosition.getSubSourcePosition(); 37 | int seizeAdapterIndex = seizePosition.getSeizeAdapterIndex(); 38 | commentTv.setText(seizeAdapterIndex + ", " + subSourcePosition + " / " + seizeAdapter.getList().get(subSourcePosition).getObj()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/MultiTypeActivity.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import com.wangjie.seizerecyclerview.SeizeAdapter; 14 | import com.wangjie.seizerecyclerview.SeizePosition; 15 | import com.wangjie.seizerecyclerview.attacher.Func1R; 16 | import com.wangjie.seizerecyclerview.attacher.MultiSeizeAdapter; 17 | import com.wangjie.seizerecyclerview.example.R; 18 | import com.wangjie.seizerecyclerview.example.basic.adapter.FeedAdapter; 19 | import com.wangjie.seizerecyclerview.example.multitype.adapter.actor.a.FilmActorAViewHolderOwner; 20 | import com.wangjie.seizerecyclerview.example.multitype.adapter.actor.b.FilmActorBViewHolderOwner; 21 | import com.wangjie.seizerecyclerview.example.multitype.adapter.comment.a.FilmCommentAViewHolderOwner; 22 | import com.wangjie.seizerecyclerview.example.multitype.adapter.comment.b.FilmCommentBViewHolderOwner; 23 | import com.wangjie.seizerecyclerview.example.multitype.vm.actor.ActorAVM; 24 | import com.wangjie.seizerecyclerview.example.multitype.vm.actor.ActorBVM; 25 | import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM; 26 | import com.wangjie.seizerecyclerview.example.multitype.vm.comment.CommentAVM; 27 | import com.wangjie.seizerecyclerview.example.multitype.vm.comment.CommentBVM; 28 | import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | /** 34 | * Author: wangjie 35 | * Email: tiantian.china.2@gmail.com 36 | * Date: 3/29/17. 37 | */ 38 | public class MultiTypeActivity extends AppCompatActivity implements 39 | View.OnClickListener { 40 | 41 | private FeedAdapter adapter; 42 | private RecyclerView feedRv; 43 | private MultiSeizeAdapter filmActorSeizeAdapter; 44 | private MultiSeizeAdapter filmCommentSeizeAdapter; 45 | private Toast toast; 46 | 47 | private View headerView; 48 | private View footerView; 49 | private View actorHeaderView; 50 | private View actorFooterView; 51 | private View commentHeaderView; 52 | private View commentFooterView; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_multi_type); 58 | feedRv = (RecyclerView) findViewById(R.id.activity_multi_type_rv); 59 | 60 | // The whole origin adapter of RecyclerView 61 | adapter = new FeedAdapter(); 62 | // set header and footer for the whole origin adapter of RecyclerView 63 | adapter.setHeader(headerView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film)); 64 | adapter.setFooter(footerView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film)); 65 | 66 | // set header and footer for the film actor seize adapter 67 | filmActorSeizeAdapter = new MultiSeizeAdapter<>(); 68 | filmActorSeizeAdapter.setHeader(actorHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_actor)); 69 | filmActorSeizeAdapter.setFooter(actorFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_actor)); 70 | filmActorSeizeAdapter.setGetItemType(new Func1R() { 71 | @Override 72 | public Integer call(ActorVM actorVM) { 73 | return actorVM.getActorViewType(); 74 | } 75 | }); 76 | filmActorSeizeAdapter.addSupportViewHolder(ActorVM.TYPE_ACTOR_A, new FilmActorAViewHolderOwner(this)); 77 | filmActorSeizeAdapter.addSupportViewHolder(ActorVM.TYPE_ACTOR_B, new FilmActorBViewHolderOwner(this)); 78 | 79 | // set header and footer for the film comment seize adapter 80 | filmCommentSeizeAdapter = new MultiSeizeAdapter<>(); 81 | filmCommentSeizeAdapter.setHeader(commentHeaderView = inflaterHeaderOrFooterAndBindClick(R.layout.header_film_comment)); 82 | filmCommentSeizeAdapter.setFooter(commentFooterView = inflaterHeaderOrFooterAndBindClick(R.layout.footer_film_comment)); 83 | filmCommentSeizeAdapter.setGetItemType(new Func1R() { 84 | @Override 85 | public Integer call(CommentVM commentVM) { 86 | return commentVM.getCommentViewType(); 87 | } 88 | }); 89 | filmCommentSeizeAdapter.addSupportViewHolder(CommentVM.TYPE_COMMENT_A, new FilmCommentAViewHolderOwner(this)); 90 | filmCommentSeizeAdapter.addSupportViewHolder(CommentVM.TYPE_COMMENT_B, new FilmCommentBViewHolderOwner(this)); 91 | 92 | // attach seize adapters to origin adapter of RecyclerView 93 | adapter.setSeizeAdapters(filmActorSeizeAdapter, filmCommentSeizeAdapter); 94 | 95 | GridLayoutManager layoutManager = new GridLayoutManager(this, 2); 96 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 97 | layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 98 | @Override 99 | public int getSpanSize(int position) { 100 | SeizePosition seizePosition = adapter.convertSeizePosition(position); 101 | if (null != seizePosition) { 102 | SeizeAdapter ada = adapter.getSeizeAdapter(position); 103 | int subPosition = seizePosition.getSubPosition(); 104 | if (ada == filmCommentSeizeAdapter 105 | && !filmCommentSeizeAdapter.isHeader(subPosition) 106 | && !filmCommentSeizeAdapter.isFooter(subPosition) 107 | ) { 108 | return 1; 109 | } 110 | } 111 | return 2; 112 | } 113 | }); 114 | feedRv.setLayoutManager(layoutManager); 115 | 116 | // set origin adapter to RecyclerView 117 | feedRv.setAdapter(adapter); 118 | 119 | initOtherComponents(); 120 | } 121 | 122 | public void addActors(View view) { 123 | List list = new ArrayList<>(); 124 | for (int i = 0; i < 2; i++) { 125 | long now = System.currentTimeMillis(); 126 | ActorVM actorVM; 127 | if (i % 2 == 0) { 128 | actorVM = new ActorAVM("actor_" + now); 129 | } else { 130 | actorVM = new ActorBVM("actor_" + now); 131 | } 132 | list.add(actorVM); 133 | 134 | } 135 | filmActorSeizeAdapter.addList(list); 136 | filmActorSeizeAdapter.notifyDataSetChanged(); 137 | } 138 | 139 | public void addComments(View view) { 140 | List list = new ArrayList<>(); 141 | for (int i = 0; i < 3; i++) { 142 | long now = System.currentTimeMillis(); 143 | CommentVM commentVM; 144 | if (i % 2 == 0) { 145 | commentVM = new CommentAVM("comment_" + now); 146 | } else { 147 | commentVM = new CommentBVM("comment_" + now); 148 | } 149 | list.add(commentVM); 150 | } 151 | filmCommentSeizeAdapter.addList(list); 152 | filmCommentSeizeAdapter.notifyDataSetChanged(); 153 | } 154 | 155 | @Override 156 | public void onClick(View v) { 157 | if (v == headerView) { 158 | toast.setText("header clicked"); 159 | toast.show(); 160 | } else if (v == footerView) { 161 | toast.setText("footer clicked"); 162 | toast.show(); 163 | } else if (v == actorHeaderView) { 164 | toast.setText("actor header clicked"); 165 | toast.show(); 166 | } else if (v == actorFooterView) { 167 | toast.setText("actor footer clicked"); 168 | toast.show(); 169 | } else if (v == commentHeaderView) { 170 | toast.setText("comment header clicked"); 171 | toast.show(); 172 | } else if (v == commentFooterView) { 173 | toast.setText("comment footer clicked"); 174 | toast.show(); 175 | } 176 | } 177 | 178 | private void initOtherComponents() { 179 | toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); 180 | toast.setDuration(Toast.LENGTH_SHORT); 181 | } 182 | 183 | private View inflaterHeaderOrFooterAndBindClick(int resId) { 184 | View view = LayoutInflater.from(this).inflate(resId, null, false); 185 | view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 186 | view.setOnClickListener(this); 187 | return view; 188 | } 189 | } -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/actor/a/FilmActorAViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.actor.a; 2 | 3 | import android.graphics.Color; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wangjie.seizerecyclerview.BaseViewHolder; 10 | import com.wangjie.seizerecyclerview.SeizePosition; 11 | import com.wangjie.seizerecyclerview.example.R; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/29/17. 17 | */ 18 | public class FilmActorAViewHolder extends BaseViewHolder implements View.OnClickListener{ 19 | public interface OnFilmActorAViewHolderListener { 20 | void onFilmActorAItemClick(int subSourcePosition); 21 | } 22 | private OnFilmActorAViewHolderListener onFilmActorAViewHolderListener; 23 | public void setOnFilmActorAViewHolderListener(OnFilmActorAViewHolderListener onFilmActorAViewHolderListener) { 24 | this.onFilmActorAViewHolderListener = onFilmActorAViewHolderListener; 25 | } 26 | 27 | TextView actorTv; 28 | 29 | public FilmActorAViewHolder(ViewGroup parent) { 30 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_actor, parent, false)); 31 | actorTv = (TextView) itemView.findViewById(R.id.item_film_actor_tv); 32 | actorTv.setBackgroundColor(Color.RED); 33 | actorTv.setOnClickListener(this); 34 | } 35 | 36 | @Override 37 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 38 | actorTv.setText("actor A " + seizePosition.getPosition()); 39 | } 40 | 41 | @Override 42 | public void onClick(View v) { 43 | if(v == actorTv && null != onFilmActorAViewHolderListener){ 44 | onFilmActorAViewHolderListener.onFilmActorAItemClick(getSeizePosition().getSubSourcePosition()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/actor/a/FilmActorAViewHolderOwner.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.actor.a; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | import android.widget.Toast; 6 | 7 | import com.wangjie.seizerecyclerview.BaseViewHolder; 8 | import com.wangjie.seizerecyclerview.attacher.ViewHolderOwner; 9 | 10 | /** 11 | * Author: wangjie 12 | * Email: tiantian.china.2@gmail.com 13 | * Date: 3/29/17. 14 | */ 15 | public class FilmActorAViewHolderOwner extends ViewHolderOwner implements FilmActorAViewHolder.OnFilmActorAViewHolderListener { 16 | public FilmActorAViewHolderOwner(Context context) { 17 | super(context); 18 | } 19 | 20 | @Override 21 | public BaseViewHolder createViewHolder(ViewGroup parent) { 22 | FilmActorAViewHolder holder = new FilmActorAViewHolder(parent); 23 | holder.setOnFilmActorAViewHolderListener(this); 24 | return holder; 25 | } 26 | 27 | @Override 28 | public void onFilmActorAItemClick(int subSourcePosition) { 29 | Toast.makeText(context, "A actor " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/actor/b/FilmActorBViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.actor.b; 2 | 3 | import android.graphics.Color; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wangjie.seizerecyclerview.BaseViewHolder; 10 | import com.wangjie.seizerecyclerview.SeizePosition; 11 | import com.wangjie.seizerecyclerview.example.R; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/29/17. 17 | */ 18 | public class FilmActorBViewHolder extends BaseViewHolder implements View.OnClickListener { 19 | public interface OnFilmActorBViewHolderListener { 20 | 21 | void onFilmActorBItemClick(int subSourcePosition); 22 | } 23 | private OnFilmActorBViewHolderListener onFilmActorBViewHolderListener; 24 | 25 | public void setOnFilmActorBViewHolderListener(OnFilmActorBViewHolderListener onFilmActorBViewHolderListener) { 26 | this.onFilmActorBViewHolderListener = onFilmActorBViewHolderListener; 27 | } 28 | 29 | TextView actorTv; 30 | 31 | public FilmActorBViewHolder(ViewGroup parent) { 32 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_actor, parent, false)); 33 | actorTv = (TextView) itemView.findViewById(R.id.item_film_actor_tv); 34 | actorTv.setBackgroundColor(Color.YELLOW); 35 | actorTv.setOnClickListener(this); 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 40 | actorTv.setText("actor B " + seizePosition.getPosition()); 41 | } 42 | 43 | @Override 44 | public void onClick(View v) { 45 | if(v == actorTv && null != onFilmActorBViewHolderListener){ 46 | onFilmActorBViewHolderListener.onFilmActorBItemClick(getSeizePosition().getSubSourcePosition()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/actor/b/FilmActorBViewHolderOwner.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.actor.b; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | import android.widget.Toast; 6 | 7 | import com.wangjie.seizerecyclerview.BaseViewHolder; 8 | import com.wangjie.seizerecyclerview.attacher.ViewHolderOwner; 9 | 10 | /** 11 | * Author: wangjie 12 | * Email: tiantian.china.2@gmail.com 13 | * Date: 3/29/17. 14 | */ 15 | public class FilmActorBViewHolderOwner extends ViewHolderOwner implements FilmActorBViewHolder.OnFilmActorBViewHolderListener { 16 | public FilmActorBViewHolderOwner(Context context) { 17 | super(context); 18 | } 19 | 20 | @Override 21 | public BaseViewHolder createViewHolder(ViewGroup parent) { 22 | FilmActorBViewHolder filmActorBViewHolder = new FilmActorBViewHolder(parent); 23 | filmActorBViewHolder.setOnFilmActorBViewHolderListener(this); 24 | return filmActorBViewHolder; 25 | } 26 | 27 | @Override 28 | public void onFilmActorBItemClick(int subSourcePosition) { 29 | Toast.makeText(context, "B actor " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/comment/a/FilmCommentAViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.comment.a; 2 | 3 | import android.graphics.Color; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wangjie.seizerecyclerview.BaseViewHolder; 10 | import com.wangjie.seizerecyclerview.SeizePosition; 11 | import com.wangjie.seizerecyclerview.example.R; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/28/17. 17 | */ 18 | public class FilmCommentAViewHolder extends BaseViewHolder implements View.OnClickListener{ 19 | public interface OnFilmCommentAViewHolderListener { 20 | void onFilmCommentAItemClick(int subSourcePosition); 21 | } 22 | private OnFilmCommentAViewHolderListener onFilmCommentAViewHolderListener; 23 | 24 | public void setOnFilmCommentAViewHolderListener(OnFilmCommentAViewHolderListener onFilmCommentAViewHolderListener) { 25 | this.onFilmCommentAViewHolderListener = onFilmCommentAViewHolderListener; 26 | } 27 | 28 | TextView commentTv; 29 | 30 | public FilmCommentAViewHolder(ViewGroup parent) { 31 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_comment, parent, false)); 32 | commentTv = (TextView) itemView.findViewById(R.id.item_film_comment_tv); 33 | commentTv.setBackgroundColor(Color.GRAY); 34 | commentTv.setOnClickListener(this); 35 | } 36 | 37 | @Override 38 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 39 | commentTv.setText("Comment A, " + seizePosition.getPosition()); 40 | } 41 | 42 | @Override 43 | public void onClick(View v) { 44 | if(commentTv == v && null != onFilmCommentAViewHolderListener){ 45 | onFilmCommentAViewHolderListener.onFilmCommentAItemClick(getSeizePosition().getSubSourcePosition()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/comment/a/FilmCommentAViewHolderOwner.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.comment.a; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | import android.widget.Toast; 6 | 7 | import com.wangjie.seizerecyclerview.BaseViewHolder; 8 | import com.wangjie.seizerecyclerview.attacher.ViewHolderOwner; 9 | 10 | /** 11 | * Author: wangjie 12 | * Email: tiantian.china.2@gmail.com 13 | * Date: 3/29/17. 14 | */ 15 | public class FilmCommentAViewHolderOwner extends ViewHolderOwner implements FilmCommentAViewHolder.OnFilmCommentAViewHolderListener { 16 | public FilmCommentAViewHolderOwner(Context context) { 17 | super(context); 18 | } 19 | 20 | @Override 21 | public BaseViewHolder createViewHolder(ViewGroup parent) { 22 | FilmCommentAViewHolder holder = new FilmCommentAViewHolder(parent); 23 | holder.setOnFilmCommentAViewHolderListener(this); 24 | return holder; 25 | } 26 | 27 | @Override 28 | public void onFilmCommentAItemClick(int subSourcePosition) { 29 | Toast.makeText(context, "A comment " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/comment/b/FilmCommentBViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.comment.b; 2 | 3 | import android.graphics.Color; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wangjie.seizerecyclerview.BaseViewHolder; 10 | import com.wangjie.seizerecyclerview.SeizePosition; 11 | import com.wangjie.seizerecyclerview.example.R; 12 | 13 | /** 14 | * Author: wangjie 15 | * Email: tiantian.china.2@gmail.com 16 | * Date: 3/28/17. 17 | */ 18 | public class FilmCommentBViewHolder extends BaseViewHolder implements View.OnClickListener { 19 | public interface OnFilmCommentBViewHolderListener { 20 | 21 | void onFilmCommentBItemClick(int subSourcePosition); 22 | } 23 | 24 | private OnFilmCommentBViewHolderListener onFilmCommentBViewHolderListener; 25 | 26 | public void setOnFilmCommentBViewHolderListener(OnFilmCommentBViewHolderListener onFilmCommentBViewHolderListener) { 27 | this.onFilmCommentBViewHolderListener = onFilmCommentBViewHolderListener; 28 | } 29 | 30 | TextView commentTv; 31 | 32 | public FilmCommentBViewHolder(ViewGroup parent) { 33 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_comment, parent, false)); 34 | commentTv = (TextView) itemView.findViewById(R.id.item_film_comment_tv); 35 | commentTv.setBackgroundColor(Color.LTGRAY); 36 | commentTv.setOnClickListener(this); 37 | } 38 | 39 | @Override 40 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) { 41 | commentTv.setText("Comment B, " + seizePosition.getPosition()); 42 | } 43 | 44 | @Override 45 | public void onClick(View v) { 46 | if (commentTv == v && null != onFilmCommentBViewHolderListener) { 47 | onFilmCommentBViewHolderListener.onFilmCommentBItemClick(getSeizePosition().getSubSourcePosition()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/adapter/comment/b/FilmCommentBViewHolderOwner.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.adapter.comment.b; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | import android.widget.Toast; 6 | 7 | import com.wangjie.seizerecyclerview.BaseViewHolder; 8 | import com.wangjie.seizerecyclerview.attacher.ViewHolderOwner; 9 | 10 | /** 11 | * Author: wangjie 12 | * Email: tiantian.china.2@gmail.com 13 | * Date: 3/29/17. 14 | */ 15 | public class FilmCommentBViewHolderOwner extends ViewHolderOwner implements FilmCommentBViewHolder.OnFilmCommentBViewHolderListener { 16 | public FilmCommentBViewHolderOwner(Context context) { 17 | super(context); 18 | } 19 | 20 | @Override 21 | public BaseViewHolder createViewHolder(ViewGroup parent) { 22 | FilmCommentBViewHolder filmCommentBViewHolder = new FilmCommentBViewHolder(parent); 23 | filmCommentBViewHolder.setOnFilmCommentBViewHolderListener(this); 24 | return filmCommentBViewHolder; 25 | } 26 | 27 | @Override 28 | public void onFilmCommentBItemClick(int subSourcePosition) { 29 | Toast.makeText(context, "B comment " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/vm/actor/ActorAVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.vm.actor; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/29/17. 9 | */ 10 | public class ActorAVM extends ActorVM { 11 | public ActorAVM(String obj) { 12 | super(obj); 13 | } 14 | 15 | @Override 16 | public int getActorViewType() { 17 | return TYPE_ACTOR_A; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/vm/actor/ActorBVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.vm.actor; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/29/17. 9 | */ 10 | public class ActorBVM extends ActorVM { 11 | public ActorBVM(String obj) { 12 | super(obj); 13 | } 14 | 15 | @Override 16 | public int getActorViewType() { 17 | return TYPE_ACTOR_B; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/vm/comment/CommentAVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.vm.comment; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/29/17. 9 | */ 10 | public class CommentAVM extends CommentVM { 11 | public CommentAVM(String obj) { 12 | super(obj); 13 | } 14 | 15 | @Override 16 | public int getCommentViewType() { 17 | return TYPE_COMMENT_A; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/multitype/vm/comment/CommentBVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.multitype.vm.comment; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/29/17. 9 | */ 10 | public class CommentBVM extends CommentVM { 11 | public CommentBVM(String obj) { 12 | super(obj); 13 | } 14 | 15 | @Override 16 | public int getCommentViewType() { 17 | return TYPE_COMMENT_B; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/vm/VM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.vm; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/28/17. 9 | */ 10 | public class VM implements Serializable { 11 | private T obj; 12 | 13 | public VM(T obj) { 14 | this.obj = obj; 15 | } 16 | 17 | public T getObj() { 18 | return obj; 19 | } 20 | 21 | public int getViewType(){ 22 | return 0; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/vm/actor/ActorVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.vm.actor; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.VM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/28/17. 9 | */ 10 | public class ActorVM extends VM { 11 | public static final int TYPE_ACTOR = 10; 12 | public static final int TYPE_ACTOR_A = 11; 13 | public static final int TYPE_ACTOR_B = 12; 14 | 15 | public ActorVM(String obj) { 16 | super(obj); 17 | } 18 | 19 | @Override 20 | public int getViewType() { 21 | return TYPE_ACTOR; 22 | } 23 | 24 | public int getActorViewType() { 25 | return TYPE_ACTOR_A; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/wangjie/seizerecyclerview/example/vm/comment/CommentVM.java: -------------------------------------------------------------------------------- 1 | package com.wangjie.seizerecyclerview.example.vm.comment; 2 | 3 | import com.wangjie.seizerecyclerview.example.vm.VM; 4 | 5 | /** 6 | * Author: wangjie 7 | * Email: tiantian.china.2@gmail.com 8 | * Date: 3/28/17. 9 | */ 10 | public class CommentVM extends VM { 11 | public static final int TYPE_COMMENT = 20; 12 | public static final int TYPE_COMMENT_A = 21; 13 | public static final int TYPE_COMMENT_B = 22; 14 | 15 | public CommentVM(String obj) { 16 | super(obj); 17 | } 18 | 19 | @Override 20 | public int getViewType() { 21 | return TYPE_COMMENT; 22 | } 23 | 24 | public int getCommentViewType() { 25 | return TYPE_COMMENT_A; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_basic.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 |