Giter Club home page Giter Club logo

treeview's Introduction

TreeView

A general TreeView implementation for android base on RecyclerView.

Setup

  1. Add it in your root build.gradle at the end of repositories:
allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}
  1. Add the dependency
dependencies {
  implementation "com.github.ikws4:TreeView:0.1.1"
}

Examples

FileTree

Check out FileTreeAdapter if you want to learn more.

demo.mp4

TaskTree

Create a custom adapter by extends TreeView.Adapter.

class TaskTreeAdapter extends TreeView.Adapter<TaskTreeAdapter.ViewHolder, String> {

  @Override
  public ViewHolder onCreateViewHolder(View view) {
    return new ViewHolder(view);
  }

  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    holder.name.setText(items.get(position).getValue());
  }

  @Override
  public int getLayoutRes() {
    return R.layout.item_tasktree;
  }

  static class ViewHolder extends TreeView.ViewHolder {
    TextView name;

    public ViewHolder(@NonNull View itemView) {
      super(itemView);
      name = itemView.findViewById(R.id.name);
    }
  }
}

item_tasktree.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/name"
        android:layout_marginLeft="4dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <io.github.ikws4.treeview.TreeView
        android:id="@+id/tree_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Bind TreeView with your custom adapter by calling treeView.setAdapter()

TreeView treeView = findViewById(R.id.tree_view);
TaskTreeAdapter adapter = new TaskTreeAdapter();
treeView.setAdapter(adapter);

TreeItem<String> root = new TreeItem<>("Tasks", true);
TreeItem<String> daily = new TreeItem<>("Daily", true);
TreeItem<String> weekly = new TreeItem<>("Weekly", true);

daily.getChildren().add(new TreeItem<>("Wake up at 6:00"));
daily.getChildren().add(new TreeItem<>("Drink at least 4 cups of water"));

weekly.getChildren().add(new TreeItem<>("Week review"));
weekly.getChildren().add(new TreeItem<>("Reward your self"));

root.setExpanded(true);
root.getChildren().add(daily);
root.getChildren().add(weekly);

adapter.setRoot(root, true);

Thanks

This library was inspired by RecyclerTreeView

License

MIT License

Copyright (c) 2022 ikws4

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

treeview's People

Contributors

ikws4 avatar

Stargazers

Daria avatar GAURAV avatar thank_classmate avatar  avatar Simon avatar Trung Duc Tran avatar weg avatar Arseny Savchenko avatar Anshul Saraf avatar feodott avatar Vladimir Medyannikov avatar Uğur Erol avatar Android Prime avatar Arda K. avatar Evert Moreno avatar  avatar Basil Kotov avatar  avatar  avatar  avatar Alex Styl avatar Robert avatar Sorab Pithawala avatar Pavel Kuznetsov avatar Bhargav Pandya avatar yusuf yiğit avatar Chimbori avatar Yeahii avatar

Watchers

 avatar  avatar

treeview's Issues

Ui got freez when the child have many items

Record_2022-07-30-11-18-45.mp4

vendor (include 40 folders and 1 files as child)
node_modules (include 300+ folders as child)

I think it's occured by this or maybe this

I have tried to used with java.util.concurrent.Executor (in case asynctask is deprecated and not familiar with rxjava) but somehow the view didn't show anything like it doesn't get the notify

How can I implemented files tree for DocumentFile[]

I've tried many times to list DocumentFile[] which is provided by StorageAccessFramework to avoid some storage restricted in newer API lvl and also access the termux's home dir

Could you help me a bit:)

IMG_20220725_121554

Conflict between item position

the structure is like

  • folder
    -- folder1
    -- folder2
  • file1
  • file2

When the folder is expand
the position of folder 1 and 2 are become 1/2
Incase the position of file 1 and 2 is still 1/2

So I can't use some methods for adapter which is strongly depend on position
like

notifyItemRemoved(int position)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.