/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.view.things;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ntels.kneet.v3.R;
import com.ntels.kneet.v3.common.AppConfig;
import com.ntels.kneet.v3.common.Constants;
import com.ntels.kneet.v3.common.c_interface.ListInterface;
import com.ntels.kneet.v3.common.util.Util;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * <pre>
 * 1. ClassName :   FragmentThingsAdapter
 * 2. FileName  :   FragmentThingsAdapter.java
 * 3. Package   :   com.ntels.kneet.v3.view.things
 * 4. Date      :   2016-11-28
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class FragmentThingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

  private ListInterface adapterCallback;
  private AppConfig appConfig;
  private Util util = new Util();
  public static final int TYPE_HEADER = 0;
  public static final int TYPE_ITEM = 1;
  public static final int TYPE_FOOTER = 2;
  private ArrayList<HashMap<String, Object>> alTotalList = new ArrayList<HashMap<String, Object>>();
  private Context context;
  private int listLayoutHead;
  private int listLayoutItem;
  private int listLayoutFooter;
  private String httpValue = "";
  private Boolean isListCheck = false;
  private Boolean isHeaderCheck = false;
  private Boolean isFooterCheck = false;
  private Boolean isFooterVisible = false;

  public String getHttpValue() {

    return httpValue;
  }

  public void setHttpValue(String value) {

    httpValue = value;
  }

  public void setListCheck(boolean isCheck) {

    isListCheck = isCheck;
  }

  public boolean getListCheck() {

    return isListCheck;
  }

  public void setHeaderCheck(boolean isCheck) {

    isHeaderCheck = isCheck;
  }

  public boolean getHeaderCheck() {

    return isHeaderCheck;
  }

  public void setFooterCheck(boolean isCheck) {

    isFooterCheck = isCheck;
  }

  public boolean getFooterCheck() {

    return isFooterCheck;
  }

  public void setFooterVisible(boolean isVisible) {

    isFooterVisible = isVisible;
  }

  public boolean getFooterVisible() {

    return isFooterVisible;
  }

  @Override
  public int getItemCount() {

    return alTotalList.size();
  }

  /**
   * 생성자.
   *
   * @param context 컨텍스트
   * @param listLayoutHead Header layout resource id
   * @param listLayoutItem Item layout resource id
   * @param listLayoutFooter Footer layout resource id
   * @param alTmp adapter에 표현 할 data
   * @param adapterCallback callback listener
   */
  public FragmentThingsAdapter(Context context, int listLayoutHead, int listLayoutItem,
                               int listLayoutFooter, ArrayList<HashMap<String, Object>> alTmp,
                               ListInterface adapterCallback) {

    this.context = context;
    alTotalList = alTmp;
    this.listLayoutHead = listLayoutHead;
    this.listLayoutItem = listLayoutItem;
    this.listLayoutFooter = listLayoutFooter;
    appConfig = (AppConfig) this.context.getApplicationContext();

    try {
      this.adapterCallback = adapterCallback;
    } catch (ClassCastException ex) {
      ex.printStackTrace();
    }
  }

  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    if (viewType == TYPE_ITEM) {
      View view = LayoutInflater.from(parent.getContext()).inflate(listLayoutItem, parent, false);
      return new ItemViewHolder(view);
    } else if (viewType == TYPE_HEADER) {
      View view = LayoutInflater.from(parent.getContext()).inflate(listLayoutHead, parent, false);
      return new HeaderViewHolder(view);
    } else if (viewType == TYPE_FOOTER) {
      View view = LayoutInflater.from(parent.getContext()).inflate(listLayoutFooter, parent, false);
      return new FooterViewHolder(view);
    }

    throw new RuntimeException("there is no mType that matches the mType " + viewType
        + " + make sure your using types correctly");
  }

  /**
   * 1. ClassName :   ItemViewHolder
   * 2. FileName  :   FragmentThingsAdapter.java
   * 3. Package   :   com.ntels.kneet.v3.view.things
   * 4. Date      :   2016-11-28
   * 5. Author    :   aaron
   * 6. Comment   :   Initialize
   */
  public static class ItemViewHolder extends RecyclerView.ViewHolder {

    public LinearLayout llRowRoot;
    public LinearLayout llRowBody;
    public LinearLayout llRowControl;
    public LinearLayout llRowControlBtn;
    public LinearLayout llRowDelete;
    public LinearLayout llRowOffline;
    public LinearLayout llLoading;
    public RelativeLayout rlRowBody;
    public ImageView ivRowIcon;
    public TextView tvRowTitle;
    public TextView tvRowControl;
    public TextView tvRowBody;
    public TextView tvRowOffline;
    public Button btnRowControl;
    public ImageView ivRowDelete;

    /**
     * 생성자.
     *
     * @param itemView Item view holder에 사용 할 view.
     */
    public ItemViewHolder(View itemView) {

      super(itemView);
      llRowRoot = (LinearLayout) itemView.findViewById(R.id.llRowRoot);
      llRowBody = (LinearLayout) itemView.findViewById(R.id.llRowBody);
      llRowControl = (LinearLayout) itemView.findViewById(R.id.llRowControl);
      llRowControlBtn = (LinearLayout) itemView.findViewById(R.id.llRowControlBtn);
      llRowDelete = (LinearLayout) itemView.findViewById(R.id.llRowDelete);
      llRowOffline = (LinearLayout) itemView.findViewById(R.id.llRowOffline);
      llLoading = (LinearLayout) itemView.findViewById(R.id.llLoading);
      rlRowBody = (RelativeLayout) itemView.findViewById(R.id.rlRowBody);
      ivRowIcon = (ImageView) itemView.findViewById(R.id.ivRowIcon);
      tvRowTitle = (TextView) itemView.findViewById(R.id.tvRowTitle);
      tvRowBody = (TextView) itemView.findViewById(R.id.tvRowBody);
      tvRowControl = (TextView) itemView.findViewById(R.id.tvRowControl);
      tvRowOffline = (TextView) itemView.findViewById(R.id.tvRowOffline);
      btnRowControl = (Button) itemView.findViewById(R.id.btnRowControl);
      ivRowDelete = (ImageView) itemView.findViewById(R.id.ivRowDelete);
    }
  }

  /**
   * <pre>
   * 1. ClassName :   HeaderViewHolder
   * 2. FileName  :   FragmentThingsAdapter.java
   * 3. Package   :   com.ntels.kneet.v3.view.things
   * 4. Date      :   2016-11-28
   * 5. Author    :   aaron
   * 6. Comment   :   Initialize
   * </pre>
   */
  public static class HeaderViewHolder extends RecyclerView.ViewHolder {

    public LinearLayout llRowRoot;
    public LinearLayout llRowBody;
    public TextView tvTitle;

    public HeaderViewHolder(View itemView) {

      super(itemView);
    }
  }

  /**
   * <pre>
   * 1. ClassName :   FooterViewHolder
   * 2. FileName  :   FragmentThingsAdapter.java
   * 3. Package   :   com.ntels.kneet.v3.view.things
   * 4. Date      :   2016-11-28
   * 5. Author    :   aaron
   * 6. Comment   :   Initialize
   * </pre>
   */
  public static class FooterViewHolder extends RecyclerView.ViewHolder {

    public LinearLayout llFooterProgress;
    public LinearLayout llFooterRoot;
    public LinearLayout llFooterBody;
    public ImageView ivFooterAdd;

    /**
     * 생성자.
     *
     * @param itemView Footer view holder에 사용할 view
     */
    public FooterViewHolder(View itemView) {

      super(itemView);

      llFooterProgress = (LinearLayout) itemView.findViewById(R.id.llFooterProgress);
      llFooterRoot = (LinearLayout) itemView.findViewById(R.id.llFooterRoot);
      llFooterBody = (LinearLayout) itemView.findViewById(R.id.llFooterBody);
      ivFooterAdd = (ImageView) itemView.findViewById(R.id.ivFooterAdd);
    }
  }

  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    try {
      HashMap<String, Object> hmItem = new HashMap<String, Object>();
      hmItem = alTotalList.get(position);
      if (holder instanceof ItemViewHolder) {
        ItemViewHolder itemViewHolerView = (ItemViewHolder) holder;

        // (장치의) 접속 상태 (ON / OFF / none)
        String onlineState = util.null2string(hmItem.get(Constants.HTTP_online_state));
        // (default) 커맨드 클래스 값의 단위
        String unit = util.null2string(hmItem.get(Constants.HTTP_unit));
        // (default) 커맨드클래스 유형 ID
        String cmdclsTypeId = util.null2string(hmItem.get(Constants.HTTP_cmdcls_type_id));
        // 디바이스클래스 타입 ID
        String deviceclassTypeId = util.null2string(hmItem.get(Constants.HTTP_deviceclass_type_id));

        // 2016.08.03 노드 이미지 로컬에 있는 이미지를 사용하는걸로 변경.
        itemViewHolerView.ivRowIcon.setImageResource(util.getImageId(context, "img_"
            + deviceclassTypeId));

        itemViewHolerView.llRowOffline.setVisibility(View.GONE);
        itemViewHolerView.llRowControl.setVisibility(View.GONE);
        itemViewHolerView.llRowDelete.setVisibility(View.GONE);

        // 장치명
        String deviceName = util.null2string(hmItem.get(Constants.HTTP_device_name));
        itemViewHolerView.tvRowTitle.setText(deviceName);

        // (default) 커맨드클래스 유형 ID number
        int cmdclsTypeIdNum = util.null2int(hmItem.get(Constants.HTTP_cmdcls_type_id));
        // (default) 커맨드클래스 장치 상태정보 값 (N-ISC 질의 결과 ,none = 정보없음)
        String contentValue = util.null2string(hmItem.get(Constants.HTTP_content_value));
        String tempValue = "";
        String select = util.getStringValues(context, "CMDCLS_TYPE_ID_" + cmdclsTypeIdNum
            + "_BG_DEFAULT");
        if (contentValue.equals("none")) {
          tempValue = util.getStringValues(context, "CMDCLS_TYPE_ID_" + cmdclsTypeIdNum
              + "_" + select);
          contentValue = select;
        } else {
          tempValue = util.getStringValues(context, "CMDCLS_TYPE_ID_" + cmdclsTypeIdNum
              + "_" + contentValue);
        }

        final View vLoding = itemViewHolerView.llLoading;
        String requestTime = util.null2string(hmItem.get(Constants.HTTP_request_time));
        if (!requestTime.equals("")) {
          itemViewHolerView.llLoading.setVisibility(View.VISIBLE);
        } else {
          itemViewHolerView.llLoading.setVisibility(View.GONE);
        }

        itemViewHolerView.btnRowControl.setTag(position);
        itemViewHolerView.llRowControlBtn.setVisibility(View.GONE);
        switch (cmdclsTypeIdNum) {
          //SENSOR_BINARY
          case Constants.CMDCLS_TYPE_ID_11001:
          case Constants.CMDCLS_TYPE_ID_11002:
          case Constants.CMDCLS_TYPE_ID_11003:
          case Constants.CMDCLS_TYPE_ID_11004:
          case Constants.CMDCLS_TYPE_ID_11005:
          case Constants.CMDCLS_TYPE_ID_11006:
          case Constants.CMDCLS_TYPE_ID_11007:
          case Constants.CMDCLS_TYPE_ID_11008:
          case Constants.CMDCLS_TYPE_ID_11009:
          case Constants.CMDCLS_TYPE_ID_11010:
          case Constants.CMDCLS_TYPE_ID_11011:
          case Constants.CMDCLS_TYPE_ID_11012:
          case Constants.CMDCLS_TYPE_ID_11013:
          case Constants.CMDCLS_TYPE_ID_11014:
          case Constants.CMDCLS_TYPE_ID_11015:
          case Constants.CMDCLS_TYPE_ID_11016:
          case Constants.CMDCLS_TYPE_ID_11017:
          case Constants.CMDCLS_TYPE_ID_11018:
            itemViewHolerView.tvRowControl.setText(tempValue);
            if (contentValue.equals(select)) {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;

          //SWITCH_BINARY
          case Constants.CMDCLS_TYPE_ID_17001:
          case Constants.CMDCLS_TYPE_ID_17002:
          case Constants.CMDCLS_TYPE_ID_17003:
          case Constants.CMDCLS_TYPE_ID_17004:
          case Constants.CMDCLS_TYPE_ID_17005:
          case Constants.CMDCLS_TYPE_ID_17006:
            itemViewHolerView.tvRowControl.setText(tempValue);
            itemViewHolerView.llRowControlBtn.setVisibility(View.VISIBLE);

            if (contentValue.equals(select)) {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(
                  util.getColor(context, R.color.color_text_01));
              itemViewHolerView.btnRowControl.setBackgroundResource(
                  R.drawable.img_things_list_btn_onoff_on);
            } else {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
              itemViewHolerView.btnRowControl.setBackgroundResource(
                  R.drawable.img_things_list_btn_onoff_off);
            }

            itemViewHolerView.btnRowControl.setOnClickListener(new View.OnClickListener() {
              int tag = 0;
              private Intent intent;

              @Override
              public void onClick(View view) {

                if (alTotalList == null || alTotalList.isEmpty()) {
                  return;
                }

                tag = (int) view.getTag();
                String cmdclsTypeId = util.null2string(alTotalList.get(tag)
                    .get(Constants.HTTP_cmdcls_type_id));
                String contentValue = util.null2string(alTotalList.get(tag)
                    .get(Constants.HTTP_content_value));
                if (contentValue.equals(util.getStringValues(context, "CMDCLS_TYPE_ID_"
                    + cmdclsTypeId + "_BG_DEFAULT"))) {
                  setHttpValue("ON");
                } else {
                  setHttpValue("OFF");
                }
                vLoding.setVisibility(View.VISIBLE);
                adapterCallback.onCallAction(3, tag);
              }
            });
            break;
          // VALVE
          case Constants.CMDCLS_TYPE_ID_36002:
            itemViewHolerView.tvRowControl.setText(tempValue);
            itemViewHolerView.llRowControlBtn.setVisibility(View.VISIBLE);

            if (contentValue.equals(select)) {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }

            itemViewHolerView.btnRowControl.setBackgroundResource(
                R.drawable.img_things_list_btn_lockunlock_lock);
            itemViewHolerView.btnRowControl.setOnClickListener(new View.OnClickListener() {
              int tag = 0;
              private Intent intent;

              @Override
              public void onClick(View view) {

                tag = (int) view.getTag();
                setHttpValue("CLOSE");
                vLoding.setVisibility(View.VISIBLE);
                adapterCallback.onCallAction(3, tag);
              }
            });
            break;
          // LOCK
          case Constants.CMDCLS_TYPE_ID_14001:
            itemViewHolerView.tvRowControl.setText(tempValue);
            itemViewHolerView.llRowControlBtn.setVisibility(View.VISIBLE);

            if (contentValue.equals(select)) {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                      R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(
                      util.getColor(context, R.color.color_text_01));
              itemViewHolerView.btnRowControl.setBackgroundResource(
                      R.drawable.img_things_list_btn_lockunlock_unlock);
            } else {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                      R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                      context, R.color.color_text_02));
              itemViewHolerView.btnRowControl.setBackgroundResource(
                      R.drawable.img_things_list_btn_lockunlock_lock);
            }

            itemViewHolerView.btnRowControl.setOnClickListener(new View.OnClickListener() {
              int tag = 0;
              private Intent intent;

              @Override
              public void onClick(View view) {

                if (alTotalList == null || alTotalList.isEmpty()) {
                  return;
                }

                tag = (int) view.getTag();
                String cmdclsTypeId = util.null2string(alTotalList.get(tag)
                        .get(Constants.HTTP_cmdcls_type_id));
                String contentValue = util.null2string(alTotalList.get(tag)
                        .get(Constants.HTTP_content_value));
                if (contentValue.equals(util.getStringValues(context, "CMDCLS_TYPE_ID_"
                        + cmdclsTypeId + "_BG_DEFAULT"))) {
                  setHttpValue("UNLOCK");
                } else {
                  setHttpValue("LOCK");
                }
                vLoding.setVisibility(View.VISIBLE);
                adapterCallback.onCallAction(3, tag);
              }
            });
            break;
          // SENSOR_MULTILEVEL
          case Constants.CMDCLS_TYPE_ID_12001:
          case Constants.CMDCLS_TYPE_ID_12002:
          case Constants.CMDCLS_TYPE_ID_12003:
          case Constants.CMDCLS_TYPE_ID_12004:
          case Constants.CMDCLS_TYPE_ID_12005:
          case Constants.CMDCLS_TYPE_ID_12006:
          case Constants.CMDCLS_TYPE_ID_12007:
          case Constants.CMDCLS_TYPE_ID_12008:
          case Constants.CMDCLS_TYPE_ID_12009:
          case Constants.CMDCLS_TYPE_ID_12010:
          case Constants.CMDCLS_TYPE_ID_12011:
          case Constants.CMDCLS_TYPE_ID_12012:
          case Constants.CMDCLS_TYPE_ID_12013:
          case Constants.CMDCLS_TYPE_ID_12014:
          case Constants.CMDCLS_TYPE_ID_12015:
          case Constants.CMDCLS_TYPE_ID_12016:
          case Constants.CMDCLS_TYPE_ID_12017:
          case Constants.CMDCLS_TYPE_ID_12018:
          case Constants.CMDCLS_TYPE_ID_12019:
          case Constants.CMDCLS_TYPE_ID_12020:
          case Constants.CMDCLS_TYPE_ID_12021:
          case Constants.CMDCLS_TYPE_ID_12022:
          case Constants.CMDCLS_TYPE_ID_12023:
          case Constants.CMDCLS_TYPE_ID_12024:
          case Constants.CMDCLS_TYPE_ID_12025:
          case Constants.CMDCLS_TYPE_ID_12026:
          case Constants.CMDCLS_TYPE_ID_12027:
          case Constants.CMDCLS_TYPE_ID_12028:
          case Constants.CMDCLS_TYPE_ID_12029:
          case Constants.CMDCLS_TYPE_ID_12030:
          case Constants.CMDCLS_TYPE_ID_12031:
          case Constants.CMDCLS_TYPE_ID_12032:
          case Constants.CMDCLS_TYPE_ID_12033:
          case Constants.CMDCLS_TYPE_ID_12034:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //METER_CURRENT
          case Constants.CMDCLS_TYPE_ID_15001:
          case Constants.CMDCLS_TYPE_ID_15002:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //METER_TOTAL
          case Constants.CMDCLS_TYPE_ID_16001:
          case Constants.CMDCLS_TYPE_ID_16002:
          case Constants.CMDCLS_TYPE_ID_16003:
          case Constants.CMDCLS_TYPE_ID_16004:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //SWITCH_MULTILEVEL
          case Constants.CMDCLS_TYPE_ID_18001:
          case Constants.CMDCLS_TYPE_ID_18002:
          case Constants.CMDCLS_TYPE_ID_18003:
          case Constants.CMDCLS_TYPE_ID_18004:
          case Constants.CMDCLS_TYPE_ID_18005:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //THERMOSTAT_SETPOINT
          case Constants.CMDCLS_TYPE_ID_19001:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          // METER
          case Constants.CMDCLS_TYPE_ID_29001:
          case Constants.CMDCLS_TYPE_ID_29002:
          case Constants.CMDCLS_TYPE_ID_29003:
          case Constants.CMDCLS_TYPE_ID_29004:
          case Constants.CMDCLS_TYPE_ID_29005:
          case Constants.CMDCLS_TYPE_ID_29006:
          case Constants.CMDCLS_TYPE_ID_29007:
          case Constants.CMDCLS_TYPE_ID_29008:
          case Constants.CMDCLS_TYPE_ID_29009:
          case Constants.CMDCLS_TYPE_ID_29010:
          case Constants.CMDCLS_TYPE_ID_29011:
          case Constants.CMDCLS_TYPE_ID_29012:
          case Constants.CMDCLS_TYPE_ID_29013:
          case Constants.CMDCLS_TYPE_ID_29014:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //BATTERY
          case Constants.CMDCLS_TYPE_ID_30001:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          //SYSTEM
          case Constants.CMDCLS_TYPE_ID_34006:
          case Constants.CMDCLS_TYPE_ID_34007:
          case Constants.CMDCLS_TYPE_ID_34008:
          case Constants.CMDCLS_TYPE_ID_34009:
          case Constants.CMDCLS_TYPE_ID_34010:
          case Constants.CMDCLS_TYPE_ID_34011:
          case Constants.CMDCLS_TYPE_ID_34012:
          case Constants.CMDCLS_TYPE_ID_34013:
          case Constants.CMDCLS_TYPE_ID_34014:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
          case Constants.CMDCLS_TYPE_ID_38001:
            itemViewHolerView.ivRowIcon.setBackgroundResource(R.drawable.img_thing_icon_bg_active);
            itemViewHolerView.tvRowControl.setText("Online");
            itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                context, R.color.color_text_02));
            break;

          case Constants.CMDCLS_TYPE_ID_38003:
            itemViewHolerView.tvRowControl.setText(tempValue);

            if (contentValue.equals(select)) {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;

          default:
            if (contentValue.equals("none")) {
              itemViewHolerView.tvRowControl.setText("-");
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_default);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_01));
            } else {
              itemViewHolerView.tvRowControl.setText(contentValue + unit);
              itemViewHolerView.ivRowIcon.setBackgroundResource(
                  R.drawable.img_thing_icon_bg_active);
              itemViewHolerView.tvRowControl.setTextColor(util.getColor(
                  context, R.color.color_text_02));
            }
            break;
        }

        if (isListCheck) {
          itemViewHolerView.llRowControl.setVisibility(View.GONE);
          itemViewHolerView.llRowDelete.setVisibility(View.VISIBLE);
          itemViewHolerView.llRowOffline.setVisibility(View.GONE);
          itemViewHolerView.llLoading.setVisibility(View.GONE);
          if (onlineState.equals("OFF")
              || appConfig.getSelect_Homegrp_Homehub_Online_State().equals("OFF")) {
            itemViewHolerView.ivRowIcon.setBackgroundResource(R.drawable.img_thing_icon_bg_default);
          }
        } else {
          if (onlineState.equals("OFF")
              || appConfig.getSelect_Homegrp_Homehub_Online_State().equals("OFF")) {
            itemViewHolerView.ivRowIcon.setBackgroundResource(R.drawable.img_thing_icon_bg_default);
            itemViewHolerView.llRowControl.setVisibility(View.GONE);
            itemViewHolerView.llRowDelete.setVisibility(View.GONE);
            itemViewHolerView.llRowOffline.setVisibility(View.VISIBLE);
            itemViewHolerView.llLoading.setVisibility(View.GONE);
          } else {
            itemViewHolerView.llRowControl.setVisibility(View.VISIBLE);
            itemViewHolerView.llRowDelete.setVisibility(View.GONE);
            itemViewHolerView.llRowOffline.setVisibility(View.GONE);
          }
        }

        itemViewHolerView.llRowBody.setTag(position);
        itemViewHolerView.llRowBody.setOnClickListener(new View.OnClickListener() {
          int tag = 0;
          private Intent intent;

          @Override
          public void onClick(View view) {

            tag = (int) view.getTag();
            if (isListCheck) {
              adapterCallback.onCallAction(2, tag);
            } else {
              adapterCallback.onCallAction(1, tag);
            }
          }
        });
        itemViewHolerView.llRowDelete.setTag(position);
        itemViewHolerView.llRowDelete.setOnClickListener(new View.OnClickListener() {
          int tag = 0;
          private Intent intent;

          @Override
          public void onClick(View view) {

            tag = (int) view.getTag();
            if (isListCheck) {
              ;
              adapterCallback.onCallAction(2, tag);
            }
          }
        });
      } else if (holder instanceof FooterViewHolder) {

        FooterViewHolder vhItemView = (FooterViewHolder) holder;
        String moreYn = util.null2string(hmItem.get(Constants.HTTP_MORE_YN));
        if (moreYn.equals("Y")) {
          vhItemView.llFooterProgress.setVisibility(View.VISIBLE);
        } else {
          vhItemView.llFooterProgress.setVisibility(View.GONE);
          if (isListCheck) {
            vhItemView.llFooterBody.setVisibility(View.GONE);
          } else {
            if (isFooterVisible) {
              vhItemView.llFooterBody.setVisibility(View.VISIBLE);
            } else {
              vhItemView.llFooterBody.setVisibility(View.GONE);
            }

            vhItemView.llFooterBody.setOnClickListener(new View.OnClickListener() {

              @Override
              public void onClick(View view) {

                adapterCallback.onCallAction(0, 0);
              }
            });
          }
        }
      }
      holder.itemView.setTag(hmItem);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  @Override
  public int getItemViewType(int position) {

    if (getHeaderCheck() && position == 0) {
      return TYPE_HEADER;
    } else if (getFooterCheck() && position == getItemCount() - 1) {
      return TYPE_FOOTER;
    } else {
      return TYPE_ITEM;
    }
  }
}
