/*
 * Copyright 2016 - 2017 ShineM (Xinyuan)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under.
 */

package com.tyron.ui.treeview.base;

import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import com.tyron.ui.treeview.TreeNode;
import com.tyron.ui.treeview.TreeView;

/** Created by zxy on 17/4/23. */
public abstract class BaseNodeViewBinder<D> extends RecyclerView.ViewHolder {
  /**
   * This reference of TreeView make BaseNodeViewBinder has the ability to expand node or select
   * node.
   */
  protected TreeView<D> treeView;

  public BaseNodeViewBinder(View itemView) {
    super(itemView);
  }

  public void setTreeView(TreeView<D> treeView) {
    this.treeView = treeView;
  }

  /**
   * Bind your data to view,you can get the data from treeNode by getValue()
   *
   * @param treeNode Node data
   */
  public abstract void bindView(TreeNode<D> treeNode);

  /**
   * if you do not want toggle the node when click whole item view,then you can assign a view to
   * trigger the toggle action
   *
   * @return The assigned view id to trigger expand or collapse.
   */
  public int getToggleTriggerViewId() {
    return 0;
  }

  /**
   * Callback when a toggle action happened (only by clicked)
   *
   * @param treeNode The toggled node
   * @param expand Expanded or collapsed
   */
  public void onNodeToggled(TreeNode<D> treeNode, boolean expand) {
    // empty
  }

  /** Callback when a node is long clicked. */
  public boolean onNodeLongClicked(View view, TreeNode<D> treeNode, boolean expanded) {
    return false;
  }
}
