Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and Structure changes #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
18 changes: 1 addition & 17 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 29 additions & 15 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ allprojects {
app build.gradle
```groovy
dependencies {
compile 'com.github.TellH:RecyclerTreeView:1.2.0'
implementation 'com.github.AZKZero:RecyclerTreeView:1.3.0'
}
```



### Quick Start

- Create a Java bean class and implement the LayoutItemType, to attach item layout id to it.
- Create a Java bean class and implement the LayoutItemType
- Attach item layout id to it.
- Attach toggle view id to it. (also you can stop toggle entirely or use the full view as toggle)

```java
public class Dir implements LayoutItemType {
Expand All @@ -41,12 +43,18 @@ public class Dir implements LayoutItemType {
public int getLayoutId() {
return R.layout.item_dir;
}

@Override
public int getToggleViewId() {
return R.id.iv_arrow;
}
}
```



- Create a ViewBinder to bind view with the data bean. As you see, `provideViewHolder(View itemView)` corresponds for `onCreateViewHolder` in RecyclerView, and `bindView` corresponds for `onBindViewHolder` in RecyclerView.
- For safety, follow the same ids provided the bean files.

```java
public class FileNodeBinder extends TreeViewBinder<FileNodeBinder.ViewHolder> {
Expand All @@ -66,6 +74,11 @@ public class FileNodeBinder extends TreeViewBinder<FileNodeBinder.ViewHolder> {
return R.layout.item_file;
}

@Override
public int getToggleViewId() {
return NO_TOGGLE_ATTACHED;
}

public class ViewHolder extends TreeViewBinder.ViewHolder {
public TextView tvName;

Expand Down Expand Up @@ -128,7 +141,7 @@ public class FileNodeBinder extends TreeViewBinder<FileNodeBinder.ViewHolder> {
public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
if (!node.isLeaf()) {
//Update and toggle the node.
onToggle(!node.isExpand(), holder);
//onToggle(!node.isExpand(), holder); onToggle is now called automatically
}
return false;
}
Expand Down
24 changes: 14 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 31
buildToolsVersion '30.0.3'
defaultConfig {
applicationId "tellh.com.recyclertreeview"
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
testCompile 'junit:junit:4.12'
compile project(path: ':recyclertreeview-lib')
// compile 'com.github.TellH:RecyclerTreeView:1.2.0'
implementation project(path: ':recyclertreeview-lib')
// implementation 'com.github.TellH:RecyclerTreeView:1.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tellh.com.recyclertreeview;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/tellh/com/recyclertreeview/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tellh.com.recyclertreeview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -74,9 +75,10 @@ private void initData() {
adapter.setOnTreeNodeListener(new TreeViewAdapter.OnTreeNodeListener() {
@Override
public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
Toast.makeText(MainActivity.this, "Item Clicked!", Toast.LENGTH_SHORT).show();
if (!node.isLeaf()) {
//Update and toggle the node.
onToggle(!node.isExpand(), holder);
// onToggle(!node.isExpand(), holder);
// if (!node.isExpand())
// adapter.collapseBrotherNode(node);
}
Expand All @@ -85,6 +87,8 @@ public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {

@Override
public void onToggle(boolean isExpand, RecyclerView.ViewHolder holder) {
Toast.makeText(MainActivity.this, "Item Toggled!", Toast.LENGTH_SHORT).show();

DirectoryNodeBinder.ViewHolder dirViewHolder = (DirectoryNodeBinder.ViewHolder) holder;
final ImageView ivArrow = dirViewHolder.getIvArrow();
int rotateDegree = isExpand ? 90 : -90;
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/tellh/com/recyclertreeview/bean/Dir.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public Dir(String dirName) {
public int getLayoutId() {
return R.layout.item_dir;
}

@Override
public int getToggleViewId() {
return R.id.iv_arrow;
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/tellh/com/recyclertreeview/bean/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public File(String fileName) {
public int getLayoutId() {
return R.layout.item_file;
}

@Override
public int getToggleViewId() {
return NO_TOGGLE_ATTACHED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public int getLayoutId() {
return R.layout.item_dir;
}

@Override
public int getToggleViewId() {
return R.id.iv_arrow;
}

public static class ViewHolder extends TreeViewBinder.ViewHolder {
private ImageView ivArrow;
private TextView tvName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public int getLayoutId() {
return R.layout.item_file;
}

@Override
public int getToggleViewId() {
return NO_TOGGLE_ATTACHED;
}

public class ViewHolder extends TreeViewBinder.ViewHolder {
public TextView tvName;

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rv"
Expand Down
Loading