├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xxxhdpi │ │ │ │ ├── img_11.jpg │ │ │ │ ├── ic_right.png │ │ │ │ ├── img_00.webp │ │ │ │ ├── img_01.webp │ │ │ │ ├── img_10.webp │ │ │ │ └── ic_fab_done.png │ │ │ ├── drawable │ │ │ │ ├── avatar_drakeet.jpg │ │ │ │ ├── square_border.xml │ │ │ │ ├── shadow.xml │ │ │ │ ├── square_background.xml │ │ │ │ └── card.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 │ │ │ ├── layout │ │ │ │ ├── item_weibo_simple_text.xml │ │ │ │ ├── item_weibo_simple_image.xml │ │ │ │ ├── item_horizontal_list.xml │ │ │ │ ├── item_inflated_text.xml │ │ │ │ ├── item_horizontal_post.xml │ │ │ │ ├── item_square.xml │ │ │ │ ├── item_image.xml │ │ │ │ ├── item_data_type1.xml │ │ │ │ ├── item_data_type2.xml │ │ │ │ ├── item_text.xml │ │ │ │ ├── activity_list.xml │ │ │ │ ├── activity_multi_selectable.xml │ │ │ │ ├── item_post.xml │ │ │ │ ├── item_heavy.xml │ │ │ │ ├── item_category.xml │ │ │ │ ├── item_weibo_frame.xml │ │ │ │ └── activity_more_apis_playground.xml │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── color │ │ │ │ └── square_number.xml │ │ │ └── menu │ │ │ │ └── menu_main.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── drakeet │ │ │ │ └── multitype │ │ │ │ └── sample │ │ │ │ ├── Numbers.kt │ │ │ │ ├── Test.java │ │ │ │ ├── common │ │ │ │ ├── Category.kt │ │ │ │ └── CategoryHolderInflater.kt │ │ │ │ ├── normal │ │ │ │ ├── ImageItem.kt │ │ │ │ ├── RichItem.kt │ │ │ │ ├── RichView.kt │ │ │ │ ├── TextItem.kt │ │ │ │ ├── ImageItemViewBinder.kt │ │ │ │ ├── RichViewDelegate.kt │ │ │ │ ├── TextItemViewBinder.kt │ │ │ │ └── NormalActivity.kt │ │ │ │ ├── payload │ │ │ │ ├── HeavyItem.kt │ │ │ │ ├── TestPayloadActivity.kt │ │ │ │ └── HeavyItemViewBinder.kt │ │ │ │ ├── bilibili │ │ │ │ ├── Post.kt │ │ │ │ ├── PostList.kt │ │ │ │ ├── PostItemDecoration.kt │ │ │ │ ├── PostViewBinder.kt │ │ │ │ ├── PostsAdapter.kt │ │ │ │ ├── HorizontalPostsHolderInflater.kt │ │ │ │ └── BilibiliActivity.kt │ │ │ │ ├── selectable │ │ │ │ ├── Square.kt │ │ │ │ ├── SquareViewBinder.kt │ │ │ │ └── MultiSelectableActivity.kt │ │ │ │ ├── weibo │ │ │ │ ├── User.kt │ │ │ │ ├── WeiboContent.kt │ │ │ │ ├── Weibo.kt │ │ │ │ ├── content │ │ │ │ │ ├── SimpleText.kt │ │ │ │ │ ├── SimpleImage.kt │ │ │ │ │ ├── SimpleTextViewBinder.kt │ │ │ │ │ └── SimpleImageViewBinder.kt │ │ │ │ ├── WeiboJsonParser.kt │ │ │ │ ├── ContentHolder.kt │ │ │ │ ├── WeiboContentDeserializer.kt │ │ │ │ ├── WeiboFrameBinder.kt │ │ │ │ └── WeiboActivity.kt │ │ │ │ ├── Savable.kt │ │ │ │ ├── one2many │ │ │ │ ├── Data.kt │ │ │ │ ├── DataType1ViewBinder.kt │ │ │ │ ├── DataType2ViewBinder.kt │ │ │ │ └── OneDataToManyActivity.kt │ │ │ │ ├── communication │ │ │ │ ├── CommunicateWithBinderActivity.kt │ │ │ │ └── TextItemWithOutsizeDataViewBinder.kt │ │ │ │ ├── MenuBaseActivity.kt │ │ │ │ └── more │ │ │ │ └── MoreApisPlayground.kt │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── kotlin │ │ └── com │ │ └── drakeet │ │ └── multitype │ │ └── sample │ │ ├── SmokeTest.kt │ │ ├── one2many │ │ ├── OneToManyTest.kt │ │ └── DuplicateTypesTest.kt │ │ ├── RecyclerViewMatcher.kt │ │ └── bilibili │ │ └── BilibiliActivityDataSetADCTest.kt ├── proguard-rules.pro └── build.gradle ├── library ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── ids.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── drakeet │ │ │ │ └── multitype │ │ │ │ ├── ViewHolderInflater.kt │ │ │ │ ├── ViewHolderDelegate.kt │ │ │ │ ├── ItemViewBinder.kt │ │ │ │ ├── DefaultLinker.kt │ │ │ │ ├── Type.kt │ │ │ │ ├── DelegateNotFoundException.kt │ │ │ │ ├── JavaClassLinker.kt │ │ │ │ ├── OneToManyFlow.kt │ │ │ │ ├── KotlinClassLinker.kt │ │ │ │ ├── Linker.kt │ │ │ │ ├── ClassLinkerBridge.kt │ │ │ │ ├── MutableTypes.kt │ │ │ │ ├── OneToManyBuilder.kt │ │ │ │ ├── Types.kt │ │ │ │ ├── ViewDelegate.kt │ │ │ │ └── OneToManyEndpoint.kt │ │ └── AndroidManifest.xml │ └── test │ │ └── kotlin │ │ └── com │ │ └── drakeet │ │ └── multitype │ │ ├── TestItem.kt │ │ ├── TestItemViewDelegate.kt │ │ ├── StringViewDelegate.kt │ │ ├── MutableTypesTest.kt │ │ ├── ItemViewDelegateTest.kt │ │ ├── MultiTypeTest.kt │ │ ├── OneToManyBuilderTest.kt │ │ └── MultiTypeAdapterTest.kt ├── module.md ├── gradle.properties └── build.gradle ├── image ├── sample-one2many.png ├── screenshot-normal.png ├── screenshot-bilibili.png └── screenshot-multigrid.png ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── publish-docs.gradle ├── findbugs.xml ├── .github ├── CONTRIBUTING.md └── ISSUE_TEMPLATE.md ├── .gitignore ├── RELEASING.md ├── settings.gradle ├── .travis.yml ├── CONTRIBUTING.md ├── gradle.properties ├── CHANGELOG.md └── gradlew.bat /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /image/sample-one2many.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/image/sample-one2many.png -------------------------------------------------------------------------------- /image/screenshot-normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/image/screenshot-normal.png -------------------------------------------------------------------------------- /image/screenshot-bilibili.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/image/screenshot-bilibili.png -------------------------------------------------------------------------------- /image/screenshot-multigrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/image/screenshot-multigrid.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/img_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/img_11.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/avatar_drakeet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable/avatar_drakeet.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/ic_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/ic_right.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/img_00.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/img_00.webp -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/img_01.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/img_01.webp -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/img_10.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/img_10.webp -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/ic_fab_done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeet/MultiType/HEAD/sample/src/main/res/drawable-xxxhdpi/ic_fab_done.png -------------------------------------------------------------------------------- /library/module.md: -------------------------------------------------------------------------------- 1 | # Module multitype 2 | 3 | An Android library to create multiple item types list views easily and flexibly 4 | 5 | # Package me.drakeet.multitype 6 | 7 | An Android library to create multiple item types list views easily and flexibly 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/Numbers.kt: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype.sample 2 | 3 | import android.content.res.Resources 4 | 5 | /** 6 | * @author Drakeet Xu 7 | */ 8 | val Number.dp: Int get() = (toInt() * Resources.getSystem().displayMetrics.density).toInt() 9 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/Test.java: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype.sample; 2 | 3 | import com.drakeet.multitype.MultiTypeAdapter; 4 | 5 | /** 6 | * @author Drakeet Xu 7 | */ 8 | class Test { 9 | MultiTypeAdapter adapter = new MultiTypeAdapter(); 10 | } 11 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/ViewHolderInflater.kt: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype 2 | 3 | import androidx.recyclerview.widget.RecyclerView 4 | 5 | /** 6 | * @author Drakeet Xu 7 | */ 8 | abstract class ViewHolderInflater : ItemViewBinder() 9 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/ViewHolderDelegate.kt: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype 2 | 3 | import androidx.recyclerview.widget.RecyclerView 4 | 5 | /** 6 | * @author Drakeet Xu 7 | */ 8 | abstract class ViewHolderDelegate: ItemViewDelegate() 9 | -------------------------------------------------------------------------------- /findbugs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | If you would like to contribute code to MultiType you can do so through GitHub by 4 | forking the repository and sending a pull request. 5 | 6 | When submitting code, please make every effort to follow existing conventions 7 | and style in order to keep the code as readable as possible. Please also make 8 | sure your code compiles by running `./gradlew clean build` and Checkstyle with 9 | `/checkstyle.xml`. 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.ap_ 3 | 4 | # files for the dex VM 5 | *.dex 6 | 7 | # Java class files 8 | *.class 9 | 10 | # generated files 11 | bin/ 12 | gen/ 13 | 14 | # Local configuration file (sdk path, etc) 15 | local.properties 16 | 17 | # Proguard folder generated by Eclipse 18 | proguard/ 19 | 20 | # Ignore gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | .settings/ 28 | 29 | # Intellij project files 30 | *.iml 31 | *.ipr 32 | *.iws 33 | .idea/ 34 | 35 | # Mac system files 36 | .DS_Store 37 | 38 | *.keystore -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | Releasing 2 | ========= 3 | 4 | 1. Change the version in `gradle.properties` to a non-SNAPSHOT version. 5 | 2. Update the `CHANGELOG.md` for the impending release 6 | 3. Update the `README.md` with the new version. 7 | 4. `git commit -am "Prepare for release X.Y.Z"` (where X.Y.Z is the new version) 8 | 5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) 9 | 6. `./gradlew clean uploadArchives` 10 | 7. Update the `gradle.properties` to the next SNAPSHOT version. 11 | 8. `git commit -am "Prepare next development version"` 12 | 9. `git push && git push --tags` 13 | 10. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. 14 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | include ':sample' 17 | include ':library' 18 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/drakeet/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/ItemViewBinder.kt: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype 2 | 3 | import android.content.Context 4 | import android.view.LayoutInflater 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.RecyclerView 7 | 8 | /** 9 | * This is a compatible version of [ItemViewDelegate]. 10 | * @see ItemViewDelegate 11 | * @author Drakeet Xu 12 | */ 13 | abstract class ItemViewBinder : ItemViewDelegate() { 14 | 15 | final override fun onCreateViewHolder(context: Context, parent: ViewGroup): VH { 16 | return onCreateViewHolder(LayoutInflater.from(context), parent) 17 | } 18 | 19 | abstract fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): VH 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /library/src/test/kotlin/com/drakeet/multitype/TestItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | open class TestItem(val text: String) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/common/Category.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.common 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class Category(var title: String) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/normal/ImageItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.normal 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class ImageItem(val resId: Int) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/payload/HeavyItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.payload 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class HeavyItem(var text: String) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/bilibili/Post.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.bilibili 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class Post(var coverResId: Int, var title: String) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/bilibili/PostList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.bilibili 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class PostList(internal val posts: List) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/normal/RichItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.normal 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class RichItem(var text: String, var imageResId: Int) 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/selectable/Square.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.selectable 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class Square(val number: Int) { 23 | var isSelected: Boolean = false 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/DefaultLinker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | internal class DefaultLinker : Linker { 23 | override fun index(position: Int, item: T): Int = 0 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/Type.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | data class Type( 23 | val clazz: Class, 24 | val delegate: ItemViewDelegate, 25 | val linker: Linker 26 | ) 27 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/User.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo 18 | 19 | import androidx.annotation.DrawableRes 20 | 21 | /** 22 | * @author Drakeet Xu 23 | */ 24 | class User(var name: String, @field:DrawableRes var avatar: Int) 25 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/Savable.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | interface Savable { 23 | 24 | fun init(data: ByteArray) 25 | 26 | fun toBytes(): ByteArray 27 | 28 | fun describe(): String 29 | } 30 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/DelegateNotFoundException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | internal class DelegateNotFoundException(clazz: Class<*>) : RuntimeException( 23 | "Have you registered the ${clazz.name} type and its delegate or binder?" 24 | ) 25 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/square_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | 4 | env: 5 | global: 6 | - ANDROID_ABI=armeabi-v7a 7 | 8 | android: 9 | components: 10 | - tools 11 | - android-22 12 | - android-28 13 | - sys-img-armeabi-v7a-android-22 14 | - extra-android-m2repository 15 | - extra-android-support 16 | - extra 17 | licenses: 18 | - android-sdk-license-.+ 19 | 20 | before_install: 21 | # Install SDK license so Android Gradle plugin can install deps. 22 | - mkdir "$ANDROID_HOME/licenses" || true 23 | - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license" 24 | - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license" 25 | 26 | before_script: 27 | - chmod +x gradlew 28 | - echo no | android create avd --force -n test -t android-22 --abi $ANDROID_ABI 29 | - emulator -avd test -no-window & 30 | - android-wait-for-emulator 31 | - adb shell input keyevent 82 & 32 | 33 | script: 34 | - ./gradlew clean connectedAndroidTest 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_weibo_simple_text.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboContent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo 18 | 19 | import com.google.gson.annotations.SerializedName 20 | 21 | /** 22 | * @author Drakeet Xu 23 | */ 24 | abstract class WeiboContent protected constructor( 25 | @field:SerializedName("content_type") 26 | val contentType: String 27 | ) 28 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_weibo_simple_image.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/Weibo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo 18 | 19 | /** 20 | * @author Drakeet Xu 21 | */ 22 | class Weibo(var user: User, var content: WeiboContent) { 23 | 24 | var createTime: String = "Just now" 25 | 26 | override fun toString(): String { 27 | return "content: " + content.javaClass.simpleName 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/content/SimpleText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo.content 18 | 19 | import com.drakeet.multitype.sample.weibo.WeiboContent 20 | 21 | /** 22 | * @author Drakeet Xu 23 | */ 24 | class SimpleText(var text: String) : WeiboContent(TYPE) { 25 | companion object { 26 | const val TYPE = "simple_text" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #FF4081 20 | #ce3066 21 | #FF4081 22 | #E07679 23 | #de000000 24 | 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | What kind of issue is this? 2 | 3 | - [ ] Question. This issue tracker is not the place for questions. If you want to ask how to do 4 | something, or to understand why something isn't working the way you expect it to, use Stack 5 | Overflow. https://stackoverflow.com/questions/tagged/MultiType 6 | 7 | - [ ] Bug report. If you’ve found a bug, spend the time to write a failing test. Please provide 8 |       your device name, device OS version, and describe the reproduction steps. 9 | 10 | - [ ] Feature Request. Start by telling us what problem you’re trying to solve. Often a solution 11 | already exists! Don’t send pull requests to implement new features without first getting our 12 | support. Sometimes we leave features out on purpose to keep the project small. 13 | 14 | ###### Info: 15 | 16 | - MultiType version: 17 | - Device OS version: 18 | - Device Name: 19 | 20 | ###### Description: 21 | 22 | ###### Reproduction Steps: 23 | 24 | ###### My thoughts: 25 | 26 | ###### What did I do: 27 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_horizontal_list.xml: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/normal/RichView.kt: -------------------------------------------------------------------------------- 1 | package com.drakeet.multitype.sample.normal 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.view.Gravity 6 | import android.view.ViewGroup.LayoutParams.WRAP_CONTENT 7 | import android.widget.LinearLayout 8 | import androidx.appcompat.widget.AppCompatImageView 9 | import androidx.appcompat.widget.AppCompatTextView 10 | import com.drakeet.multitype.sample.R 11 | import com.drakeet.multitype.sample.dp 12 | 13 | /** 14 | * @author Drakeet Xu 15 | */ 16 | class RichView(context: Context) : LinearLayout(context) { 17 | 18 | val imageView = AppCompatImageView(context).apply { 19 | addView(this, LayoutParams(72.dp, 72.dp)) 20 | } 21 | 22 | val textView = AppCompatTextView(context).apply { 23 | gravity = Gravity.CENTER 24 | setTextColor(Color.BLACK) 25 | addView(this, LayoutParams(WRAP_CONTENT, WRAP_CONTENT)) 26 | } 27 | 28 | init { 29 | orientation = VERTICAL 30 | gravity = Gravity.CENTER 31 | setPadding(16.dp, 16.dp, 16.dp, 16.dp) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 21 | 64dp 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/color/square_number.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 21 | 22 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_inflated_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | MultiType 19 | MT: Bilibili 20 | MT: MultiGrid 21 | close 22 | ADD 23 | REMOVE 24 | CLEAR 25 | 26 | -------------------------------------------------------------------------------- /gradle/publish-docs.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 3 | * Copyright (c) 2018 Drakeet Xu 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | configurations { 19 | osstrich 20 | } 21 | 22 | dependencies { 23 | osstrich 'com.squareup.osstrich:osstrich:1.3.0' 24 | } 25 | 26 | task publishDocs(type: JavaExec) { 27 | classpath = configurations.osstrich 28 | main = 'com.squareup.osstrich.JavadocPublisher' 29 | args = ['build/javadoc', 30 | 'https://github.com/drakeet/MultiType', 31 | 'com.drakeet.multitype'] 32 | } 33 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/one2many/Data.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.one2many 18 | 19 | import com.google.gson.annotations.SerializedName 20 | 21 | /** 22 | * @author Drakeet Xu 23 | */ 24 | class Data( 25 | @field:SerializedName("title") var title: String, 26 | @field:SerializedName("type") var type: Int 27 | ) { 28 | 29 | companion object { 30 | const val TYPE_1 = 1 31 | const val TYPE_2 = 2 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/content/SimpleImage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo.content 18 | 19 | import androidx.annotation.DrawableRes 20 | import com.drakeet.multitype.sample.weibo.WeiboContent 21 | 22 | /** 23 | * @author Drakeet Xu 24 | */ 25 | class SimpleImage( 26 | @param:DrawableRes @field:DrawableRes var resId: Int 27 | ) : WeiboContent(TYPE) { 28 | 29 | companion object { 30 | const val TYPE = "simple_image" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/square_background.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_horizontal_post.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 24 | 28 | 29 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to MultiType 2 | 3 | If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request. 4 | 5 | When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. 6 | 7 | ## License 8 | 9 | By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/drakeet/MultiType/blob/4.x/LICENSE 10 | 11 | All files are released with the Apache 2.0 license. 12 | 13 | If you are adding a new file it should have a header like this: 14 | 15 | ``` 16 | /* 17 | * Licensed under the Apache License, Version 2.0 (the "License"); 18 | * you may not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * http://www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an "AS IS" BASIS, 25 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | ``` 30 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_square.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 25 | 26 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 16dp 20 | 16dp 21 | 2dp 22 | 6dp 23 | 24 | 24dp 25 | 12dp 26 | 6dp 27 | 96dp 28 | 29 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboJsonParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo 18 | 19 | import com.google.gson.GsonBuilder 20 | import com.google.gson.reflect.TypeToken 21 | import java.util.* 22 | 23 | /** 24 | * @author Drakeet Xu 25 | */ 26 | internal object WeiboJsonParser { 27 | 28 | val GSON = GsonBuilder() 29 | .registerTypeAdapter(WeiboContent::class.java, WeiboContentDeserializer()) 30 | .create()!! 31 | 32 | fun fromJson(json: String): List { 33 | return GSON.fromJson(json, object : TypeToken>() {}.type) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 31 | 32 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/JavaClassLinker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | /** 20 | * An interface to link the items and delegates by the classes of delegates. 21 | * 22 | * @author Drakeet Xu 23 | */ 24 | interface JavaClassLinker { 25 | 26 | /** 27 | * Returns the class of your registered delegates for your item. 28 | * 29 | * @param position The position in items 30 | * @param item The item 31 | * @return The index of your registered delegates 32 | * @see OneToManyEndpoint.withJavaClassLinker 33 | */ 34 | fun index(position: Int, item: T): Class> 35 | } 36 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/card.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/OneToManyFlow.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | import androidx.annotation.CheckResult 20 | 21 | /** 22 | * Process and flow operators for one-to-many. 23 | * 24 | * @author Drakeet Xu 25 | */ 26 | interface OneToManyFlow { 27 | 28 | /** 29 | * Sets some item view delegates to the item type. 30 | * 31 | * @param delegates the item view delegates 32 | * @return end flow operator 33 | */ 34 | @CheckResult 35 | fun to(vararg delegates: ItemViewDelegate): OneToManyEndpoint 36 | 37 | @CheckResult 38 | fun to(vararg delegates: ItemViewBinder): OneToManyEndpoint 39 | } 40 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/KotlinClassLinker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | import kotlin.reflect.KClass 20 | 21 | /** 22 | * An interface to link the items and delegates by the classes of delegates. 23 | * 24 | * @author Drakeet Xu 25 | */ 26 | interface KotlinClassLinker { 27 | 28 | /** 29 | * Returns the class of your registered delegates for your item. 30 | * 31 | * @param position The position in items 32 | * @param item The item 33 | * @return The index of your registered delegates 34 | * @see OneToManyEndpoint.withJavaClassLinker 35 | */ 36 | fun index(position: Int, item: T): KClass> 37 | } 38 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/ContentHolder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.weibo 18 | 19 | import android.view.View 20 | 21 | /** 22 | * @author Drakeet Xu 23 | */ 24 | open class ContentHolder(val itemView: View) { 25 | 26 | lateinit var parent: WeiboFrameBinder.FrameHolder 27 | 28 | val absoluteAdapterPosition: Int 29 | get() = parent.absoluteAdapterPosition 30 | 31 | val layoutPosition: Int 32 | get() = parent.layoutPosition 33 | 34 | val oldPosition: Int 35 | get() = parent.oldPosition 36 | 37 | var isRecyclable: Boolean 38 | get() = parent.isRecyclable 39 | set(recyclable) = parent.setIsRecyclable(recyclable) 40 | } 41 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_data_type1.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_data_type2.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016-present. Drakeet Xu 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | POM_NAME=MultiType 18 | POM_ARTIFACT_ID=multitype 19 | POM_PACKAGING=aar 20 | 21 | GROUP=com.drakeet.multitype 22 | 23 | POM_DESCRIPTION=Easier and more flexible to create multiple types for Android RecyclerView. 24 | POM_URL=https://github.com/drakeet/MultiType 25 | POM_SCM_URL=https://github.com/drakeet/MultiType 26 | POM_SCM_CONNECTION=scm:git@github.com:drakeet/MultiType.git 27 | POM_SCM_DEV_CONNECTION=scm:git@github.com:drakeet/MultiType.git 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | POM_DEVELOPER_ID=drakeet 32 | POM_DEVELOPER_NAME=Drakeet Xu 33 | POM_DEVELOPER_URL=https://drakeet.com 34 | -------------------------------------------------------------------------------- /library/src/test/kotlin/com/drakeet/multitype/TestItemViewDelegate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | import android.content.Context 20 | import android.view.View 21 | import android.view.ViewGroup 22 | import androidx.recyclerview.widget.RecyclerView 23 | 24 | /** 25 | * @author Drakeet Xu 26 | */ 27 | open class TestItemViewDelegate : ItemViewDelegate() { 28 | 29 | override fun onCreateViewHolder(context: Context, parent: ViewGroup): ViewHolder { 30 | throw NotImplementedError() 31 | } 32 | 33 | override fun onBindViewHolder(holder: ViewHolder, item: TestItem) {} 34 | 35 | inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) 36 | } 37 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 33 | 34 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016-present. Drakeet Xu 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Project-wide Gradle settings. 18 | 19 | # IDE (e.g. Android Studio) users: 20 | # Gradle settings configured through the IDE *will override* 21 | # any settings specified in this file. 22 | 23 | # For more details on how to configure your build environment visit 24 | # http://www.gradle.org/docs/current/userguide/build_environment.html 25 | 26 | # Specifies the JVM arguments used for the daemon process. 27 | # The setting is particularly useful for tweaking memory settings. 28 | android.useAndroidX=true 29 | org.gradle.jvmargs=-Xmx4096m 30 | 31 | # When configured, Gradle will run in incubating parallel mode. 32 | # This option should only be used with decoupled projects. More details, visit 33 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 34 | # org.gradle.parallel=true 35 | -------------------------------------------------------------------------------- /library/src/test/kotlin/com/drakeet/multitype/StringViewDelegate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | import android.R 20 | import android.content.Context 21 | import android.view.LayoutInflater 22 | import android.view.View 23 | import android.view.ViewGroup 24 | import androidx.recyclerview.widget.RecyclerView 25 | 26 | /** 27 | * @author Drakeet Xu 28 | */ 29 | class StringViewDelegate : ItemViewDelegate() { 30 | 31 | override fun onCreateViewHolder(context: Context, parent: ViewGroup): ViewHolder { 32 | return ViewHolder(LayoutInflater.from(context).inflate(R.layout.test_list_item, parent, false)) 33 | } 34 | 35 | override fun onBindViewHolder(holder: ViewHolder, item: String) {} 36 | 37 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) 38 | } 39 | -------------------------------------------------------------------------------- /library/src/main/kotlin/com/drakeet/multitype/Linker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype 18 | 19 | import androidx.annotation.IntRange 20 | 21 | /** 22 | * An interface to link the items and delegates by the array index. 23 | * 24 | * @author Drakeet Xu 25 | */ 26 | interface Linker { 27 | 28 | /** 29 | * Returns the index of your registered delegates for your item. The result should be in range of 30 | * `[0, one-to-multiple-delegates.length)`. 31 | * 32 | * Note: The argument of [OneToManyFlow.to] is the 33 | * one-to-multiple-delegates. 34 | * 35 | * @param position The position in items 36 | * @param item The data item 37 | * @return The index of your registered delegates 38 | * @see OneToManyFlow.to 39 | * @see OneToManyEndpoint.withLinker 40 | */ 41 | @IntRange(from = 0) 42 | fun index(position: Int, item: T): Int 43 | } 44 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/bilibili/PostItemDecoration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.bilibili 18 | 19 | import android.graphics.Rect 20 | import android.view.View 21 | import androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup 22 | import androidx.recyclerview.widget.RecyclerView 23 | 24 | /** 25 | * @author Drakeet Xu 26 | */ 27 | class PostItemDecoration(private val space: Int, private val spanSizeLookup: SpanSizeLookup) : RecyclerView.ItemDecoration() { 28 | 29 | override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { 30 | val position = parent.getChildLayoutPosition(view) 31 | if (spanSizeLookup.getSpanSize(position) == 1) { 32 | outRect.left = space 33 | if (position % 2 == 0) { 34 | outRect.right = space 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/src/main/kotlin/com/drakeet/multitype/sample/normal/TextItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present. Drakeet Xu 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.drakeet.multitype.sample.normal 18 | 19 | import com.google.gson.Gson 20 | import com.drakeet.multitype.sample.Savable 21 | import java.nio.charset.Charset 22 | 23 | /** 24 | * @author Drakeet Xu 25 | */ 26 | class TextItem : Savable { 27 | 28 | lateinit var text: String 29 | 30 | constructor(text: String) { 31 | this.text = text 32 | } 33 | 34 | constructor(data: ByteArray) { 35 | init(data) 36 | } 37 | 38 | override fun init(data: ByteArray) { 39 | val json = String(data, UTF_8) 40 | this.text = Gson().fromJson(json, TextItem::class.java).text 41 | } 42 | 43 | override fun toBytes(): ByteArray { 44 | return Gson().toJson(this).toByteArray(UTF_8) 45 | } 46 | 47 | override fun describe(): String { 48 | return "Text" 49 | } 50 | 51 | companion object { 52 | private val UTF_8 = Charset.forName("UTF-8") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_multi_selectable.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 25 | 26 | 33 | 34 |