Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,27 @@ There are some gifs from Demo:
- selectAll/deselectAll
- getAllSelectedNodes

Now supports [sevar83's IndeterminateCheckBox](https://github.com/sevar83/indeterminate-checkbox) as well as Android's android.widget.CheckBox

### Usage
**1.Reference the library from your module's build.gradle:**
```groovy
compile 'me.texy.treeview:treeview_lib:1.0.3'
```
1. You need to have this in your project's `build.gradle` file:

```Gradle
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
```
2. You need this in your app's module `build.gradle` file:
```Gradle
dependencies {
compile 'com.github.penguin86:TreeView:1.0.5@aar'
}
```

**2.Implement your all level's BaseNodeViewBinder**

Sample:
Expand Down
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
compileSdkVersion 27
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "me.texy.treeviewdemo"
Expand All @@ -24,10 +24,11 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:recyclerview-v7:27.0.2'
testCompile 'junit:junit:4.12'
compile project(':treeview_lib')
// compile 'me.texy.treeview:treeview_lib:1.0.1'
compile 'com.github.sevar83:indeterminate-checkbox:1.0.5@aar'

}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_first_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</LinearLayout>


<android.support.v7.widget.AppCompatCheckBox
<com.buildware.widget.indeterm.IndeterminateCheckBox
android:id="@+id/checkBox"
android:layout_width="30dp"
android:layout_height="30dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_second_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:textSize="15dp" />
</LinearLayout>

<android.support.v7.widget.AppCompatCheckBox
<com.buildware.widget.indeterm.IndeterminateCheckBox
android:id="@+id/checkBox"
android:layout_width="30dp"
android:layout_height="30dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_third_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:textSize="15dp" />
</LinearLayout>

<android.support.v7.widget.AppCompatCheckBox
<com.buildware.widget.indeterm.IndeterminateCheckBox
android:id="@+id/checkBox"
android:layout_width="30dp"
android:layout_height="30dp"
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,6 +17,8 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
8 changes: 5 additions & 3 deletions treeview_lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
compileSdkVersion 27
buildToolsVersion "25.0.2"

defaultConfig {
Expand All @@ -26,8 +26,10 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
testCompile 'junit:junit:4.12'
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.github.sevar83:indeterminate-checkbox:1.0.5@aar'
}
apply from: "bintray.gradle"
12 changes: 11 additions & 1 deletion treeview_lib/src/main/java/me/texy/treeview/TreeViewAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
package me.texy.treeview;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;

import com.buildware.widget.indeterm.IndeterminateCheckBox;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -140,7 +143,14 @@ public void onClick(View v) {

if (view != null && view instanceof CheckBox) {
final CheckBox checkableView = (CheckBox) view;
checkableView.setChecked(treeNode.isSelected());

if(treeNode.isSelected()){
checkableView.setChecked(true);
} else if(view instanceof IndeterminateCheckBox && TreeHelper.hasOneSelectedNodeAtLeast(treeNode)) {
((IndeterminateCheckBox) view).setIndeterminate(true);
} else {
checkableView.setChecked(false);
}

checkableView.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package me.texy.treeview.animator;

import android.support.annotation.NonNull;
import android.support.v4.animation.AnimatorCompatHelper;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
Expand Down Expand Up @@ -517,7 +516,7 @@ public void endAnimation(ViewHolder item) {
}

private void resetAnimation(ViewHolder holder) {
AnimatorCompatHelper.clearInterpolator(holder.itemView);
//AnimatorCompatHelper.clearInterpolator(holder.itemView);
endAnimation(holder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,19 @@ public static List<TreeNode> selectParentIfNeedWhenNodeSelected(TreeNode treeNod
parent.setSelected(true);
impactedParents.add(parent);
impactedParents.addAll(selectParentIfNeedWhenNodeSelected(parent, true));
} else if(select){
impactedParents.add(parent);
impactedParents.addAll(selectParentIfNeedWhenNodeSelected(parent, true));
} else if (!select && selectedBrotherCount == brothers.size() - 1) {
// only the condition that the size of selected's brothers
// is one less than total count can trigger the deselect
parent.setSelected(false);
impactedParents.add(parent);
impactedParents.addAll(selectParentIfNeedWhenNodeSelected(parent, false));
} else {
// only some selected/deselected: refresh parent view
impactedParents.add(parent);
impactedParents.addAll(selectParentIfNeedWhenNodeSelected(parent, false));
}
return impactedParents;
}
Expand Down