├── .gitignore ├── .gradle └── 2.2.1 │ └── taskArtifacts │ ├── cache.properties │ ├── cache.properties.lock │ ├── fileHashes.bin │ ├── fileSnapshots.bin │ ├── outputFileStates.bin │ └── taskArtifacts.bin ├── LICENSE ├── README.md ├── advanceadapter ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zzhoujay │ │ └── advanceadapter │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zzhoujay │ │ │ └── advanceadapter │ │ │ ├── AdvanceAdapter.java │ │ │ ├── DynamicAdapter.java │ │ │ └── SingleAdapter.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── zzhoujay │ └── advanceadapter │ └── ExampleUnitTest.java ├── build.gradle ├── build └── intermediates │ ├── dex-cache │ └── cache.xml │ └── gradle_project_sync_data.bin ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── image1.png ├── image2.png └── image3.png ├── settings.gradle └── simple ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── zzhoujay │ └── advanceadaptersimple │ └── ApplicationTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── zzhoujay │ │ └── advanceadaptersimple │ │ ├── MainActivity.java │ │ └── NormalAdapter.java └── res │ ├── layout │ ├── activity_main.xml │ ├── footer.xml │ ├── header.xml │ └── item.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── com └── zzhoujay └── advanceadaptersimple └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | 40 | # Keystore files 41 | *.jks 42 | ### Eclipse template 43 | 44 | .metadata 45 | bin/ 46 | tmp/ 47 | *.tmp 48 | *.bak 49 | *.swp 50 | *~.nib 51 | local.properties 52 | .settings/ 53 | .loadpath 54 | .recommenders 55 | 56 | # Eclipse Core 57 | .project 58 | 59 | # External tool builders 60 | .externalToolBuilders/ 61 | 62 | # Locally stored "Eclipse launch configurations" 63 | *.launch 64 | 65 | # PyDev specific (Python IDE for Eclipse) 66 | *.pydevproject 67 | 68 | # CDT-specific (C/C++ Development Tooling) 69 | .cproject 70 | 71 | # JDT-specific (Eclipse Java Development Tools) 72 | .classpath 73 | 74 | # Java annotation processor (APT) 75 | .factorypath 76 | 77 | # PDT-specific (PHP Development Tools) 78 | .buildpath 79 | 80 | # sbteclipse plugin 81 | .target 82 | 83 | # Tern plugin 84 | .tern-project 85 | 86 | # TeXlipse plugin 87 | .texlipse 88 | 89 | # STS (Spring Tool Suite) 90 | .springBeans 91 | 92 | # Code Recommenders 93 | .recommenders/ 94 | ### OSX template 95 | .DS_Store 96 | .AppleDouble 97 | .LSOverride 98 | 99 | # Icon must end with two \r 100 | Icon 101 | 102 | # Thumbnails 103 | ._* 104 | 105 | # Files that might appear in the root of a volume 106 | .DocumentRevisions-V100 107 | .fseventsd 108 | .Spotlight-V100 109 | .TemporaryItems 110 | .Trashes 111 | .VolumeIcon.icns 112 | 113 | # Directories potentially created on remote AFP share 114 | .AppleDB 115 | .AppleDesktop 116 | Network Trash Folder 117 | Temporary Items 118 | .apdisk 119 | ### Gradle template 120 | .gradle 121 | build/ 122 | 123 | # Ignore Gradle GUI config 124 | gradle-app.setting 125 | 126 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 127 | !gradle-wrapper.jar 128 | 129 | # Cache of project 130 | .gradletasknamecache 131 | 132 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 133 | # gradle/wrapper/gradle-wrapper.properties 134 | ### Windows template 135 | # Windows image file caches 136 | Thumbs.db 137 | ehthumbs.db 138 | 139 | # Folder config file 140 | Desktop.ini 141 | 142 | # Recycle Bin used on file shares 143 | $RECYCLE.BIN/ 144 | 145 | # Windows Installer files 146 | *.cab 147 | *.msi 148 | *.msm 149 | *.msp 150 | 151 | # Windows shortcuts 152 | *.lnk 153 | ### Linux template 154 | *~ 155 | 156 | # temporary files which can be created if a process still has a handle open of a deleted file 157 | .fuse_hidden* 158 | 159 | # KDE directory preferences 160 | .directory 161 | 162 | # Linux trash folder which might appear on any partition or disk 163 | .Trash-* 164 | ### JDeveloper template 165 | # default application storage directory used by the IDE Performance Cache feature 166 | .data/ 167 | 168 | # used for ADF styles caching 169 | temp/ 170 | 171 | # default output directories 172 | classes/ 173 | deploy/ 174 | javadoc/ 175 | 176 | # lock file, a part of Oracle Credential Store Framework 177 | cwallet.sso.lck### JetBrains template 178 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 179 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 180 | 181 | # User-specific stuff: 182 | .idea/workspace.xml 183 | .idea/tasks.xml 184 | .idea/dictionaries 185 | .idea/vcs.xml 186 | .idea/jsLibraryMappings.xml 187 | 188 | # Sensitive or high-churn files: 189 | .idea/dataSources.ids 190 | .idea/dataSources.xml 191 | .idea/dataSources.local.xml 192 | .idea/sqlDataSources.xml 193 | .idea/dynamic.xml 194 | .idea/uiDesigner.xml 195 | 196 | # Gradle: 197 | .idea/gradle.xml 198 | .idea/libraries 199 | 200 | # Mongo Explorer plugin: 201 | .idea/mongoSettings.xml 202 | 203 | ## File-based project format: 204 | *.iws 205 | 206 | ## Plugin-specific files: 207 | 208 | # IntelliJ 209 | /out/ 210 | 211 | # mpeltonen/sbt-idea plugin 212 | .idea_modules/ 213 | 214 | # JIRA plugin 215 | atlassian-ide-plugin.xml 216 | 217 | # Crashlytics plugin (for Android Studio and IntelliJ) 218 | com_crashlytics_export_strings.xml 219 | crashlytics.properties 220 | crashlytics-build.properties 221 | fabric.properties 222 | ### NetBeans template 223 | nbproject/private/ 224 | build/ 225 | nbbuild/ 226 | dist/ 227 | nbdist/ 228 | nbactions.xml 229 | .nb-gradle/ 230 | 231 | -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Wed Jul 22 12:25:47 CST 2015 2 | -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/.gradle/2.2.1/taskArtifacts/cache.properties.lock -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/.gradle/2.2.1/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/outputFileStates.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/.gradle/2.2.1/taskArtifacts/outputFileStates.bin -------------------------------------------------------------------------------- /.gradle/2.2.1/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 zzhoujay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AdvanceAdapter 2 | 3 | > 可以添加Header和Footer的Adapter 4 | 5 | * 低侵入性,采用装饰器的方式包裹正真的Adapter,无需修改原本Adapter 6 | * 支持`LinearLayoutManager`、`GridLayoutManager`、`StaggeredGridLayoutManager` 7 | * 可自定义Header和Footer的增加方式 8 | 9 | ### 运行效果 10 | 11 | ![演示截图](images/image1.png) 12 | ![演示截图](images/image2.png) 13 | ![演示截图](images/image3.png) 14 | 15 | ### 注意 16 | 17 | 1. 在子Adapter中ViewHolder中调用getLayoutPosition()和getAdapterPosition()时会包含外层已添加的Header和Footer 18 | 19 | 2. 默认Header和Footer数量最大为100,且`ViewType`中的`Integer.MIN_VALUE`~`Integer.MIN_VALUE+100`、`Integer.MAX_VALUE-100`~`Integer.MAX_VALUE`均被占用 20 | 21 | ### 使用方法 22 | 23 | 1. 继承`AdvanceAdapter`并实现其中的抽象方法 24 | 25 | 2. 使用`AdvanceAdapter`的两个实现类:`DynamicAdapter`、`SingleAdapter` 26 | 27 | ``` 28 | // 包裹你的Adapter,若是GridLayoutManager或StaggeredGridLayoutManager需要传入layoutManager 29 | AdvanceAdapter advanceAdapter=new DynamicAdapter(normalAdapter,layoutManager); 30 | // 给你的RecyclerView设置advanceAdapter 31 | recyclerView.setAdapter(advanceAdapter); 32 | ``` 33 | 34 | ### gradle引用方法 35 | ``` 36 | repositories { 37 | maven { 38 | url "http://dl.bintray.com/zzhoujay/maven" 39 | } 40 | } 41 | 42 | dependencies { 43 | compile 'com.zzhoujay.advanceadapter:advanceadapter:1.0.2' 44 | } 45 | ``` 46 | 47 | 48 | 49 | _by zzhoujay_ -------------------------------------------------------------------------------- /advanceadapter/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /advanceadapter/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | android { 6 | compileSdkVersion 23 7 | buildToolsVersion "23.0.2" 8 | 9 | defaultConfig { 10 | minSdkVersion 8 11 | targetSdkVersion 23 12 | versionCode 3 13 | versionName "1.0.2" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | android { 22 | lintOptions { 23 | abortOnError false 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | testCompile 'junit:junit:4.12' 31 | compile 'com.android.support:recyclerview-v7:23.2.1' 32 | 33 | } 34 | 35 | 36 | 37 | version = "1.0.2" 38 | 39 | 40 | def siteUrl = 'https://github.com/zzhoujay/AdvanceAdapter' // 项目的主页 41 | def gitUrl = 'https://github.com/zzhoujay/AdvanceAdapter.git' // Git仓库的url 42 | group = "com.zzhoujay.advanceadapter" // Maven Group ID for the artifact,一般填你唯一的包名 43 | install { 44 | repositories.mavenInstaller { 45 | // This generates POM.xml with proper parameters 46 | pom { 47 | project { 48 | packaging 'aar' 49 | name 'AdvanceAdapter' 50 | url siteUrl 51 | licenses { 52 | license { 53 | name 'The MIT License (MIT)' 54 | url 'http://www.opensource.org/licenses/mit-license.php' 55 | } 56 | } 57 | developers { 58 | developer { 59 | id 'zzhoujay' 60 | name '郑州' 61 | email '1582519486@qq.com' 62 | } 63 | } 64 | scm { 65 | connection gitUrl 66 | developerConnection gitUrl 67 | url siteUrl 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | task sourcesJar(type: Jar) { 75 | from android.sourceSets.main.java.srcDirs 76 | classifier = 'sources' 77 | } 78 | 79 | task javadoc(type: Javadoc) { 80 | options.encoding='utf-8' 81 | source = android.sourceSets.main.java.srcDirs 82 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 83 | } 84 | 85 | task javadocJar(type: Jar, dependsOn: javadoc) { 86 | classifier = 'javadoc' 87 | from javadoc.destinationDir 88 | } 89 | 90 | artifacts { 91 | archives javadocJar 92 | archives sourcesJar 93 | } 94 | 95 | Properties properties = new Properties() 96 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 97 | bintray { 98 | user = properties.getProperty("bintray.user") 99 | key = properties.getProperty("bintray.apikey") 100 | configurations = ['archives'] 101 | pkg { 102 | repo = "maven" 103 | name = "AdvanceAdapter" // project name in jcenter 104 | websiteUrl = siteUrl 105 | vcsUrl = gitUrl 106 | licenses = ["MIT"] 107 | publish = true 108 | } 109 | } -------------------------------------------------------------------------------- /advanceadapter/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 /home/zhou/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 | -------------------------------------------------------------------------------- /advanceadapter/src/androidTest/java/com/zzhoujay/advanceadapter/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadapter; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /advanceadapter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /advanceadapter/src/main/java/com/zzhoujay/advanceadapter/AdvanceAdapter.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadapter; 2 | 3 | import android.support.v7.widget.GridLayoutManager; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.support.v7.widget.StaggeredGridLayoutManager; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by zhou on 16-3-24. 12 | * 拥有Header和Footer的Adapter 13 | */ 14 | public abstract class AdvanceAdapter extends RecyclerView.Adapter { 15 | 16 | public static final int MAX_HEADER_SIZE = 100; 17 | public static final int MAX_FOOTER_SIZE = 100; 18 | public static final int TYPE_HEADER_START = Integer.MAX_VALUE - MAX_HEADER_SIZE; 19 | public static final int TYPE_FOOTER_START = Integer.MIN_VALUE; 20 | 21 | private RecyclerView.Adapter childAdapter; 22 | private RecyclerView.LayoutManager layoutManager; 23 | private boolean isStaggered; 24 | 25 | /** 26 | * 适用于LinearLayoutManager 27 | * 28 | * @param childAdapter 被包裹的adapter 29 | */ 30 | public AdvanceAdapter(RecyclerView.Adapter childAdapter) { 31 | this(childAdapter, null); 32 | } 33 | 34 | /** 35 | * 适用于GridLayoutManager和StaggeredGridLayoutManager 36 | * 37 | * @param childAdapter 被包裹的adapter 38 | * @param layoutManager recyclerView的layoutManager 39 | */ 40 | public AdvanceAdapter(RecyclerView.Adapter childAdapter, RecyclerView.LayoutManager layoutManager) { 41 | this.childAdapter = childAdapter; 42 | this.layoutManager = layoutManager; 43 | if (layoutManager instanceof GridLayoutManager) { 44 | ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridSpanSizeLookup(this, (GridLayoutManager) layoutManager)); 45 | } else if (layoutManager instanceof StaggeredGridLayoutManager) { 46 | isStaggered = true; 47 | } 48 | } 49 | 50 | /** 51 | * Header的数量 52 | * 53 | * @return header count 54 | */ 55 | public abstract int headerCount(); 56 | 57 | /** 58 | * Footer的数量 59 | * 60 | * @return footer count 61 | */ 62 | public abstract int footerCount(); 63 | 64 | /** 65 | * 创建Header的Holder 66 | * 67 | * @param parent parent 68 | * @param viewType TYPE_HEADER_START~Integer.MAX_VALUE,代表Header顺序 69 | * @return holder 70 | */ 71 | public abstract RecyclerView.ViewHolder onHeaderCreateViewHolder(ViewGroup parent, int viewType); 72 | 73 | /** 74 | * 创建Footer的Holder 75 | * 76 | * @param parent parent 77 | * @param viewType TYPE_FOOTER_START~Integer.MIN_VALUE+MAX_FOOTER_SIZE,代表Footer的顺序 78 | * @return holder 79 | */ 80 | public abstract RecyclerView.ViewHolder onFooterCreateViewHolder(ViewGroup parent, int viewType); 81 | 82 | /** 83 | * 绑定Header 84 | * 85 | * @param holder holder 86 | * @param position position 0~MAX_HEADER_SIZE 87 | */ 88 | public abstract void onHeaderBindViewHolder(RecyclerView.ViewHolder holder, int position); 89 | 90 | /** 91 | * 绑定Footer 92 | * 93 | * @param holder holder 94 | * @param position position 0~MAX_FOOTER_SIZE 95 | */ 96 | public abstract void onFooterBindViewHolder(RecyclerView.ViewHolder holder, int position); 97 | 98 | protected int childItemCount() { 99 | return childAdapter == null ? 0 : childAdapter.getItemCount(); 100 | } 101 | 102 | protected RecyclerView.Adapter childAdapter() { 103 | return childAdapter; 104 | } 105 | 106 | 107 | @Override 108 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 109 | RecyclerView.ViewHolder holder; 110 | if (viewType >= TYPE_HEADER_START) { 111 | holder = onHeaderCreateViewHolder(parent, viewType - TYPE_HEADER_START); 112 | } else if (viewType <= TYPE_FOOTER_START + MAX_FOOTER_SIZE) { 113 | holder = onFooterCreateViewHolder(parent, viewType - TYPE_FOOTER_START); 114 | } else { 115 | holder = childAdapter.onCreateViewHolder(parent, viewType); 116 | } 117 | return holder; 118 | } 119 | 120 | @Override 121 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 122 | int headerPosition = headerCount(); 123 | if (position < headerPosition) { 124 | setStaggeredLayoutParams(holder); 125 | onHeaderBindViewHolder(holder, position); 126 | } else { 127 | int childPosition = headerPosition + childItemCount(); 128 | if (position < childPosition) { 129 | childAdapter.onBindViewHolder(holder, position - headerPosition); 130 | } else { 131 | setStaggeredLayoutParams(holder); 132 | onFooterBindViewHolder(holder, position - childPosition); 133 | } 134 | } 135 | } 136 | 137 | @Override 138 | public int getItemCount() { 139 | return headerCount() + childItemCount() + footerCount(); 140 | } 141 | 142 | @Override 143 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads) { 144 | if (position >= headerCount() && position < headerCount() + childItemCount()) { 145 | childAdapter.onBindViewHolder(holder, position - headerCount(), payloads); 146 | } else { 147 | super.onBindViewHolder(holder, position, payloads); 148 | } 149 | } 150 | 151 | @Override 152 | public int getItemViewType(int position) { 153 | int headerPosition = headerCount(); 154 | if (position < headerPosition) { 155 | return TYPE_HEADER_START + position; 156 | } else { 157 | int childPosition = headerPosition + childItemCount(); 158 | if (position < childPosition) { 159 | return childAdapter.getItemViewType(position - headerPosition); 160 | } else { 161 | return TYPE_FOOTER_START + (position - childPosition); 162 | } 163 | } 164 | } 165 | 166 | @Override 167 | public void setHasStableIds(boolean hasStableIds) { 168 | super.setHasStableIds(hasStableIds); 169 | childAdapter.setHasStableIds(hasStableIds); 170 | } 171 | 172 | @Override 173 | public long getItemId(int position) { 174 | if (position >= headerCount() && position < headerCount() + childItemCount()) { 175 | return childAdapter.getItemId(position - headerCount()); 176 | } 177 | return super.getItemId(position); 178 | } 179 | 180 | @Override 181 | public void onViewRecycled(RecyclerView.ViewHolder holder) { 182 | super.onViewRecycled(holder); 183 | childAdapter.onViewRecycled(holder); 184 | } 185 | 186 | @Override 187 | public boolean onFailedToRecycleView(RecyclerView.ViewHolder holder) { 188 | return childAdapter.onFailedToRecycleView(holder) && super.onFailedToRecycleView(holder); 189 | } 190 | 191 | @Override 192 | public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { 193 | super.onViewAttachedToWindow(holder); 194 | childAdapter.onViewAttachedToWindow(holder); 195 | } 196 | 197 | @Override 198 | public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) { 199 | super.onViewDetachedFromWindow(holder); 200 | childAdapter.onViewDetachedFromWindow(holder); 201 | } 202 | 203 | @Override 204 | public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) { 205 | super.registerAdapterDataObserver(observer); 206 | childAdapter.registerAdapterDataObserver(childObserver); 207 | } 208 | 209 | @Override 210 | public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) { 211 | childAdapter.unregisterAdapterDataObserver(childObserver); 212 | super.unregisterAdapterDataObserver(observer); 213 | } 214 | 215 | @Override 216 | public void onAttachedToRecyclerView(RecyclerView recyclerView) { 217 | super.onAttachedToRecyclerView(recyclerView); 218 | childAdapter.onAttachedToRecyclerView(recyclerView); 219 | } 220 | 221 | @Override 222 | public void onDetachedFromRecyclerView(RecyclerView recyclerView) { 223 | super.onDetachedFromRecyclerView(recyclerView); 224 | childAdapter.onDetachedFromRecyclerView(recyclerView); 225 | } 226 | 227 | 228 | private void setStaggeredLayoutParams(RecyclerView.ViewHolder holder) { 229 | if (isStaggered) { 230 | ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams(); 231 | if (layoutParams == null) { 232 | // 解决header或footer在没有layoutParam时显示不正确的情况 233 | StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) layoutManager.generateDefaultLayoutParams(); 234 | lp.setFullSpan(true); 235 | holder.itemView.setLayoutParams(lp); 236 | return; 237 | } 238 | if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) { 239 | ((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true); 240 | } 241 | } 242 | } 243 | 244 | private RecyclerView.AdapterDataObserver childObserver = new RecyclerView.AdapterDataObserver() { 245 | @Override 246 | public void onChanged() { 247 | super.onChanged(); 248 | notifyDataSetChanged(); 249 | } 250 | 251 | @Override 252 | public void onItemRangeChanged(int positionStart, int itemCount) { 253 | super.onItemRangeChanged(positionStart, itemCount); 254 | notifyItemRangeChanged(positionStart + headerCount(), itemCount); 255 | } 256 | 257 | @Override 258 | public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { 259 | super.onItemRangeChanged(positionStart, itemCount, payload); 260 | notifyItemRangeChanged(positionStart + headerCount(), itemCount, payload); 261 | } 262 | 263 | @Override 264 | public void onItemRangeInserted(int positionStart, int itemCount) { 265 | super.onItemRangeInserted(positionStart, itemCount); 266 | notifyItemRangeInserted(positionStart + headerCount(), itemCount); 267 | } 268 | 269 | @Override 270 | public void onItemRangeRemoved(int positionStart, int itemCount) { 271 | super.onItemRangeRemoved(positionStart, itemCount); 272 | notifyItemRangeRemoved(positionStart + headerCount(), itemCount); 273 | } 274 | 275 | @Override 276 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { 277 | super.onItemRangeMoved(fromPosition, toPosition, itemCount); 278 | notifyItemRangeChanged(fromPosition + headerCount(), toPosition + itemCount + headerCount()); 279 | } 280 | }; 281 | 282 | private static class GridSpanSizeLookup extends GridLayoutManager.SpanSizeLookup { 283 | 284 | private AdvanceAdapter advanceAdapter; 285 | private GridLayoutManager gridLayoutManager; 286 | 287 | public GridSpanSizeLookup(AdvanceAdapter advanceAdapter, GridLayoutManager gridLayoutManager) { 288 | this.advanceAdapter = advanceAdapter; 289 | this.gridLayoutManager = gridLayoutManager; 290 | } 291 | 292 | @Override 293 | public int getSpanSize(int position) { 294 | if (position < advanceAdapter.headerCount() || position >= advanceAdapter.headerCount() + advanceAdapter.childItemCount()) 295 | return gridLayoutManager.getSpanCount(); 296 | else 297 | return 1; 298 | } 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /advanceadapter/src/main/java/com/zzhoujay/advanceadapter/DynamicAdapter.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.util.Log; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | * Created by zhou on 16-3-24. 12 | * 动态添加Header和Footer的Adapter 13 | */ 14 | public class DynamicAdapter extends AdvanceAdapter { 15 | 16 | private ArrayList headers, footers; 17 | 18 | /** 19 | * 适用于LinearLayoutManager 20 | * @param childAdapter 被包裹的adapter 21 | */ 22 | public DynamicAdapter(RecyclerView.Adapter childAdapter) { 23 | super(childAdapter); 24 | init(); 25 | } 26 | 27 | /** 28 | * 适用于GridLayoutManager和StaggeredGridLayoutManager 29 | * @param childAdapter 被包裹的adapter 30 | * @param layoutManager recyclerView的layoutManager 31 | */ 32 | public DynamicAdapter(RecyclerView.Adapter childAdapter, RecyclerView.LayoutManager layoutManager) { 33 | super(childAdapter, layoutManager); 34 | init(); 35 | } 36 | 37 | private void init() { 38 | headers = new ArrayList<>(); 39 | footers = new ArrayList<>(); 40 | } 41 | 42 | public void addHeaderView(View header) { 43 | headers.add(header); 44 | notifyItemInserted(headerCount() - 1); 45 | } 46 | 47 | public void addFooterView(View footer) { 48 | footers.add(footer); 49 | notifyItemInserted(getItemCount() - 1); 50 | } 51 | 52 | public boolean removeHeaderView(View header) { 53 | boolean flag = headers.remove(header); 54 | notifyItemRemoved(headerCount()); 55 | return flag; 56 | } 57 | 58 | public boolean removeFooterView(View footer) { 59 | boolean flag = footers.remove(footer); 60 | notifyItemRemoved(getItemCount()); 61 | return flag; 62 | } 63 | 64 | @Override 65 | public int headerCount() { 66 | return headers.size(); 67 | } 68 | 69 | @Override 70 | public int footerCount() { 71 | return footers.size(); 72 | } 73 | 74 | @Override 75 | public RecyclerView.ViewHolder onHeaderCreateViewHolder(ViewGroup parent, int viewType) { 76 | return new Holder(headers.get(viewType)); 77 | } 78 | 79 | @Override 80 | public RecyclerView.ViewHolder onFooterCreateViewHolder(ViewGroup parent, int viewType) { 81 | return new Holder(footers.get(viewType)); 82 | } 83 | 84 | @Override 85 | public void onHeaderBindViewHolder(RecyclerView.ViewHolder holder, int position) { 86 | 87 | } 88 | 89 | @Override 90 | public void onFooterBindViewHolder(RecyclerView.ViewHolder holder, int position) { 91 | 92 | } 93 | 94 | public static class Holder extends RecyclerView.ViewHolder { 95 | 96 | public Holder(View itemView) { 97 | super(itemView); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /advanceadapter/src/main/java/com/zzhoujay/advanceadapter/SingleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | /** 8 | * Created by zhou on 16-3-24. 9 | * 只含有单个Header和Footer的Adapter 10 | */ 11 | public class SingleAdapter extends AdvanceAdapter { 12 | 13 | private View headerView, footerView; 14 | 15 | /** 16 | * 适用于LinearLayoutManager 17 | * @param childAdapter 被包裹的adapter 18 | */ 19 | public SingleAdapter(RecyclerView.Adapter childAdapter) { 20 | super(childAdapter); 21 | } 22 | 23 | /** 24 | * 适用于GridLayoutManager和StaggeredGridLayoutManager 25 | * @param childAdapter 被包裹的adapter 26 | * @param layoutManager recyclerView的layoutManager 27 | */ 28 | public SingleAdapter(RecyclerView.Adapter childAdapter, RecyclerView.LayoutManager layoutManager) { 29 | super(childAdapter, layoutManager); 30 | } 31 | 32 | public View getHeaderView() { 33 | return headerView; 34 | } 35 | 36 | public void setHeaderView(View headerView) { 37 | if (this.headerView != null) { 38 | this.headerView = headerView; 39 | if (headerView == null) { 40 | notifyItemRemoved(0); 41 | } else { 42 | notifyItemChanged(0); 43 | } 44 | } else { 45 | this.headerView = headerView; 46 | notifyItemInserted(0); 47 | } 48 | } 49 | 50 | public View getFooterView() { 51 | return footerView; 52 | } 53 | 54 | public void setFooterView(View footerView) { 55 | if (this.footerView != null) { 56 | this.footerView = footerView; 57 | if (footerView == null) { 58 | notifyItemRemoved(getItemCount()); 59 | } else { 60 | notifyItemChanged(getItemCount() - 1); 61 | } 62 | } else { 63 | this.footerView = footerView; 64 | notifyItemInserted(getItemCount() - 1); 65 | } 66 | } 67 | 68 | @Override 69 | public int headerCount() { 70 | return headerView == null ? 0 : 1; 71 | } 72 | 73 | @Override 74 | public int footerCount() { 75 | return footerView == null ? 0 : 1; 76 | } 77 | 78 | @Override 79 | public RecyclerView.ViewHolder onHeaderCreateViewHolder(ViewGroup parent, int viewType) { 80 | return new Holder(headerView); 81 | } 82 | 83 | @Override 84 | public RecyclerView.ViewHolder onFooterCreateViewHolder(ViewGroup parent, int viewType) { 85 | return new Holder(footerView); 86 | } 87 | 88 | @Override 89 | public void onHeaderBindViewHolder(RecyclerView.ViewHolder holder, int position) { 90 | 91 | } 92 | 93 | @Override 94 | public void onFooterBindViewHolder(RecyclerView.ViewHolder holder, int position) { 95 | 96 | } 97 | 98 | public static class Holder extends RecyclerView.ViewHolder { 99 | 100 | public Holder(View itemView) { 101 | super(itemView); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /advanceadapter/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AdvanceAdapter 3 | 4 | -------------------------------------------------------------------------------- /advanceadapter/src/test/java/com/zzhoujay/advanceadapter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadapter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /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:1.5.0' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 10 | classpath 'com.github.dcendents:android-maven-plugin:1.2' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /build/intermediates/dex-cache/cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 23 | 24 | 25 | 30 | 31 | 32 | 37 | 38 | 39 | 44 | 45 | 46 | 51 | 52 | 53 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /build/intermediates/gradle_project_sync_data.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/build/intermediates/gradle_project_sync_data.bin -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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.2.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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /images/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/images/image1.png -------------------------------------------------------------------------------- /images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/images/image2.png -------------------------------------------------------------------------------- /images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/images/image3.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':advanceadapter', ':simple' 2 | -------------------------------------------------------------------------------- /simple/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /simple/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.zzhoujay.advanceadaptersimple" 9 | minSdkVersion 8 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | repositories { 23 | maven { 24 | url "http://dl.bintray.com/zzhoujay/maven" 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(include: ['*.jar'], dir: 'libs') 30 | testCompile 'junit:junit:4.12' 31 | compile 'com.android.support:appcompat-v7:23.2.1' 32 | compile 'com.android.support:recyclerview-v7:23.2.1' 33 | // compile project(':advanceadapter') 34 | compile 'com.zzhoujay.advanceadapter:advanceadapter:1.0.2' 35 | // compile 'com.zzhoujay.advanceadapter:advanceadapter:1.0.0' 36 | } 37 | -------------------------------------------------------------------------------- /simple/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 /home/zhou/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 | -------------------------------------------------------------------------------- /simple/src/androidTest/java/com/zzhoujay/advanceadaptersimple/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadaptersimple; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /simple/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /simple/src/main/java/com/zzhoujay/advanceadaptersimple/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadaptersimple; 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.Menu; 9 | import android.view.MenuItem; 10 | import android.view.View; 11 | 12 | import com.zzhoujay.advanceadapter.DynamicAdapter; 13 | 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | DynamicAdapter dynamicAdapter; 18 | View h; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 25 | 26 | RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); 27 | 28 | if (recyclerView != null) { 29 | recyclerView.setLayoutManager(layoutManager); 30 | } 31 | 32 | assert recyclerView != null; 33 | 34 | final NormalAdapter normalAdapter = new NormalAdapter(20); 35 | dynamicAdapter = new DynamicAdapter(normalAdapter, layoutManager); 36 | 37 | normalAdapter.setCallback(new NormalAdapter.Callback() { 38 | @Override 39 | public void call(int index) { 40 | normalAdapter.setNum(index - dynamicAdapter.headerCount()); 41 | } 42 | }); 43 | 44 | View header = getLayoutInflater().inflate(R.layout.header, null); 45 | View header2 = getLayoutInflater().inflate(R.layout.header, null); 46 | View footer = getLayoutInflater().inflate(R.layout.footer, null); 47 | View footer2 = getLayoutInflater().inflate(R.layout.footer, null); 48 | dynamicAdapter.addHeaderView(header); 49 | dynamicAdapter.addHeaderView(header2); 50 | dynamicAdapter.addFooterView(footer); 51 | dynamicAdapter.addFooterView(footer2); 52 | // 53 | recyclerView.setAdapter(dynamicAdapter); 54 | 55 | 56 | } 57 | 58 | @Override 59 | public boolean onCreateOptionsMenu(Menu menu) { 60 | menu.add(0, 0, 0, "add"); 61 | menu.add(0, 1, 1, "remove"); 62 | return super.onCreateOptionsMenu(menu); 63 | } 64 | 65 | @Override 66 | public boolean onOptionsItemSelected(MenuItem item) { 67 | switch (item.getItemId()) { 68 | case 0: 69 | h = LayoutInflater.from(this).inflate(R.layout.header, null); 70 | dynamicAdapter.addFooterView(h); 71 | break; 72 | case 1: 73 | dynamicAdapter.removeFooterView(h); 74 | } 75 | return super.onOptionsItemSelected(item); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /simple/src/main/java/com/zzhoujay/advanceadaptersimple/NormalAdapter.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadaptersimple; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import java.util.ArrayList; 10 | 11 | /** 12 | * Created by zzhoujay on 2015/7/22 0022. 13 | */ 14 | public class NormalAdapter extends RecyclerView.Adapter { 15 | 16 | private int size; 17 | 18 | private ArrayList nums; 19 | 20 | public NormalAdapter(int size) { 21 | this.size = size; 22 | nums = new ArrayList<>(size); 23 | for (int i = 0; i < size; i++) { 24 | nums.add(i); 25 | } 26 | } 27 | 28 | private Callback callback; 29 | 30 | @Override 31 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false); 33 | Holder holder = new Holder(view); 34 | holder.setCallback(new Callback() { 35 | @Override 36 | public void call(int index) { 37 | if (callback != null) { 38 | callback.call(index); 39 | } 40 | } 41 | }); 42 | return holder; 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 47 | if (holder instanceof Holder) { 48 | // ViewGroup.LayoutParams layoutParams = ((Holder) holder).view.getLayoutParams(); 49 | // layoutParams.height = (position % 5) * 30 + 200; 50 | // if(position>=getItemCount()){ 51 | // System.out.println("gg"); 52 | // } 53 | ((Holder) holder).view.setText("" + nums.get(position)); 54 | } 55 | } 56 | 57 | @Override 58 | public int getItemCount() { 59 | return nums.size(); 60 | } 61 | 62 | public static class Holder extends RecyclerView.ViewHolder { 63 | 64 | public TextView view; 65 | 66 | private Callback callback; 67 | 68 | public Holder(View itemView) { 69 | super(itemView); 70 | 71 | view = (TextView) itemView.findViewById(R.id.view); 72 | 73 | view.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | if (callback != null) { 77 | callback.call(getAdapterPosition()); 78 | } 79 | } 80 | }); 81 | } 82 | 83 | public void setCallback(Callback callback) { 84 | this.callback = callback; 85 | } 86 | } 87 | 88 | public void setCallback(Callback callback) { 89 | this.callback = callback; 90 | } 91 | 92 | public void setNum(int index) { 93 | // nums.set(index, nums.get(index) + 1); 94 | nums.remove(index); 95 | notifyItemRemoved(index); 96 | } 97 | 98 | public interface Callback { 99 | void call(int index); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /simple/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /simple/src/main/res/layout/footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /simple/src/main/res/layout/header.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /simple/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /simple/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/simple/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /simple/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/simple/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /simple/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/simple/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /simple/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/simple/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzhoujay/AdvanceAdapter/73a629787e9b7fcc196b322680482676b8a8b306/simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /simple/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /simple/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /simple/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /simple/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AdvanceAdapterSimple 3 | 4 | -------------------------------------------------------------------------------- /simple/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /simple/src/test/java/com/zzhoujay/advanceadaptersimple/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zzhoujay.advanceadaptersimple; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } --------------------------------------------------------------------------------