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

package com.ntels.onecable.view.rules;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.ntels.onecable.R;
import com.ntels.onecable.common.Constants;
import com.ntels.onecable.common.util.Dlog;
import com.ntels.onecable.common.util.Util;
import com.ntels.onecable.common.widget.CustomActivity;

/**
 * <pre>
 * 1. ClassName :   RulesAddSucess
 * 2. FileName  :   RulesAddSucess.java
 * 3. Package   :   com.ntels.onecable.view.rules
 * 4. Date      :   2016-11-28
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class RulesAddSucess extends CustomActivity implements View.OnClickListener {

  /*공통*/
  private Activity act;
  private Util util = new Util();
  private String callType = "";
  private String ruleName = "";

  @Override
  public void onStop() {

    super.onStop();
    Dlog.v("onStop()");
  }

  @Override
  public void onDestroy() {

    super.onDestroy();
    Dlog.v("onDestroy()");
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    act = RulesAddSucess.this;

    View viewToLoad = LayoutInflater.from(act).inflate(R.layout.rules_add_sucess, null);
    this.setContentView(viewToLoad);

    if (null != getIntent()) {
      Intent intent = getIntent();
      callType = intent.getStringExtra(Constants.EXTRA_CALL_TYPE);
      ruleName = intent.getStringExtra(Constants.EXTRA_RULE_NAME);
    }

    setDisp();
  }

  /**
   * UI display.
   */
  private void setDisp() {

    util.getView(act, R.id.llBtn1).setOnClickListener(this);
    util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);

    util.getTextView(act, R.id.tvRulesName).setText(ruleName);
    if (callType.equals("05")) {
      //time
      util.setImage(act, R.drawable.img_rule_item_sub_type_code_05, R.id.ivSucess);
    } else if (callType.equals("32")) {
      //sun
      util.setImage(act, R.drawable.img_rule_item_sub_type_code_32, R.id.ivSucess);
    } else if (callType.equals("31")) {
      //더울 때 /추울때
      util.setImage(act, R.drawable.img_rule_item_sub_type_code_31, R.id.ivSucess);
    } else if (callType.equals("01")) {
      //상태가 변할때
      util.setImage(act, R.drawable.img_rule_trigger_icon_thingschange, R.id.ivSucess);
    }
  }

  @Override
  public void onConfigurationChanged(Configuration newConfig) {

    super.onConfigurationChanged(newConfig);
  }

  @Override
  public void onClick(View view) {

    switch (view.getId()) {
      case R.id.llBtn1:
        onBackPressed();
        break;
      default:
        break;
    }
  }

  @Override
  public void onBackPressed() {

    Intent intent = new Intent();
    intent.putExtra(Constants.EXTRA_RELOAD_FLAG, true);
    act.setResult(RESULT_OK, intent);
    finish();
  }

}

