├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── adapterflowlayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── commit451 │ └── adapterflowlayout │ └── AdapterFlowLayout.java ├── adapterlayout-kotlin ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── commit451 │ └── adapterlayout │ └── kotlin │ └── kotlin.kt ├── adapterlayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── commit451 │ │ └── adapterlayout │ │ ├── AdapterLayout.java │ │ ├── AdapterLayoutDelegate.java │ │ └── AdapterLinearLayout.java │ └── res │ └── values │ └── ids.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── commit451 │ │ └── adapterlayout │ │ └── sample │ │ ├── AdapterFlowLayoutActivity.kt │ │ ├── Cheese.kt │ │ ├── CheeseAdapter.kt │ │ ├── CheeseViewHolder.kt │ │ ├── Cheeses.kt │ │ └── MainActivity.kt │ └── res │ ├── drawable-nodpi │ ├── cheese_1.jpg │ ├── cheese_2.jpg │ ├── cheese_3.jpg │ ├── cheese_4.jpg │ └── cheese_5.jpg │ ├── drawable │ ├── ic_arrow_back_24dp.xml │ └── ic_close_white_24dp.xml │ ├── layout │ ├── activity_custom_adapter_layout.xml │ ├── activity_main.xml │ └── item_cheese.xml │ ├── menu │ └── main.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 ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Android ### 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | 29 | ### Intellij ### 30 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 31 | 32 | *.iml 33 | 34 | ## Directory-based project format: 35 | .idea/ 36 | # if you remove the above rule, at least ignore the following: 37 | 38 | # User-specific stuff: 39 | # .idea/workspace.xml 40 | # .idea/tasks.xml 41 | # .idea/dictionaries 42 | 43 | # Sensitive or high-churn files: 44 | # .idea/dataSources.ids 45 | # .idea/dataSources.xml 46 | # .idea/sqlDataSources.xml 47 | # .idea/dynamic.xml 48 | # .idea/uiDesigner.xml 49 | 50 | # Gradle: 51 | # .idea/gradle.xml 52 | # .idea/libraries 53 | 54 | # Mongo Explorer plugin: 55 | # .idea/mongoSettings.xml 56 | 57 | ## File-based project format: 58 | *.ipr 59 | *.iws 60 | 61 | ## Plugin-specific files: 62 | 63 | # IntelliJ 64 | out/ 65 | 66 | # mpeltonen/sbt-idea plugin 67 | .idea_modules/ 68 | 69 | # JIRA plugin 70 | atlassian-ide-plugin.xml 71 | 72 | # Crashlytics plugin (for Android Studio and IntelliJ) 73 | com_crashlytics_export_strings.xml 74 | 75 | # Ignore Gradle GUI config 76 | gradle-app.setting 77 | 78 | # Mobile Tools for Java (J2ME) 79 | .mtj.tmp/ 80 | 81 | # Package Files # 82 | *.war 83 | *.ear 84 | 85 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 86 | hs_err_pid* 87 | 88 | *.DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | before_install: 7 | - chmod +x gradlew 8 | - mkdir "$ANDROID_HOME/licenses" || true 9 | - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" 10 | 11 | script: "./gradlew build" 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AdapterLayout 2 | ViewGroup backed by RecyclerView.Adapter, allowing for easy data set manipulation with non recycling views. Aka RecyclerView minus the recycling. 3 | 4 | [![Build Status](https://travis-ci.org/Commit451/AdapterLayout.svg?branch=master)](https://travis-ci.org/Commit451/AdapterLayout) [![](https://jitpack.io/v/Commit451/AdapterLayout.svg)](https://jitpack.io/#Commit451/AdapterLayout) 5 | 6 | # Dependency 7 | ```gradle 8 | allprojects { 9 | repositories { 10 | maven { url "https://jitpack.io" } 11 | } 12 | } 13 | ``` 14 | and within your application `build.gradle` 15 | 16 | ```gradle 17 | dependencies { 18 | implementation 'com.github.Commit451.AdapterLayout:adapterlayout:latest.release.here' 19 | } 20 | ``` 21 | and for [FlowLayout](https://github.com/blazsolar/FlowLayout) support: 22 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.wefika/flowlayout/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.wefika/flowlayout) 23 | ```gradle 24 | dependencies { 25 | //add the latest of FlowLayout 26 | implementation 'com.wefika:flowlayout:latest.release.here' 27 | implementation 'com.github.Commit451.AdapterLayout:adapterflowlayout:latest.release.here' 28 | } 29 | ``` 30 | and for Kotlin extensions support: 31 | ```gradle 32 | dependencies { 33 | implementation 'com.github.Commit451.AdapterLayout:adapterlayout-kotlin:latest.release.here' 34 | } 35 | ``` 36 | 37 | # Usage 38 | See the sample project for full usage. 39 | ```java 40 | //CheeseAdapter is a RecyclerView adapter 41 | CheeseAdapter cheeseAdapter = new CheeseAdapter(); 42 | adapterLinearLayout adapterLinearLayout = (AdapterLinearLayout) findViewById(R.id.adapter_linear_layout); 43 | adapterLinearLayout.setAdapter(cheeseAdapter); 44 | ``` 45 | Later, when you get your data set: 46 | ```java 47 | ArrayList cheeses = loadCheeses(); 48 | //addAll is a method in our custom RecyclerView.Adapter 49 | cheeseAdapter.addAll(cheeses); 50 | ``` 51 | At this point, the data will be added to the `LinearLayout` so long as your `RecyclerView.Adapter` works correctly. `onCreateViewHolder` and `onBindViewHolder` will be called as needed. 52 | 53 | ## But... Why? 54 | This library is useful for displaying data sets that are repeating, but do not need to be recycled as they would be in a `RecyclerView`. This could be the case if you wanted to display a list of items within a `ScrollView`, or wanted to use a custom `ViewGroup` that did not extend `RecyclerView`. 55 | 56 | ## But Why RecyclerView Adapter? 57 | Most developers should be using `RecyclerView` instead of `ListView` and should be familiar with creating a `RecyclerView.Adapter`. `RecyclerView.Adapter` also enforces the use of `ViewHolder`s which is better for performance. RecyclerView's adapter also allows for better responses to data structure changes via `notifyItemInserted`, `notifyItemRemoved` etc. 58 | 59 | ## Currently Created AdapterLayouts 60 | - AdapterLinearLayout 61 | - AdapterFlowLayout (separate dependency) 62 | 63 | ## Creating Your Own AdapterLayout 64 | It is simple to create your own `ViewGroup` backed by a `RecyclerView.Adapter`. See the `AdapterFlowLayout` library and `AdapterLayoutDelegate` in the library for an example of how to create one. 65 | 66 | # Limitations 67 | - Within a `RecyclerView.Adapter`, you can call `getAdapterPosition()`. This will always return -1 since there is actually never an associated RecyclerView. Instead, you can call `AdapterLayout.getAdapterPosition(holder)` to get the position of the `ViewHolder` within the adapter. 68 | 69 | License 70 | -------- 71 | 72 | Copyright 2018 Commit 451 73 | 74 | Licensed under the Apache License, Version 2.0 (the "License"); 75 | you may not use this file except in compliance with the License. 76 | You may obtain a copy of the License at 77 | 78 | http://www.apache.org/licenses/LICENSE-2.0 79 | 80 | Unless required by applicable law or agreed to in writing, software 81 | distributed under the License is distributed on an "AS IS" BASIS, 82 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 83 | See the License for the specific language governing permissions and 84 | limitations under the License. 85 | -------------------------------------------------------------------------------- /adapterflowlayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /adapterflowlayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | 6 | defaultConfig { 7 | minSdkVersion rootProject.ext.minSdkVersion 8 | targetSdkVersion rootProject.ext.targetSdkVersion 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | lintOptions { 19 | abortOnError false 20 | } 21 | } 22 | 23 | dependencies { 24 | compileOnly("com.wefika:flowlayout:0.4.1") { 25 | exclude group: 'com.intellij', module: 'annotations' 26 | } 27 | compileOnly project(':adapterlayout') 28 | } 29 | 30 | apply from: 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle' 31 | -------------------------------------------------------------------------------- /adapterflowlayout/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/Jawn/Develop/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 | -------------------------------------------------------------------------------- /adapterflowlayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /adapterflowlayout/src/main/java/com/commit451/adapterflowlayout/AdapterFlowLayout.java: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterflowlayout; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.commit451.adapterlayout.AdapterLayoutDelegate; 7 | import com.wefika.flowlayout.FlowLayout; 8 | 9 | import androidx.annotation.Nullable; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | 12 | /** 13 | * {@link com.wefika.flowlayout.FlowLayout} with {@link androidx.recyclerview.widget.RecyclerView.Adapter} support. 14 | */ 15 | @SuppressWarnings("unused") 16 | public class AdapterFlowLayout extends FlowLayout { 17 | 18 | private AdapterLayoutDelegate adapterLayoutDelegate; 19 | 20 | public AdapterFlowLayout(Context context) { 21 | super(context); 22 | } 23 | 24 | public AdapterFlowLayout(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | public AdapterFlowLayout(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | } 31 | 32 | public void setAdapter(RecyclerView.Adapter adapter) { 33 | if (adapterLayoutDelegate == null) { 34 | adapterLayoutDelegate = new AdapterLayoutDelegate(this); 35 | } 36 | adapterLayoutDelegate.setAdapter(adapter); 37 | } 38 | 39 | @Nullable 40 | public RecyclerView.Adapter getAdapter() { 41 | if (adapterLayoutDelegate != null) { 42 | return adapterLayoutDelegate.getAdapter(); 43 | } 44 | return null; 45 | } 46 | 47 | @Nullable 48 | public RecyclerView.ViewHolder getViewHolderAt(int index) { 49 | if (adapterLayoutDelegate != null) { 50 | return adapterLayoutDelegate.getViewHolderAt(index); 51 | } 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /adapterlayout-kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /adapterlayout-kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion rootProject.ext.compileSdkVersion 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.minSdkVersion 9 | targetSdkVersion rootProject.ext.targetSdkVersion 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | lintOptions { 20 | abortOnError false 21 | } 22 | } 23 | 24 | dependencies { 25 | api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 26 | 27 | compileOnly project(':adapterlayout') 28 | } 29 | -------------------------------------------------------------------------------- /adapterlayout-kotlin/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/johncarlson/Develop/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 | -------------------------------------------------------------------------------- /adapterlayout-kotlin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /adapterlayout-kotlin/src/main/java/com/commit451/adapterlayout/kotlin/kotlin.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.commit451.adapterlayout.kotlin 4 | 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.commit451.adapterlayout.AdapterLayout 7 | 8 | fun RecyclerView.ViewHolder.getAdapterLayoutAdapterPosition(): Int { 9 | return AdapterLayout.getAdapterPosition(this) 10 | } 11 | 12 | fun RecyclerView.ViewHolder.getAdapterLayoutLayoutPosition(): Int { 13 | return AdapterLayout.getLayoutPosition(this) 14 | } 15 | -------------------------------------------------------------------------------- /adapterlayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /adapterlayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | 6 | defaultConfig { 7 | minSdkVersion rootProject.ext.minSdkVersion 8 | targetSdkVersion rootProject.ext.targetSdkVersion 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | lintOptions { 19 | abortOnError false 20 | } 21 | } 22 | 23 | dependencies { 24 | api "androidx.recyclerview:recyclerview:1.1.0" 25 | } 26 | 27 | apply from: 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle' 28 | -------------------------------------------------------------------------------- /adapterlayout/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 C:\Users\Jawn\Develop\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 | -------------------------------------------------------------------------------- /adapterlayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /adapterlayout/src/main/java/com/commit451/adapterlayout/AdapterLayout.java: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | 5 | /** 6 | * Provides access to some of the public API of AdapterLayout in a way that will be available for any given 7 | * AdapterLayout 8 | */ 9 | public class AdapterLayout { 10 | 11 | /** 12 | * Get the position in the AdapterLayout of the View holder. 13 | * Use this instead of {@link RecyclerView.ViewHolder#getAdapterPosition()} 14 | * 15 | * @param viewHolder the holder to find the position of 16 | * @return the index of the holder, or -1 if not found 17 | */ 18 | public static int getAdapterPosition(RecyclerView.ViewHolder viewHolder) { 19 | return getPosition(viewHolder); 20 | } 21 | 22 | /** 23 | * Get the position in the AdapterLayout of the View holder. 24 | * Use this instead of {@link RecyclerView.ViewHolder#getLayoutPosition()} 25 | * 26 | * @param viewHolder the holder to find the position of 27 | * @return the index of the holder, or -1 if not found 28 | */ 29 | public static int getLayoutPosition(RecyclerView.ViewHolder viewHolder) { 30 | return getPosition(viewHolder); 31 | } 32 | 33 | private static int getPosition(RecyclerView.ViewHolder viewHolder) { 34 | return (int) viewHolder.itemView.getTag(R.id.adapter_layout_list_position); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /adapterlayout/src/main/java/com/commit451/adapterlayout/AdapterLayoutDelegate.java: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | import androidx.annotation.Nullable; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | /** 10 | * Does all the hard to work to map a {@link androidx.recyclerview.widget.RecyclerView.Adapter} to a 11 | * {@link ViewGroup}. See {@link AdapterLinearLayout} for an example on how to create your own 12 | */ 13 | public class AdapterLayoutDelegate { 14 | 15 | private RecyclerView.Adapter adapter; 16 | private ViewGroup viewGroup; 17 | 18 | /** 19 | * Checks for if the data changes and changes the views accordingly 20 | */ 21 | private RecyclerView.AdapterDataObserver observer = new RecyclerView.AdapterDataObserver() { 22 | @Override 23 | public void onChanged() { 24 | super.onChanged(); 25 | //too general, we just have to completely recreate 26 | recreateViews(); 27 | reindex(); 28 | } 29 | 30 | @Override 31 | public void onItemRangeChanged(int positionStart, int itemCount) { 32 | super.onItemRangeChanged(positionStart, itemCount); 33 | updateViews(positionStart, itemCount); 34 | reindex(); 35 | } 36 | 37 | @Override 38 | public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { 39 | super.onItemRangeChanged(positionStart, itemCount, payload); 40 | updateViews(positionStart, itemCount); 41 | reindex(); 42 | } 43 | 44 | @Override 45 | public void onItemRangeInserted(int positionStart, int itemCount) { 46 | super.onItemRangeInserted(positionStart, itemCount); 47 | addViews(positionStart, itemCount); 48 | reindex(); 49 | } 50 | 51 | @Override 52 | public void onItemRangeRemoved(int positionStart, int itemCount) { 53 | super.onItemRangeRemoved(positionStart, itemCount); 54 | removeViews(positionStart, itemCount); 55 | reindex(); 56 | } 57 | 58 | @Override 59 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { 60 | super.onItemRangeMoved(fromPosition, toPosition, itemCount); 61 | // this should probably be smarter and just move relevant views 62 | recreateViews(); 63 | reindex(); 64 | } 65 | }; 66 | 67 | /** 68 | * Create a new delegate, acting as the bridge between the adapter and the ViewGroup 69 | * 70 | * @param viewGroup the ViewGroup which will have views added and removed from 71 | */ 72 | public AdapterLayoutDelegate(ViewGroup viewGroup) { 73 | this.viewGroup = viewGroup; 74 | } 75 | 76 | /** 77 | * Set the adapter which will add and remove views from this layout 78 | * 79 | * @param adapter the adapter 80 | */ 81 | public void setAdapter(@Nullable RecyclerView.Adapter adapter) { 82 | if (this.adapter != null) { 83 | try { 84 | this.adapter.unregisterAdapterDataObserver(observer); 85 | } catch (Exception ignored) { 86 | } 87 | } 88 | 89 | this.adapter = adapter; 90 | if (this.adapter != null) { 91 | this.adapter.registerAdapterDataObserver(observer); 92 | } 93 | recreateViews(); 94 | } 95 | 96 | /** 97 | * Returns the adapter which was passed via {@link #setAdapter(RecyclerView.Adapter)} 98 | * 99 | * @return the adapter 100 | */ 101 | public RecyclerView.Adapter getAdapter() { 102 | return adapter; 103 | } 104 | 105 | /** 106 | * Return the {@link RecyclerView.ViewHolder} at the specified position. 107 | * 108 | * @param index the position at which to get the ViewHolder 109 | * @return the ViewHolder at the index, or null if none exists 110 | */ 111 | @Nullable 112 | public RecyclerView.ViewHolder getViewHolderAt(int index) { 113 | View view = viewGroup.getChildAt(index); 114 | if (view == null) { 115 | return null; 116 | } 117 | return (RecyclerView.ViewHolder) view.getTag(R.id.adapter_layout_list_holder); 118 | } 119 | 120 | private void addViews(int positionStart, int itemCount) { 121 | final int end = positionStart + itemCount; 122 | for (int i = positionStart; i < end; i++) { 123 | addViewAt(i); 124 | } 125 | } 126 | 127 | private void addViewAt(int index) { 128 | addViewAt(adapter.getItemViewType(index), index); 129 | } 130 | 131 | private void addViewAt(int viewType, int index) { 132 | RecyclerView.ViewHolder viewHolder = adapter.onCreateViewHolder(viewGroup, viewType); 133 | //setting the lib to min 4.0 to avoid leaks from doing this 134 | viewHolder.itemView.setTag(R.id.adapter_layout_list_holder, viewHolder); 135 | viewHolder.itemView.setTag(R.id.adapter_layout_list_view_type, viewType); 136 | viewHolder.itemView.setTag(R.id.adapter_layout_list_position, index); 137 | viewGroup.addView(viewHolder.itemView); 138 | //noinspection unchecked 139 | adapter.onBindViewHolder(viewHolder, index); 140 | } 141 | 142 | private void updateViews(int positionStart, int itemCount) { 143 | final int end = positionStart + itemCount; 144 | for (int i = positionStart; i < end; i++) { 145 | RecyclerView.ViewHolder viewHolder = getViewHolderAt(i); 146 | //noinspection unchecked 147 | adapter.onBindViewHolder(viewHolder, i); 148 | } 149 | } 150 | 151 | private void removeViews(int positionStart, int itemCount) { 152 | viewGroup.removeViews(positionStart, itemCount); 153 | } 154 | 155 | /** 156 | * Updates all the views to match the dataset changing. Its kinda a last resort since we would 157 | * prefer to just adjust the views that were changed or removed 158 | */ 159 | private void recreateViews() { 160 | if (adapter == null) { 161 | viewGroup.removeAllViews(); 162 | return; 163 | } 164 | int i; 165 | for (i = 0; i < adapter.getItemCount(); i++) { 166 | int viewType = adapter.getItemViewType(i); 167 | //This means the view could already exist 168 | if (i < viewGroup.getChildCount()) { 169 | View child = viewGroup.getChildAt(i); 170 | Integer savedViewType = (Integer) child.getTag(R.id.adapter_layout_list_view_type); 171 | RecyclerView.ViewHolder savedViewHolder = (RecyclerView.ViewHolder) child.getTag(R.id.adapter_layout_list_holder); 172 | 173 | if (savedViewType != null && savedViewType == viewType && savedViewHolder != null) { 174 | //perfect, it exists and is the right type, so just bind it 175 | //noinspection unchecked 176 | adapter.onBindViewHolder(savedViewHolder, i); 177 | } else { 178 | //it already existed, but something was wrong. So remove it and recreate it 179 | addViewAt(viewType, i); 180 | viewGroup.removeView(child); 181 | } 182 | } else { 183 | //Creating a brand new view 184 | addViewAt(viewType, i); 185 | } 186 | } 187 | 188 | //Outside the bounds of the dataset, so remove it 189 | if (i < viewGroup.getChildCount()) { 190 | viewGroup.removeViews(i, viewGroup.getChildCount() - i); 191 | } 192 | } 193 | 194 | private void reindex() { 195 | for (int i = 0; i < adapter.getItemCount(); i++) { 196 | View child = viewGroup.getChildAt(i); 197 | child.setTag(R.id.adapter_layout_list_position, i); 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /adapterlayout/src/main/java/com/commit451/adapterlayout/AdapterLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.widget.Adapter; 8 | import android.widget.LinearLayout; 9 | 10 | import androidx.annotation.Nullable; 11 | import androidx.recyclerview.widget.RecyclerView; 12 | 13 | /** 14 | * LinearLayout with {@link Adapter} support. See {@link AdapterLayoutDelegate} for 15 | * the good bits, and follow the convention here to create your own {@link RecyclerView.Adapter} 16 | * backed {@link android.view.ViewGroup} 17 | */ 18 | @SuppressWarnings("unused") 19 | public class AdapterLinearLayout extends LinearLayout { 20 | 21 | private AdapterLayoutDelegate adapterLayoutDelegate; 22 | 23 | public AdapterLinearLayout(Context context) { 24 | super(context); 25 | } 26 | 27 | public AdapterLinearLayout(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 32 | public AdapterLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | } 35 | 36 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 37 | public AdapterLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 38 | super(context, attrs, defStyleAttr, defStyleRes); 39 | } 40 | 41 | public void setAdapter(RecyclerView.Adapter adapter) { 42 | if (adapterLayoutDelegate == null) { 43 | adapterLayoutDelegate = new AdapterLayoutDelegate(this); 44 | } 45 | adapterLayoutDelegate.setAdapter(adapter); 46 | } 47 | 48 | @Nullable 49 | public RecyclerView.Adapter getAdapter() { 50 | if (adapterLayoutDelegate != null) { 51 | return adapterLayoutDelegate.getAdapter(); 52 | } 53 | return null; 54 | } 55 | 56 | @Nullable 57 | public RecyclerView.ViewHolder getViewHolderAt(int index) { 58 | if (adapterLayoutDelegate != null) { 59 | return adapterLayoutDelegate.getViewHolderAt(index); 60 | } 61 | return null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /adapterlayout/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.compileSdkVersion 7 | 8 | defaultConfig { 9 | applicationId "com.commit451.adapterlayout.sample" 10 | minSdkVersion rootProject.ext.minSdkVersion 11 | targetSdkVersion rootProject.ext.targetSdkVersion 12 | versionCode 1 13 | versionName "1.0" 14 | vectorDrawables.useSupportLibrary = true 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | lintOptions { 23 | abortOnError false 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 29 | implementation "androidx.appcompat:appcompat:1.2.0" 30 | implementation "com.google.android.material:material:1.2.1" 31 | 32 | implementation("com.wefika:flowlayout:0.4.1") { 33 | exclude group: 'com.intellij', module: 'annotations' 34 | } 35 | 36 | implementation project(':adapterlayout') 37 | 38 | implementation project(':adapterflowlayout') 39 | } 40 | -------------------------------------------------------------------------------- /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 C:\Users\Jawn\Develop\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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/AdapterFlowLayoutActivity.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.widget.Toast 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.appcompat.widget.Toolbar 8 | import com.commit451.adapterflowlayout.AdapterFlowLayout 9 | import java.util.* 10 | 11 | class AdapterFlowLayoutActivity : AppCompatActivity() { 12 | 13 | private lateinit var toolbar: Toolbar 14 | private lateinit var adapterFlowLayout: AdapterFlowLayout 15 | 16 | private lateinit var adapter: CheeseAdapter 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | val listener = { cheese: Cheese -> 21 | Toast.makeText(this, "${cheese.name} clicked", Toast.LENGTH_SHORT) 22 | .show() 23 | } 24 | setContentView(R.layout.activity_custom_adapter_layout) 25 | toolbar = findViewById(R.id.toolbar) 26 | adapterFlowLayout = findViewById(R.id.adapter_layout) 27 | toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24dp) 28 | toolbar.setNavigationOnClickListener { onBackPressed() } 29 | adapter = CheeseAdapter(listener) 30 | adapterFlowLayout.adapter = adapter 31 | 32 | findViewById(R.id.add_cheese).setOnClickListener { adapter.add(Cheeses.randomCheese) } 33 | findViewById(R.id.remove_cheese).setOnClickListener { adapter.removeLast() } 34 | findViewById(R.id.new_adapter).setOnClickListener { 35 | adapterFlowLayout.adapter = null 36 | adapter = CheeseAdapter(listener) 37 | adapterFlowLayout.adapter = adapter 38 | } 39 | loadCheeses() 40 | } 41 | 42 | private fun loadCheeses() { 43 | val cheeses = ArrayList() 44 | for (i in 0..4) { 45 | cheeses.add(Cheeses.randomCheese) 46 | } 47 | adapter.setData(cheeses) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/Cheese.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | /** 4 | * A fake model to show usage 5 | */ 6 | data class Cheese( 7 | val drawable: Int, 8 | var name: String 9 | ) 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/CheeseAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | import android.view.ViewGroup 4 | import androidx.recyclerview.widget.RecyclerView 5 | import com.commit451.adapterlayout.AdapterLayout 6 | 7 | /** 8 | * Adapter for the recyclerview, which holds cheeses 9 | */ 10 | class CheeseAdapter(private val listener: (cheese: Cheese) -> Unit) : RecyclerView.Adapter() { 11 | 12 | private val values = mutableListOf() 13 | 14 | fun setData(cheeses: Collection) { 15 | values.clear() 16 | values.addAll(cheeses) 17 | notifyDataSetChanged() 18 | } 19 | 20 | fun add(cheese: Cheese) { 21 | values.add(cheese) 22 | notifyItemInserted(values.size - 1) 23 | } 24 | 25 | fun removeLast() { 26 | if (values.isNotEmpty()) { 27 | val removeIndex = values.size - 1 28 | remove(removeIndex) 29 | } 30 | } 31 | 32 | fun remove(index: Int) { 33 | values.removeAt(index) 34 | notifyItemRemoved(index) 35 | } 36 | 37 | fun changeMiddle() { 38 | if (values.isNotEmpty()) { 39 | val index = values.size / 2 40 | values[index].name = "Swiss" 41 | notifyItemChanged(index) 42 | } 43 | } 44 | 45 | fun changeAll() { 46 | if (values.isNotEmpty()) { 47 | for (cheese in values) { 48 | cheese.name = "Swiss" 49 | } 50 | notifyItemRangeChanged(0, values.size) 51 | } 52 | } 53 | 54 | fun clear() { 55 | if (values.isNotEmpty()) { 56 | val size = values.size 57 | values.clear() 58 | notifyItemRangeRemoved(0, size) 59 | } 60 | } 61 | 62 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder { 63 | val holder = CheeseViewHolder.inflate(parent) 64 | holder.itemView.setOnClickListener { 65 | //Takes the place of holder.getAdapterPosition() 66 | val position = AdapterLayout.getAdapterPosition(holder) 67 | val cheese = getItemAt(position) 68 | listener.invoke(cheese) 69 | } 70 | holder.buttonRemove.setOnClickListener { 71 | val position = AdapterLayout.getAdapterPosition(holder) 72 | remove(position) 73 | } 74 | return holder 75 | } 76 | 77 | override fun onBindViewHolder(holder: CheeseViewHolder, position: Int) { 78 | val cheese = getItemAt(position) 79 | holder.bind(cheese) 80 | } 81 | 82 | override fun getItemCount(): Int { 83 | return values.size 84 | } 85 | 86 | private fun getItemAt(position: Int): Cheese { 87 | return values[position] 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/CheeseViewHolder.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.TextView 7 | 8 | import androidx.recyclerview.widget.RecyclerView 9 | 10 | /** 11 | * The view holder related to each Cheese item 12 | */ 13 | class CheeseViewHolder(view: View) : RecyclerView.ViewHolder(view) { 14 | 15 | companion object { 16 | 17 | fun inflate(parent: ViewGroup): CheeseViewHolder { 18 | val view = LayoutInflater.from(parent.context) 19 | .inflate(R.layout.item_cheese, parent, false) 20 | return CheeseViewHolder(view) 21 | } 22 | } 23 | 24 | private val title: TextView = view.findViewById(R.id.text) 25 | val buttonRemove: View = view.findViewById(R.id.button_remove) 26 | 27 | fun bind(cheese: Cheese) { 28 | title.text = cheese.name 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/Cheeses.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | import java.util.ArrayList 4 | import java.util.Random 5 | 6 | /** 7 | * Get some cheese 8 | */ 9 | object Cheeses { 10 | 11 | private val RANDOM = Random() 12 | 13 | private val randomCheeseDrawable: Int 14 | get() { 15 | return when (RANDOM.nextInt(5)) { 16 | 0 -> R.drawable.cheese_1 17 | 1 -> R.drawable.cheese_2 18 | 2 -> R.drawable.cheese_3 19 | 3 -> R.drawable.cheese_4 20 | 4 -> R.drawable.cheese_5 21 | else -> R.drawable.cheese_1 22 | } 23 | } 24 | 25 | private val cheeseStrings = arrayOf("Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese", "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell", "Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc", "Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss", "Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon", "Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase", "Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese", "Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy", "Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille", "Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore", "Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)", "Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves", "Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur", "Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon", "Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin", "Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)", "Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine", "Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza", "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)", "Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta", "Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie", "Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat", "Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano", "Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain", "Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou", "Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar", "Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno", "Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack", "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper", "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)", "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese", "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza", "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley", "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino", "Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina", "Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby", "Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin", "Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester", "Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue", "Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz", "Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich", "Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue", "Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle", "Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia", "Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis", "Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus", "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison", "Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois", "Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse", "Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese", "Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise", "Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra", "Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola", "Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost", "Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel", "Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve", "Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi", "Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti", "Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve", "Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster", "Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg", "Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa", "Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine", "Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese", "Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere", "La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire", "Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou", "Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger", "Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings", "Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse", "Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam", "Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego", "Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin", "Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)", "Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse", "Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda", "Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte", "Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio", "Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne", "Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)", "Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster", "Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel", "Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca", "Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre", "Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty", "Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela", "Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano", "Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage", "Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry", "Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid", "Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn", "Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse", "Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin", "Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin", "Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre", "Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone", "Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark", "Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit", "Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia", "Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)", "Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna", "Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera", "Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou", "Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder", "Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort", "Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr", "Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin", "Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre", "Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss", "Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela", "Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda", "Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain", "Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese", "Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale", "Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie", "Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri", "Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar", "Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance", "Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes", "Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet", "Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe", "Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa", "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois", "Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue", "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington", "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano") 26 | 27 | private val randomCheeseName: String 28 | get() = cheeseStrings[RANDOM.nextInt(cheeseStrings.size - 1)] 29 | 30 | val randomCheese: Cheese 31 | get() = Cheese(randomCheeseDrawable, randomCheeseName) 32 | 33 | fun getRandomCheeses(count: Int): List { 34 | val cheeses = ArrayList(count) 35 | for (i in 0 until count) { 36 | cheeses.add(randomCheese) 37 | } 38 | return cheeses 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/commit451/adapterlayout/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.commit451.adapterlayout.sample 2 | 3 | import android.animation.LayoutTransition 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.CheckBox 9 | import android.widget.Toast 10 | import androidx.appcompat.app.AppCompatActivity 11 | import androidx.appcompat.widget.Toolbar 12 | import com.commit451.adapterlayout.AdapterLinearLayout 13 | 14 | class MainActivity : AppCompatActivity() { 15 | 16 | private lateinit var root: ViewGroup 17 | private lateinit var toolbar: Toolbar 18 | private lateinit var adapterLinearLayout: AdapterLinearLayout 19 | private lateinit var checkBoxAnimateLayoutChanges: CheckBox 20 | 21 | private lateinit var adapter: CheeseAdapter 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_main) 26 | val listener = { cheese: Cheese -> 27 | Toast.makeText(this, "${cheese.name} clicked", Toast.LENGTH_SHORT) 28 | .show() 29 | } 30 | root = findViewById(R.id.root) 31 | toolbar = findViewById(R.id.toolbar) 32 | adapterLinearLayout = findViewById(R.id.adapter_layout) 33 | checkBoxAnimateLayoutChanges = findViewById(R.id.animate_layout_changes) 34 | findViewById(R.id.add_cheese).setOnClickListener { adapter.add(Cheeses.randomCheese) } 35 | findViewById(R.id.remove_cheese).setOnClickListener { adapter.removeLast() } 36 | findViewById(R.id.change_middle).setOnClickListener { adapter.changeMiddle() } 37 | findViewById(R.id.clear_all).setOnClickListener { adapter.clear() } 38 | findViewById(R.id.change_all).setOnClickListener { adapter.changeAll() } 39 | findViewById(R.id.set_to_5).setOnClickListener { adapter.setData(Cheeses.getRandomCheeses(5)) } 40 | findViewById(R.id.new_adapter).setOnClickListener { 41 | adapterLinearLayout.setAdapter(null) 42 | adapter = CheeseAdapter(listener) 43 | adapterLinearLayout.setAdapter(adapter) 44 | } 45 | toolbar.setTitle(R.string.app_name) 46 | toolbar.inflateMenu(R.menu.main) 47 | toolbar.setOnMenuItemClickListener(Toolbar.OnMenuItemClickListener { item -> 48 | when (item.itemId) { 49 | R.id.action_adapter_flow_layout -> { 50 | startActivity(Intent(this@MainActivity, AdapterFlowLayoutActivity::class.java)) 51 | return@OnMenuItemClickListener true 52 | } 53 | } 54 | false 55 | }) 56 | adapter = CheeseAdapter(listener) 57 | adapterLinearLayout.adapter = adapter 58 | 59 | checkBoxAnimateLayoutChanges.setOnCheckedChangeListener { _, isChecked -> 60 | if (isChecked) { 61 | val layoutTransition = LayoutTransition() 62 | adapterLinearLayout.layoutTransition = layoutTransition 63 | } else { 64 | adapterLinearLayout.layoutTransition = null 65 | } 66 | } 67 | checkBoxAnimateLayoutChanges.isChecked = true 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cheese_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Commit451/AdapterLayout/cf3976d86c499d24549426e837e71ae734f67e9b/app/src/main/res/drawable-nodpi/cheese_1.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cheese_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Commit451/AdapterLayout/cf3976d86c499d24549426e837e71ae734f67e9b/app/src/main/res/drawable-nodpi/cheese_2.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cheese_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Commit451/AdapterLayout/cf3976d86c499d24549426e837e71ae734f67e9b/app/src/main/res/drawable-nodpi/cheese_3.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cheese_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Commit451/AdapterLayout/cf3976d86c499d24549426e837e71ae734f67e9b/app/src/main/res/drawable-nodpi/cheese_4.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cheese_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Commit451/AdapterLayout/cf3976d86c499d24549426e837e71ae734f67e9b/app/src/main/res/drawable-nodpi/cheese_5.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_adapter_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 16 | 17 | 21 | 22 | 26 | 27 | 30 | 31 |