content: /*
   * Copyright 2017 JessYan
   *
   * 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 the License.
   */
  package com.alex.voiceplayer;
  
  import android.content.Context;
  import android.view.View;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  /**
   * ================================================
   * 基类 {@link RecyclerView.ViewHolder}
   * <p>
   * Created by JessYan on 2015/11/24.
   * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
   * <a href="https://github.com/JessYanCoding">Follow me</a>
   * ================================================
   */
  public abstract class BaseHolder<T> extends RecyclerView.ViewHolder implements View.OnClickListener {
      protected final String TAG = this.getClass().getSimpleName();
      protected OnViewClickListener mOnViewClickListener = null;
      /**
       * 用于加载图片的管理类, 默认使用 Glide, 使用策略模式, 可替换框架
       */
      protected Context mContext;
  
      public BaseHolder(View itemView) {
          super(itemView);
          //点击事件
          itemView.setOnClickListener(this);
          mContext = itemView.getContext();
      }
  
      /**
       * 设置数据
       *
       * @param data     数据
       * @param position 在 RecyclerView 中的位置
       */
      public abstract void setData(@NonNull T data, int position);
  
      /**
       * 在 Activity 的 onDestroy 中使用 {@link DefaultAdapter#releaseAllHolder(RecyclerView)} 方法 (super.onDestroy() 之前)
       * {@link BaseHolder#onRelease()} 才会被调用, 可以在此方法中释放一些资源
       */
      protected void onRelease() {
  
      }
  
      @Override
      public void onClick(View view) {
          if (mOnViewClickListener != null) {
              mOnViewClickListener.onViewClick(view, this.getPosition());
          }
      }
  
      public void setOnItemClickListener(OnViewClickListener listener) {
          this.mOnViewClickListener = listener;
      }
  
      /**
       * item 点击事件
       */
      public interface OnViewClickListener {
  
          /**
           * item 被点击
           *
           * @param view     被点击的 {@link View}
           * @param position 在 RecyclerView 中的位置
           */
          void onViewClick(View view, int position);
      }
  }