/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.activity;

import android.os.Bundle;
import android.view.ViewGroup;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.manager.ActionBarManager;
import kr.co.zumo.app.lifeplus.model.PinModel;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.IPinView;
import kr.co.zumo.app.lifeplus.view.custom.pin.CustomPinResetPresenter;
import kr.co.zumo.app.lifeplus.view.custom.pin.CustomPinView;
import kr.co.zumo.app.lifeplus.view.custom.pin.IPinContract;
import kr.co.zumo.app.lifeplus.view.presenter.PinResetPresenter;

/**
 * PinResetActivity
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018-10-04]   [최초 작성]
 * @since 2018-10-04
 */
public class PinResetActivity extends ActivityBase<PinResetPresenter> implements IPinView {
  private CustomPinView customPinView;
  private IPinContract.Presenter pinPresenter;

  @Override
  void onAfterCreate(Bundle savedInstanceState) {

    setContentView(R.layout.view_container);

    /**
     * 핀 확인/등록/초기화(재등록)
     *
     * - 같은 뷰(CustomPinView)를 이용한다.
     * - presenter 를 달리하여 각 단계를 컨트롤한다.
     * - 결과는 IPinContract.Listener 로 전달한다.
     *
     */
    customPinView = new CustomPinView(this);
    pinPresenter = new CustomPinResetPresenter(customPinView, new IPinContract.Listener() {
      @Override
      public void onPinResult(String result) {
        presenter.onEvent(new Event.Builder(Event.SUCCESS).string(result).build());
      }

      @Override
      public void onClickPinReset() {
      }

      @Override
      public void onPinFail() {
        pinPresenter.onPinStart();
      }
    });

    ViewGroup layout = findViewById(R.id.container);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    layout.addView(customPinView, params);
  }

  @Override
  void defineActionBar() {
    ActionBarManager.getInstance().hide();
  }

  @Override
  PinResetPresenter definePresenter() {
    return new PinResetPresenter(getModel(PinModel.class), this);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (null != pinPresenter) {
      pinPresenter.dispose();
      pinPresenter = null;
    }

    if (null != customPinView) {
      customPinView.dispose();
      customPinView = null;
    }
  }
}
