?,
11 | // 是否支持多选
12 | var isMultiCheck: Boolean = false
13 | )
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/JDFilter/src/main/res/layout/layout_drawer_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/kiffon/filter/demo/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.kiffon.filter.demo
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/JDFilter/src/test/java/com/kiffon/filter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kiffon.filter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/TreeRvAdapter/src/test/java/com/kiffon/tree/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kiffon.tree;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/kiffon/filter/demo/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.kiffon.filter.demo
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.kiffon.filter.demo", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/JDFilter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/TreeRvAdapter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/JDFilter/src/androidTest/java/com/kiffon/filter/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.kiffon.filter;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.kiffon.filter.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/TreeRvAdapter/src/androidTest/java/com/kiffon/tree/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.kiffon.tree;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.kiffon.tree.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/JDFilter/src/main/res/layout/item_tree_child_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
26 |
27 |
--------------------------------------------------------------------------------
/JDFilter/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2E3034
4 | #2E3034
5 | #2E3034
6 |
7 | #2E3034
8 |
9 | #00FFFFFF
10 | #80FFFFFF
11 | #80000000
12 |
13 |
14 | #F5F5F5
15 | #000000
16 | #FFFFFF
17 |
18 | #F08327
19 | #D07528
20 | #50F08327
21 |
22 | #F08327
23 | #999999
24 | #666666
25 | #333333
26 | #2A2A2A
27 | #C6C6C6
28 |
29 | #E7E7E7
30 |
31 |
--------------------------------------------------------------------------------
/JDFilter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 28
6 |
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | compileOptions {
27 | targetCompatibility 1.8
28 | sourceCompatibility 1.8
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 |
35 | implementation 'com.android.support:appcompat-v7:28.0.0'
36 | implementation "com.android.support:design:28.0.0"
37 | implementation "com.android.support:support-v4:28.0.0"
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
41 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
42 | api project(':TreeRvAdapter')
43 | }
44 | repositories {
45 | mavenCentral()
46 | }
47 |
--------------------------------------------------------------------------------
/TreeRvAdapter/src/main/java/com/plumcookingwine/tree/ItemStatus.java:
--------------------------------------------------------------------------------
1 | package com.plumcookingwine.tree;
2 |
3 | /**
4 | * Created by Kevin on 2019/1/22.
5 | *
6 | * 用来存储item的状态, 并计算真实索引值
7 | */
8 | public class ItemStatus {
9 | // 一级item
10 | public static final int VIEW_TYPE_GROUP_ITEM = 0x00000000;
11 | // 二级item
12 | public static final int VIEW_TYPE_SUB_ITEM = 0x00000001;
13 |
14 | // 当前item类型
15 | private int mViewType;
16 | // 组索引
17 | private int mGroupItemIndex;
18 | // 子索引
19 | private int mSubItemIndex;
20 |
21 | public ItemStatus() {
22 | }
23 |
24 | public ItemStatus(int mViewType, int mGroupItemIndex, int mSubItemIndex) {
25 | this.mViewType = mViewType;
26 | this.mGroupItemIndex = mGroupItemIndex;
27 | this.mSubItemIndex = mSubItemIndex;
28 | }
29 |
30 | public int getViewType() {
31 | return mViewType;
32 | }
33 |
34 | public void setViewType(int mViewType) {
35 | this.mViewType = mViewType;
36 | }
37 |
38 | public int getGroupItemIndex() {
39 | return mGroupItemIndex;
40 | }
41 |
42 | public void setGroupItemIndex(int mGroupItemIndex) {
43 | this.mGroupItemIndex = mGroupItemIndex;
44 | }
45 |
46 | public int getSubItemIndex() {
47 | return mSubItemIndex;
48 | }
49 |
50 | public void setSubItemIndex(int mSubItemIndex) {
51 | this.mSubItemIndex = mSubItemIndex;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.kiffon.filter.demo"
11 | minSdkVersion 14
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | compileOptions {
18 | sourceCompatibility JavaVersion.VERSION_1_8
19 | targetCompatibility JavaVersion.VERSION_1_8
20 | }
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(include: ['*.jar'], dir: 'libs')
32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
33 | implementation 'com.android.support:appcompat-v7:28.0.0'
34 | implementation 'com.android.support:design:28.0.0'
35 | implementation 'com.android.support:support-v4:28.0.0'
36 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
37 | testImplementation 'junit:junit:4.12'
38 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40 | implementation project(':JDFilter')
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/TreeRvAdapter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'//添加
3 |
4 | android {
5 | compileSdkVersion 28
6 |
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | lintOptions {
27 | abortOnError false
28 | }
29 |
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 |
35 | implementation 'com.android.support:appcompat-v7:28.0.0'
36 | implementation "com.android.support:design:28.0.0"
37 | implementation "com.android.support:support-v4:28.0.0"
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
41 | }
42 |
43 | publish {
44 | userOrg = 'plumcookingwine'
45 | groupId = 'com.plumcookingwine.treeadapter'
46 | artifactId = 'TreeRecyclerview'
47 | publishVersion = '1.0.0'
48 | desc = 'this is a treerecyclerview for android'
49 | website = 'https://github.com/KevinkfFEF/TreeRecyclerView.git'
50 | repoName = 'KevinArticle'
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/TreeRvAdapter/src/main/java/com/plumcookingwine/tree/dao/TreeListDao.java:
--------------------------------------------------------------------------------
1 | package com.plumcookingwine.tree.dao;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by Kevin on 2019/1/22.
7 | */
8 | public class TreeListDao {
9 |
10 | /**
11 | * 配置项
12 | */
13 | // 是否可展开收起
14 | private boolean isEnableExpand = true;
15 | // 默认是否展开状态
16 | private boolean isExpand = false;
17 | // 收起状态最少展示子item数量
18 | private int minCount = 6;
19 |
20 | /**
21 | * 数据
22 | */
23 | // 组
24 | private K groupDao;
25 | // 子
26 | private List subList;
27 |
28 | public TreeListDao(){}
29 |
30 | public TreeListDao(K groupDao, List subList) {
31 | this.groupDao = groupDao;
32 | this.subList = subList;
33 | }
34 |
35 | public K getGroupDao() {
36 | return groupDao;
37 | }
38 |
39 | public void setGroupDao(K groupDao) {
40 | this.groupDao = groupDao;
41 | }
42 |
43 | public List getSubList() {
44 | return subList;
45 | }
46 |
47 | public void setSubList(List subList) {
48 | this.subList = subList;
49 | }
50 |
51 | public boolean isEnableExpand() {
52 | return isEnableExpand;
53 | }
54 |
55 | public void setEnableExpand(boolean enableExpand) {
56 | isEnableExpand = enableExpand;
57 | }
58 |
59 | public boolean isExpand() {
60 | return isExpand;
61 | }
62 |
63 | public void setExpand(boolean expand) {
64 | isExpand = expand;
65 | }
66 |
67 | public int getMinCount() {
68 | return minCount;
69 | }
70 |
71 | public void setMinCount(int minCount) {
72 | this.minCount = minCount;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/JDFilter/src/main/res/layout/item_tree_title_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
22 |
29 |
30 |
31 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TreeAdapter [  ](https://bintray.com/plumcookingwine/maven/TreeRvAdapter/_latestVersion)
2 | 1、# 使用: compile ‘com.plumcookingwine.tree:TreeRvAdapter:1.0.3’
3 |
4 | 2、实体类的创建: TreeListDao是具体封装的对象, 里面有两个泛型,第一个就是父级对象,第二个就是子级集合; 其他属性为一些配置项:
5 | ```
6 | // 是否可展开收起
7 | private boolean isEnableExpand = true;
8 | // 默认是否展开状态
9 | private boolean isExpand = false;
10 | // 收起状态最少展示子item数量
11 | private int minCount = 6;
12 | ```
13 |
14 | 目前支持这几种配置;以后会逐渐完善。。。
15 |
16 | (举例)
17 |
18 |
19 | `
20 | data class FilterDao(
21 | var _ID: Int = 0,
22 | var mTitle: String = "",
23 | var mDesc: String = "",
24 | var mCheckOption: List?
25 | )
26 | `
27 | `
28 | data class OptionDao(
29 | var _ID: Int = 0,
30 | var mTitle: String = "",
31 | var mDesc: String = "",
32 | var isCheck: Boolean = false
33 | )
34 | `
35 |
36 |
37 | 其中FilterDao 是父级对象, OptionDao是子级对象,最后将这两个对象放到TreeListDao对象中:
38 |
39 | ```
40 | private fun initData(): MutableList> {
41 | val list = mutableListOf>()
42 | for (i in 0..5) {
43 | val dao = TreeListDao()
44 | val filterDao = FilterDao(i, "title$i", "title$i", null)
45 | val subs = mutableListOf()
46 | for (j in 0..20) {
47 | val subListDao = OptionDao(j, "o${j}t${i}", "o${j}t${i}", false)
48 | subs.add(subListDao)
49 | }
50 | dao.groupDao = filterDao
51 | dao.subList = subs if (i % 2 == 0) {
52 | dao.isMultiCheck = true } list.add(dao)
53 | }
54 | return list
55 | }
56 | ```
57 |
58 |
59 | 2、创建adapter继承自AbsTreeListAdapter,将TreeListDao传进来,重写方法:
60 | ```
61 | // 组item的layoutId
62 | public abstract int groupLayoutId();
63 | // 子item的layoutId
64 | public abstract int subLayoutId();
65 | // 绑定组item数据(K 为传进来的父对象泛型)
66 | public abstract void onBindGroupHolder(GroupItemViewHolder holder, K k, int groupIndex, int position);
67 | // 绑定子item数据(V 为传进来的子对象泛型)
68 | public abstract void onBindSubHolder(SubItemViewHolder holder, V v, int subIndex, int groupIndex, int position);
69 | ```
70 |
71 | ## 效果
72 | ### 效果:
73 |
74 |
75 |
76 | ## 实现 具体的实现原理请看文章:
77 | ## https://blog.csdn.net/qq_22090073/article/details/86623042
78 |
--------------------------------------------------------------------------------
/JDFilter/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12sp
4 | 14sp
5 | 16sp
6 | 18sp
7 |
8 |
9 | 56dp
10 |
11 | 16dp
12 |
13 |
14 | 100.0dip
15 | 110.0dip
16 | 120.0dip
17 | 80.0dip
18 | 60dp
19 | 50dp
20 | 36dp
21 | 34dp
22 | 30.0dip
23 | 40.0dip
24 | 28.0dip
25 | 26.0dip
26 | 24.0dip
27 | 22.0dip
28 | 20.0dip
29 | 18.0dip
30 | 16.0dip
31 | 14.0dip
32 | 12.0dip
33 | 10.0dip
34 | 8.0dip
35 | 6.0dip
36 | 4.0dip
37 | 2.0dip
38 |
39 |
40 | 10sp
41 | 12sp
42 | 14sp
43 | 16sp
44 | 18sp
45 | 20sp
46 |
47 |
51 | 50dp
52 | 4dp
53 | 2dp
54 | 2dp
55 |
56 | - 1
57 | 2dp
58 | 10sp
59 | 10sp
60 | 20dp
61 |
62 | 36dp
63 |
64 | 36dp
65 |
66 | 8sp
67 |
--------------------------------------------------------------------------------
/JDFilter/src/main/java/com/kiffon/filter/FilterAdapter.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("DEPRECATION")
2 |
3 | package com.kiffon.filter
4 |
5 | import android.widget.CheckBox
6 | import android.widget.TextView
7 | import com.plumcookingwine.tree.adapter.AbsTreeListAdapter
8 | import com.plumcookingwine.tree.dao.TreeListDao
9 | import com.kiffon.filter.dao.FilterDao
10 | import com.kiffon.filter.dao.OptionDao
11 |
12 | /**
13 | * Created by Kevin on 2019/1/22.
14 | */
15 | class FilterAdapter(private val treeList: MutableList>?) :
16 | AbsTreeListAdapter(treeList) {
17 |
18 | private var selectList: MutableList> = mutableListOf()
19 |
20 | override fun groupLayoutId(): Int {
21 | return R.layout.item_tree_title_layout
22 | }
23 |
24 | override fun subLayoutId(): Int {
25 | return R.layout.item_tree_child_layout
26 | }
27 |
28 | override fun onBindGroupHolder(holder: GroupItemViewHolder?, k: FilterDao?, groupIndex: Int, position: Int) {
29 | val view = holder?.itemView
30 |
31 | view?.setOnClickListener {
32 | toggleMoreHide(groupIndex)
33 | }
34 |
35 | val mTvFilter = view?.findViewById(R.id.mTvFilter)
36 | mTvFilter?.text = k?.mTitle ?: "null"
37 |
38 | val mCbDesc = view?.findViewById(R.id.mCbDesc)
39 | var selectedOptions = ""
40 | treeList?.get(groupIndex)?.subList?.map {
41 | if (it.isCheck) {
42 | selectedOptions += it.mTitle + ","
43 | }
44 | }
45 | if (selectedOptions.isEmpty().not()) {
46 | mCbDesc?.text = selectedOptions.substring(0, selectedOptions.lastIndex)
47 | } else {
48 | mCbDesc?.text = ""
49 | }
50 | }
51 |
52 | override fun onBindSubHolder(holder: SubItemViewHolder?, v: OptionDao?, subIndex: Int, groupIndex: Int, position: Int) {
53 | if (v == null) return
54 | val view = holder?.itemView
55 | val mCbSub = view?.findViewById(R.id.mCbSub)
56 | mCbSub?.text = v.mTitle
57 | mCbSub?.isChecked = v.isCheck
58 | mCbSub?.setOnClickListener {
59 | val check = mCbSub.isChecked
60 | if (treeList!![groupIndex].groupDao.isMultiCheck) {
61 | treeList[groupIndex].subList?.map { its ->
62 | its.isCheck = false
63 | }
64 | }
65 |
66 | v.isCheck = check
67 | notifyDataSetChanged()
68 |
69 | }
70 | }
71 |
72 | fun getSelectOptionDao(): List>? {
73 |
74 | selectList.clear()
75 |
76 | treeList?.map { item ->
77 |
78 | val list = mutableListOf()
79 | item.subList.map {
80 | if (it.isCheck) {
81 | list.add(it)
82 | }
83 | }
84 | if (list.size > 0) {
85 | item.groupDao.mCheckOption = list
86 | selectList.add(item)
87 | }
88 |
89 | }
90 |
91 | return selectList
92 | }
93 |
94 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/kiffon/filter/demo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kiffon.filter.demo
2 |
3 | import android.app.AlertDialog
4 | import android.support.v7.app.AppCompatActivity
5 | import android.os.Bundle
6 | import android.support.v7.widget.GridLayoutManager
7 | import android.util.Log
8 | import com.plumcookingwine.tree.ItemStatus
9 | import com.plumcookingwine.tree.dao.TreeListDao
10 | import com.kiffon.filter.FilterAdapter
11 | import com.kiffon.filter.dao.FilterDao
12 | import com.kiffon.filter.dao.OptionDao
13 | import kotlinx.android.synthetic.main.activity_main.*
14 |
15 | class MainActivity : AppCompatActivity() {
16 |
17 |
18 | private val mData = mutableListOf>()
19 |
20 | private lateinit var mAdapter: FilterAdapter
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContentView(R.layout.activity_main)
25 |
26 | mAdapter = FilterAdapter(mData)
27 |
28 | mRecyclerView.let {
29 | val manager = GridLayoutManager(this, 3)
30 |
31 | manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
32 | override fun getSpanSize(position: Int): Int {
33 | if (mAdapter.getItemViewType(position) == ItemStatus.VIEW_TYPE_SUB_ITEM) {
34 | return 1
35 | }
36 | return 3
37 | }
38 | }
39 |
40 | it.layoutManager = manager
41 |
42 | it.adapter = mAdapter
43 | //
44 | mAdapter.setData(initData())
45 |
46 | mBtnConfirm.setOnClickListener {
47 | val treeListDao = mAdapter.getSelectOptionDao()
48 | var str = ""
49 | treeListDao?.map {
50 | str += "\n${it.groupDao.mTitle}"
51 | Log.e("TAG", it.groupDao.mTitle)
52 | it.groupDao.mCheckOption?.map {
53 | str += "\n\t${it.mTitle}"
54 | Log.e("TAG", "\t\t" + it.mTitle)
55 | }
56 | }
57 |
58 | AlertDialog.Builder(this).setTitle("您选择了:")
59 | .setCancelable(true)
60 | .setMessage(str)
61 | .create()
62 | .show()
63 |
64 | }
65 | }
66 |
67 | }
68 |
69 | private fun initData(): MutableList> {
70 | val list = mutableListOf>()
71 |
72 | for (i in 0..5) {
73 | val dao = TreeListDao()
74 | val filterDao = FilterDao(i, "title$i", "title$i", null)
75 | val subs = mutableListOf()
76 | for (j in 0..20) {
77 | val subListDao = OptionDao(j, "o${j}t${i}", "o${j}t${i}", false)
78 | subs.add(subListDao)
79 | }
80 |
81 | dao.groupDao = filterDao
82 | dao.subList = subs
83 |
84 | /* 设置为2的整数倍的类不可多选 */
85 | if (i % 2 == 0) {
86 | dao.groupDao.isMultiCheck = true
87 | }
88 |
89 | /* 设置为3的整数倍的类不可展开和收起 */
90 | if(i % 3 == 0) {
91 | dao.isEnableExpand = false
92 | }
93 |
94 | list.add(dao)
95 | }
96 |
97 | return list
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/TreeRvAdapter/src/main/java/com/plumcookingwine/tree/adapter/AbsTreeListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.plumcookingwine.tree.adapter;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.plumcookingwine.tree.ItemStatus;
10 | import com.plumcookingwine.tree.dao.TreeListDao;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | * Created by Kevin on 2019/1/22.
17 | *
18 | * K代表组对象, V代表子对象
19 | */
20 | public abstract class AbsTreeListAdapter extends RecyclerView.Adapter {
21 |
22 | private List> mTreeList;
23 |
24 | private List mGroupItemStatus;
25 |
26 | public AbsTreeListAdapter(List> treeList) {
27 | this.mTreeList = treeList;
28 | }
29 |
30 | public abstract int groupLayoutId();
31 |
32 | public abstract int subLayoutId();
33 |
34 | public abstract void onBindGroupHolder(GroupItemViewHolder holder, K k, int groupIndex, int position);
35 |
36 | public abstract void onBindSubHolder(SubItemViewHolder holder, V v, int subIndex, int groupIndex, int position);
37 |
38 | @NonNull
39 | @Override
40 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
41 | LayoutInflater inflater = LayoutInflater.from(parent.getContext());
42 | View view;
43 | RecyclerView.ViewHolder viewHolder;
44 |
45 | if (viewType == ItemStatus.VIEW_TYPE_GROUP_ITEM) {
46 | view = inflater.inflate(groupLayoutId(), parent, false);
47 | viewHolder = new GroupItemViewHolder(view);
48 | } else {
49 | view = inflater.inflate(subLayoutId(), parent, false);
50 | viewHolder = new SubItemViewHolder(view);
51 | }
52 |
53 | return viewHolder;
54 | }
55 |
56 | @Override
57 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
58 |
59 | ItemStatus itemStatus = getItemStatusByPosition(position);
60 |
61 | TreeListDao data = mTreeList.get(itemStatus.getGroupItemIndex());
62 |
63 | int groupIndex = itemStatus.getGroupItemIndex();
64 | int subIndex = itemStatus.getSubItemIndex();
65 |
66 | if (itemStatus.getViewType() == ItemStatus.VIEW_TYPE_GROUP_ITEM) {
67 | GroupItemViewHolder holder = (GroupItemViewHolder) viewHolder;
68 |
69 | onBindGroupHolder(holder, data.getGroupDao(), groupIndex, position);
70 | } else if (itemStatus.getViewType() == ItemStatus.VIEW_TYPE_SUB_ITEM) {
71 | try {
72 | SubItemViewHolder holder = (SubItemViewHolder) viewHolder;
73 | onBindSubHolder(holder, data.getSubList().get(subIndex), subIndex, groupIndex, position);
74 | } catch (Exception e) {
75 | // Log.e("TAG", "position === " + position + ";subIndex === " + subIndex);
76 | }
77 |
78 | }
79 |
80 | }
81 |
82 | @Override
83 | public int getItemCount() {
84 | int itemCount = 0;
85 | if (mGroupItemStatus == null || 0 == mGroupItemStatus.size()) {
86 | return itemCount;
87 | }
88 | for (int i = 0; i < mTreeList.size(); i++) {
89 | itemCount++;
90 | int subSize = mTreeList.get(i).getSubList().size();
91 | if (mGroupItemStatus.get(i)) {
92 | itemCount += subSize;
93 | } else {
94 | int minCount = mTreeList.get(i).getMinCount();
95 | itemCount += subSize > minCount ? minCount : subSize;
96 | }
97 | }
98 | return itemCount;
99 | }
100 |
101 | @Override
102 | public int getItemViewType(int position) {
103 | return getItemStatusByPosition(position).getViewType();
104 | }
105 |
106 | public void setData(List> list) {
107 | this.mTreeList.clear();
108 | this.mTreeList.addAll(list);
109 | initGroupItemStatus();
110 | notifyDataSetChanged();
111 | }
112 |
113 | public void toggleMoreHide(int groupIndex) {
114 | if (mTreeList.get(groupIndex).isEnableExpand()) {
115 | mGroupItemStatus.set(groupIndex, !mGroupItemStatus.get(groupIndex));
116 | notifyDataSetChanged();
117 | }
118 | }
119 |
120 | private void initGroupItemStatus() {
121 | if (mGroupItemStatus == null) {
122 | mGroupItemStatus = new ArrayList<>();
123 | }
124 | mGroupItemStatus.clear();
125 | for (TreeListDao item : mTreeList) {
126 | mGroupItemStatus.add(!item.isEnableExpand() || (item.isEnableExpand() && item.isExpand()));
127 | }
128 | }
129 |
130 | private ItemStatus getItemStatusByPosition(int position) {
131 |
132 | ItemStatus itemStatus = new ItemStatus();
133 | int itemCount = 0;
134 | int i = 0;
135 |
136 | while (i < mGroupItemStatus.size()) {
137 |
138 | if (itemCount == position) {
139 | itemStatus.setViewType(ItemStatus.VIEW_TYPE_GROUP_ITEM);
140 | itemStatus.setGroupItemIndex(i);
141 | break;
142 | } else if (itemCount > position) {
143 | itemStatus.setViewType(ItemStatus.VIEW_TYPE_SUB_ITEM);
144 | itemStatus.setGroupItemIndex(i - 1);
145 | TreeListDao dao = mTreeList.get(i - 1);
146 | int subSize = dao.getSubList().size();
147 | int temp = itemCount - subSize;
148 | // Log.i("TAG", "\ntemp === " + temp + ";itemcount === " + itemCount + ";subsize === " + subSize + ";pos === " + position);
149 | if (!mGroupItemStatus.get(i - 1)) {
150 | int ind;
151 | if (subSize > dao.getMinCount()) {
152 | ind = position - temp - subSize + dao.getMinCount();
153 | } else {
154 | ind = position - temp;
155 | }
156 | itemStatus.setSubItemIndex(ind);
157 | } else {
158 | itemStatus.setSubItemIndex(position - temp);
159 | }
160 | break;
161 | }
162 | TreeListDao dao = mTreeList.get(i);
163 | int subSize = dao.getSubList().size();
164 | int minCount = dao.getMinCount();
165 | int realCount = subSize > minCount ? minCount : subSize;
166 | itemCount += realCount + 1;
167 | if (mGroupItemStatus.get(i)) {
168 | if (subSize > minCount) {
169 | itemCount += (subSize - minCount);
170 | }
171 | }
172 | i++;
173 | }
174 |
175 | if (i >= mGroupItemStatus.size()) {
176 | itemStatus.setViewType(ItemStatus.VIEW_TYPE_SUB_ITEM);
177 | itemStatus.setGroupItemIndex(i - 1);
178 | int subSize = mTreeList.get(i - 1).getSubList().size();
179 | int minCount = mTreeList.get(i - 1).getMinCount();
180 | int temp = itemCount - subSize;
181 | // Log.i("TAG", "\ntemp2 === " + temp + ";itemcount === " + itemCount + ";subsize === " + subSize + ";pos === " + position);
182 | if (!mGroupItemStatus.get(i - 1)) {
183 | int ind;
184 | if (subSize > minCount) {
185 | ind = position - temp - subSize + minCount;
186 | } else {
187 | ind = position - temp;
188 | }
189 | itemStatus.setSubItemIndex(ind);
190 | } else {
191 | itemStatus.setSubItemIndex(position - temp);
192 | }
193 | }
194 |
195 | return itemStatus;
196 | }
197 |
198 |
199 | public class GroupItemViewHolder extends RecyclerView.ViewHolder {
200 | GroupItemViewHolder(@NonNull View itemView) {
201 | super(itemView);
202 | }
203 | }
204 |
205 | public class SubItemViewHolder extends RecyclerView.ViewHolder {
206 | SubItemViewHolder(@NonNull View itemView) {
207 | super(itemView);
208 | }
209 | }
210 |
211 | }
212 |
--------------------------------------------------------------------------------