├── .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 |
23 |
24 |
31 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_multi_type.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
23 |
24 |
31 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/footer_film.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/footer_film_actor.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/footer_film_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/header_film.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/header_film_actor.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/header_film_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_film_actor.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_film_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SeizeRecyclerView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wangjie/seizerecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | ext {
20 | global_compileSdkVersion = 25
21 | global_buildToolsVersion = "25.0.0"
22 | global_minSdkVersion = 14
23 | global_targetSdkVersion = 25
24 | global_supportVersion = '25.0.0'
25 | global_junitVersion = '4.12'
26 | global_espressoVersion = '2.2.2'
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 22 13:29:11 CST 2017
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.14.1-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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile("com.android.support.test.espresso:espresso-core:$global_espressoVersion", {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile "com.android.support:appcompat-v7:$global_supportVersion"
30 | testCompile "junit:junit:$global_junitVersion"
31 |
32 | compile "com.android.support:recyclerview-v7:$global_supportVersion"
33 | }
34 |
35 | apply from: 'nexus_aar_db.gradle'
--------------------------------------------------------------------------------
/library/nexus_aar_center.gradle:
--------------------------------------------------------------------------------
1 | // ********************************** upload archives ***********************************
2 |
3 | apply plugin: 'maven'
4 | apply plugin: 'signing' //使用signing plugin做数字签名
5 |
6 | //定义GroupID和Version,ArtefactID会自动使用Project名
7 | group = "$archiveGroup"
8 | version = "$archiveVersion"
9 | //sourceCompatibility = 1.7
10 | //targetCompatibility = 1.7
11 |
12 | repositories {
13 | mavenCentral();
14 | }
15 |
16 | artifacts {
17 | // archives file("$archivePath")
18 | archives file: file("$archivePath"), /*name: 'A', */ type: 'aar', classifier: 'android'
19 | }
20 | signing {
21 | sign configurations.archives
22 | }
23 |
24 | uploadArchives {
25 | repositories {
26 | mavenDeployer {
27 | //为Pom文件做数字签名
28 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
29 |
30 | //指定项目部署到的中央库地址,UserName和Password就是Part 1中注册的账号。
31 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
32 | authentication(userName: "$ossrhUsername", password: "$ossrhPassword")
33 | }
34 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
35 | authentication(userName: "$ossrhUsername", password: "$ossrhPassword")
36 | }
37 |
38 | // addFilter("$archiveName") {artifact, file ->
39 | // artifact.name.endsWith("$archiveName")
40 | // }
41 |
42 | //构造项目的Pom文件,参见Part 2中Pom文件的规范,不要遗漏必填项
43 | pom.project {
44 | name "$archiveName"
45 | artifactId "$archiveName"
46 | packaging 'aar'
47 | description "$archiveDesc"
48 | url "$archiveUrl"
49 |
50 | scm {
51 | url 'scm:git@github.com:wangjiegulu/RapidORM.git'
52 | connection 'scm:git@github.com:wangjiegulu/RapidORM.git'
53 | developerConnection 'git@github.com:wangjiegulu/RapidORM.git'
54 | }
55 |
56 | licenses {
57 | license {
58 | name 'The Apache Software License, Version 2.0'
59 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
60 | distribution 'wangjie'
61 | }
62 | }
63 |
64 | developers {
65 | developer {
66 | id 'wangjie'
67 | name 'Wang Jie'
68 | email 'tiantian.china.2@gmail.com'
69 | }
70 | }
71 | }
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/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.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/BaseRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | /**
14 | * Author: wangjie
15 | * Email: tiantian.china.2@gmail.com
16 | * Date: 3/23/17.
17 | */
18 | public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter {
19 |
20 | protected List> seizeAdapters = new ArrayList<>();
21 |
22 | private static final int TYPE_DEFAULT = 0x7682;
23 | private static final int TYPE_HEADER_VIEW = 0x7683;
24 | private static final int TYPE_FOOTER_VIEW = 0x7684;
25 |
26 | private View headerView;
27 | private View footerView;
28 |
29 | public void setHeader(@NonNull View view) {
30 | headerView = view;
31 | }
32 |
33 | public void setFooter(@NonNull View view) {
34 | footerView = view;
35 | }
36 |
37 | @SafeVarargs
38 | public final void setSeizeAdapters(SeizeAdapter... seizeAdapters) {
39 | this.seizeAdapters = Arrays.asList(seizeAdapters);
40 | for (SeizeAdapter seizeAdapter : this.seizeAdapters) {
41 | seizeAdapter.setParentAdapter(this);
42 | }
43 | }
44 |
45 | @Override
46 | public final BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
47 | switch (viewType) {
48 | case TYPE_HEADER_VIEW:
49 | return new EmptyViewHolder(headerView);
50 | case TYPE_FOOTER_VIEW:
51 | return new EmptyViewHolder(footerView);
52 | default:
53 | if (null != seizeAdapters) {
54 | for (SeizeAdapter seizeAdapter : seizeAdapters) {
55 | BaseViewHolder viewHolder;
56 | if (seizeAdapter.hasViewType(viewType)
57 | && null != (viewHolder = seizeAdapter.onCreateViewHolder(parent, viewType))
58 | ) {
59 | return viewHolder;
60 | }
61 | }
62 | }
63 | }
64 | return null;
65 | }
66 |
67 | @Override
68 | public final int getItemViewType(int position) {
69 | if (isHeader(position)) {
70 | return TYPE_HEADER_VIEW;
71 | } else if (isFooter((position))) {
72 | return TYPE_FOOTER_VIEW;
73 | } else {
74 | SeizePosition seizePosition = convertSeizePosition(position);
75 | if (null != seizePosition) {
76 | return seizeAdapters.get(seizePosition.getSeizeAdapterIndex())
77 | .getItemViewType(seizePosition);
78 | }
79 | }
80 |
81 | return super.getItemViewType(position);
82 | }
83 |
84 | public boolean isHeader(int position) {
85 | int headerCount = getCount(headerView);
86 | return 0 != headerCount && position <= headerCount - 1;
87 | }
88 |
89 | public boolean isFooter(int position) {
90 | int footerCount = getCount(footerView);
91 | return 0 != footerCount && position >= getItemCount() - footerCount;
92 | }
93 |
94 | @Override
95 | public final void onBindViewHolder(BaseViewHolder holder, int position) {
96 | SeizePosition seizePosition = convertSeizePosition(position);
97 | if (null != seizePosition) {
98 | seizeAdapters.get(seizePosition.getSeizeAdapterIndex())
99 | .onBindViewHolder(holder, seizePosition);
100 | }
101 | }
102 |
103 | @Nullable
104 | public final SeizeAdapter getSeizeAdapter(int position) {
105 | SeizePosition seizePosition = convertSeizePosition(position);
106 | if (null != seizePosition) {
107 | return seizeAdapters.get(seizePosition.getSeizeAdapterIndex());
108 | }
109 | return null;
110 | }
111 |
112 | @Nullable
113 | public final SeizePosition convertSeizePosition(int position) {
114 | if (null != seizeAdapters) {
115 | int seizeLastPosition = getCount(headerView);
116 | for (int i = 0, len = seizeAdapters.size(); i < len; i++) {
117 | SeizeAdapter seizeAdapter = seizeAdapters.get(i);
118 | int count = seizeAdapter.getItemCount();
119 | seizeLastPosition += count;
120 | if (seizeLastPosition > position) {
121 | int subPosition = count - (seizeLastPosition - position);
122 | return new SeizePosition(i,
123 | position, positionToSourcePosition(position),
124 | subPosition, seizeAdapter.subPositionToSubSourcePosition(subPosition)
125 | );
126 | }
127 | }
128 | }
129 | return null;
130 | }
131 |
132 | @Nullable
133 | public final SeizePosition convertSeizePosition(int seizeAdapterIndex, int subPosition) {
134 | // TODO: 3/28/17 wangjie impl
135 | throw new RuntimeException("Not supported!");
136 | }
137 |
138 | @Override
139 | public final int getItemCount() {
140 | int itemCount = getCount(headerView) + getCount(footerView);
141 | List> childSeizeAdapters = seizeAdapters;
142 | if (null != childSeizeAdapters) {
143 | for (SeizeAdapter seizeAdapter : childSeizeAdapters) {
144 | itemCount += seizeAdapter.getItemCount();
145 | }
146 | }
147 | return itemCount;
148 | }
149 |
150 | private int getCount(View view) {
151 | return null == view ? 0 : 1;
152 | }
153 |
154 | public final int positionToSourcePosition(int position) {
155 | return position - getCount(headerView);
156 | }
157 |
158 | public final int sourcePositionToPosition(int sourcePosition) {
159 | return sourcePosition + getCount(headerView);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/BaseSeizeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | /**
9 | * Author: wangjie
10 | * Email: tiantian.china.2@gmail.com
11 | * Date: 3/27/17.
12 | */
13 | public abstract class BaseSeizeAdapter implements SeizeAdapter {
14 | protected RecyclerView.Adapter parentAdapter;
15 | private static final int TYPE_DEFAULT = 0x8682;
16 | private int typeHeaderDefault = -0x8683;
17 | private int typeFooterDefault = -0x8684;
18 | private View headerView;
19 | private View footerView;
20 |
21 | @Override
22 | public void setHeader(@NonNull View view) {
23 | headerView = view;
24 | // TODO: 3/29/17 wangjie optim
25 | typeHeaderDefault = this.hashCode();
26 | }
27 |
28 | @Override
29 | public void setFooter(@NonNull View view) {
30 | footerView = view;
31 | // TODO: 3/29/17 wangjie optim
32 | typeFooterDefault = this.hashCode() - 1;
33 | }
34 |
35 | @Override
36 | public final BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
37 | return createTypeViewHolderInternal(parent, viewType);
38 | }
39 |
40 | private BaseViewHolder createTypeViewHolderInternal(ViewGroup parent, int viewType) {
41 | if (viewType == typeHeaderDefault) {
42 | return new EmptyViewHolder(headerView);
43 | } else if (viewType == typeFooterDefault) {
44 | return new EmptyViewHolder(footerView);
45 | } else {
46 | return onCreateTypeViewHolder(parent, viewType);
47 | }
48 | }
49 |
50 | public abstract BaseViewHolder onCreateTypeViewHolder(ViewGroup parent, int type);
51 |
52 | @Override
53 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) {
54 | holder.onBindViewHolderInternal(holder, seizePosition);
55 | }
56 |
57 | @Override
58 | public void setParentAdapter(RecyclerView.Adapter parentAdapter) {
59 | this.parentAdapter = parentAdapter;
60 | }
61 |
62 | @Override
63 | public boolean hasViewType(int viewType) {
64 | return true;
65 | }
66 |
67 | @Override
68 | public final int getItemCount() {
69 | return getSourceItemCount() + getCount(headerView) + getCount(footerView);
70 | }
71 |
72 | private int getCount(View view) {
73 | return null == view ? 0 : 1;
74 | }
75 |
76 | @Override
77 | public long getItemId(int subPosition) {
78 | return subPosition;
79 | }
80 |
81 | public abstract Object getItem(int subSourcePosition);
82 |
83 | @Override
84 | public final int getItemViewType(SeizePosition seizePosition) {
85 | int subPosition = seizePosition.getSubPosition();
86 | if (isHeader(subPosition)) {
87 | return typeHeaderDefault;
88 | } else if (isFooter(subPosition)) {
89 | return typeFooterDefault;
90 | } else {
91 | return getSourceItemViewType(seizePosition.getSubSourcePosition());
92 | }
93 | }
94 |
95 | @Override
96 | public boolean isHeader(int subPosition) {
97 | int headerCount = getCount(headerView);
98 | return 0 != headerCount && subPosition <= headerCount - 1;
99 | }
100 |
101 | @Override
102 | public boolean isFooter(int subPosition) {
103 | int footerCount = getCount(footerView);
104 | return 0 != footerCount && subPosition >= getItemCount() - footerCount;
105 | }
106 |
107 | @Override
108 | public int subPositionToSubSourcePosition(int subPosition) {
109 | return subPosition - getCount(headerView);
110 | }
111 |
112 | @Override
113 | public int subSourcePositionToSubPosition(int subSourcePosition) {
114 | return subSourcePosition + getCount(headerView);
115 | }
116 |
117 | public abstract int getSourceItemCount();
118 |
119 | public int getSourceItemViewType(int subSourcePosition) {
120 | return TYPE_DEFAULT;
121 | }
122 |
123 | @Override
124 | public void notifyDataSetChanged() {
125 | if (null != parentAdapter) {
126 | parentAdapter.notifyDataSetChanged();
127 | }
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | /**
7 | * Author: wangjie
8 | * Email: tiantian.china.2@gmail.com
9 | * Date: 3/28/17.
10 | */
11 | public abstract class BaseViewHolder extends RecyclerView.ViewHolder {
12 | public BaseViewHolder(View itemView) {
13 | super(itemView);
14 | }
15 |
16 | private SeizePosition seizePosition;
17 |
18 | public SeizePosition getSeizePosition() {
19 | return seizePosition;
20 | }
21 |
22 | public final void onBindViewHolderInternal(BaseViewHolder holder, SeizePosition seizePosition) {
23 | this.seizePosition = seizePosition;
24 | onBindViewHolder(holder, seizePosition);
25 | }
26 |
27 | public abstract void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition);
28 |
29 | public void onViewRecycled() {
30 | // ignore
31 | }
32 |
33 | public void onViewDetachedFromWindow() {
34 | // ignore
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/EmptyViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Author: wangjie
7 | * Email: tiantian.china.2@gmail.com
8 | * Date: 3/28/17.
9 | */
10 | public class EmptyViewHolder extends BaseViewHolder {
11 | public EmptyViewHolder(View itemView) {
12 | super(itemView);
13 | }
14 |
15 | @Override
16 | public void onBindViewHolder(BaseViewHolder holder, SeizePosition seizePosition) {
17 | // ignore
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/SeizeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | /**
9 | * Author: wangjie
10 | * Email: tiantian.china.2@gmail.com
11 | * Date: 3/27/17.
12 | */
13 | public interface SeizeAdapter {
14 |
15 | void setParentAdapter(RecyclerView.Adapter parentAdapter);
16 |
17 | void setHeader(@NonNull View view);
18 |
19 | void setFooter(@NonNull View view);
20 |
21 | boolean isHeader(int subPosition);
22 |
23 | boolean isFooter(int subPosition);
24 |
25 | boolean hasViewType(int viewType);
26 |
27 | int getItemViewType(SeizePosition seizePosition);
28 |
29 | VH onCreateViewHolder(ViewGroup parent, int viewType);
30 |
31 | void onBindViewHolder(VH holder, SeizePosition seizePosition);
32 |
33 | int getItemCount();
34 |
35 | long getItemId(int position);
36 |
37 | int subPositionToSubSourcePosition(int subPosition);
38 |
39 | int subSourcePositionToSubPosition(int subSourcePosition);
40 |
41 | void notifyDataSetChanged();
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/SeizePosition.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
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 SeizePosition implements Serializable{
11 | private int seizeAdapterIndex;
12 | private int position;
13 | private int sourcePosition;
14 | private int subPosition;
15 | private int subSourcePosition;
16 |
17 | public SeizePosition(int seizeAdapterIndex, int position, int sourcePosition, int subPosition, int subSourcePosition) {
18 | this.seizeAdapterIndex = seizeAdapterIndex;
19 | this.position = position;
20 | this.sourcePosition = sourcePosition;
21 | this.subPosition = subPosition;
22 | this.subSourcePosition = subSourcePosition;
23 | }
24 |
25 | public int getSeizeAdapterIndex() {
26 | return seizeAdapterIndex;
27 | }
28 |
29 | public void setSeizeAdapterIndex(int seizeAdapterIndex) {
30 | this.seizeAdapterIndex = seizeAdapterIndex;
31 | }
32 |
33 | public int getPosition() {
34 | return position;
35 | }
36 |
37 | public void setPosition(int position) {
38 | this.position = position;
39 | }
40 |
41 | public int getSubPosition() {
42 | return subPosition;
43 | }
44 |
45 | public void setSubPosition(int subPosition) {
46 | this.subPosition = subPosition;
47 | }
48 |
49 | public int getSubSourcePosition() {
50 | return subSourcePosition;
51 | }
52 |
53 | public void setSubSourcePosition(int subSourcePosition) {
54 | this.subSourcePosition = subSourcePosition;
55 | }
56 |
57 | public int getSourcePosition() {
58 | return sourcePosition;
59 | }
60 |
61 | public void setSourcePosition(int sourcePosition) {
62 | this.sourcePosition = sourcePosition;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "SeizePosition{" +
68 | "seizeAdapterIndex=" + seizeAdapterIndex +
69 | ", position=" + position +
70 | ", sourcePosition=" + sourcePosition +
71 | ", subPosition=" + subPosition +
72 | ", subSourcePosition=" + subSourcePosition +
73 | '}';
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/attacher/Func1R.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview.attacher;
2 |
3 | /**
4 | * Author: wangjie
5 | * Email: tiantian.china.2@gmail.com
6 | * Date: 3/29/17.
7 | */
8 | public interface Func1R {
9 | Result call(Param1 param1);
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/attacher/MultiSeizeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview.attacher;
2 |
3 | import android.util.SparseArray;
4 | import android.view.ViewGroup;
5 |
6 | import com.wangjie.seizerecyclerview.BaseSeizeAdapter;
7 | import com.wangjie.seizerecyclerview.BaseViewHolder;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Author: wangjie
14 | * Email: tiantian.china.2@gmail.com
15 | * Date: 3/29/17.
16 | */
17 | public class MultiSeizeAdapter extends BaseSeizeAdapter {
18 | /**
19 | * Get type function
20 | */
21 | private Func1R getItemType;
22 | /**
23 | * Map -> key: type; value: viewHolderOwner creation function
24 | */
25 | private SparseArray viewHolderOwnerMap = new SparseArray<>();
26 |
27 | public void setGetItemType(Func1R getItemType) {
28 | this.getItemType = getItemType;
29 | }
30 |
31 | public void addSupportViewHolder(int type, ViewHolderOwner viewHolderOwner) {
32 | viewHolderOwnerMap.put(type, viewHolderOwner);
33 | }
34 |
35 | private List list = new ArrayList<>();
36 |
37 | public List getList() {
38 | return list;
39 | }
40 |
41 | public void addList(List list) {
42 | this.list.addAll(list);
43 | }
44 |
45 | public void setList(List list) {
46 | if (null == list) {
47 | this.list = new ArrayList<>();
48 | } else {
49 | this.list = list;
50 | }
51 | }
52 |
53 | @Override
54 | public int getSourceItemViewType(int subSourcePosition) {
55 | if (null != getItemType) {
56 | return getItemType.call(list.get(subSourcePosition));
57 | }
58 | return super.getSourceItemViewType(subSourcePosition);
59 | }
60 |
61 | @Override
62 | public BaseViewHolder onCreateTypeViewHolder(ViewGroup parent, int type) {
63 | ViewHolderOwner viewHolderOwner = viewHolderOwnerMap.get(type);
64 | if (null != viewHolderOwner) {
65 | return viewHolderOwner.createViewHolder(parent);
66 | }
67 | return null;
68 | }
69 |
70 | @Override
71 | public Object getItem(int subSourcePosition) {
72 | return list.get(subSourcePosition);
73 | }
74 |
75 | @Override
76 | public int getSourceItemCount() {
77 | return list.size();
78 | }
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wangjie/seizerecyclerview/attacher/ViewHolderOwner.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview.attacher;
2 |
3 | import android.content.Context;
4 | import android.view.ViewGroup;
5 |
6 | import com.wangjie.seizerecyclerview.BaseViewHolder;
7 |
8 | /**
9 | * Author: wangjie Email: tiantian.china.2@gmail.com Date: 3/2/17.
10 | */
11 | public abstract class ViewHolderOwner {
12 | private static final String TAG = ViewHolderOwner.class.getSimpleName();
13 | protected Context context;
14 |
15 | public ViewHolderOwner(Context context) {
16 | this.context = context;
17 | }
18 |
19 |
20 | public abstract BaseViewHolder createViewHolder(ViewGroup parent);
21 |
22 | public void onParentViewAttachedToWindow() {
23 |
24 | }
25 |
26 | public void onParentViewDetachedFromWindow() {
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/wangjie/seizerecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.seizerecyclerview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshot/basic.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/screenshot/basic.gif
--------------------------------------------------------------------------------
/screenshot/multi_type.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjiegulu/SeizeRecyclerView/916c0ae97bc16878af9b6335796130d1194aecf2/screenshot/multi_type.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------