content: package com.amrdeveloper.treeviewlib.todotree;
  
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import com.amrdeveloper.treeview.TreeNode;
  import com.amrdeveloper.treeview.TreeViewAdapter;
  import com.amrdeveloper.treeview.TreeViewHolderFactory;
  import com.amrdeveloper.treeviewlib.R;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class TodoTreeFragment extends Fragment  {
  
      private TreeViewAdapter treeViewAdapter;
  
      private static final String TAG = "TodoTreeFragment";
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(true);
      }
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_todo_tree, container, false);
  
          RecyclerView recyclerView = view.findViewById(R.id.files_recycler_view);
          recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
          recyclerView.setNestedScrollingEnabled(false);
  
          TreeViewHolderFactory factory = (v, layout) -> new TodoViewHolder(v);
  
          treeViewAdapter = new TreeViewAdapter(factory);
          recyclerView.setAdapter(treeViewAdapter);
  
          TreeNode workCategory = new TodoNode("Work", R.layout.list_item_todo);
          workCategory.addChild(new TodoNode("Task 1", R.layout.list_item_todo));
          workCategory.addChild(new TodoNode("Task 2", R.layout.list_item_todo));
          workCategory.addChild(new TodoNode("Task 3", R.layout.list_item_todo));
  
          TreeNode educationCategory = new TodoNode("Education", R.layout.list_item_todo);
          educationCategory.addChild(new TodoNode("Course 1", R.layout.list_item_todo));
          educationCategory.addChild(new TodoNode("Course 2", R.layout.list_item_todo));
          educationCategory.addChild(new TodoNode("Course 3", R.layout.list_item_todo));
  
          List<TreeNode> todoRoots = new ArrayList<>();
          todoRoots.add(workCategory);
          todoRoots.add(educationCategory);
  
          treeViewAdapter.updateTreeNodes(todoRoots);
  
          return view;
      }
  
      @Override
      public boolean onOptionsItemSelected(@NonNull MenuItem item) {
          final int menuId = item.getItemId();
          if (menuId == R.id.expand_all_action) {
              treeViewAdapter.expandAll();
          }
          else if (menuId == R.id.collapse_all_action) {
              treeViewAdapter.collapseAll();
          }
          else if (menuId == R.id.expand_selected_action) {
              treeViewAdapter.expandNode(treeViewAdapter.getSelectedNode());
          }
          else if (menuId == R.id.collapse_selected_action) {
              treeViewAdapter.collapseNode(treeViewAdapter.getSelectedNode());
          }
          else if (menuId == R.id.expand_selected_branch_action) {
              treeViewAdapter.expandNodeBranch(treeViewAdapter.getSelectedNode());
          }
          else if (menuId == R.id.collapse_selected_branch_action) {
              treeViewAdapter.collapseNodeBranch(treeViewAdapter.getSelectedNode());
          }
          else if (menuId == R.id.expand_selected_level_action) {
              treeViewAdapter.expandNodesAtLevel(2);
          }
          return super.onOptionsItemSelected(item);
      }
  }
  