package kr.co.hanwha.hifive.screen.main.setting;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.base.BaseActivity;
import kr.co.hanwha.hifive.enums.BaseAnimationType;
import kr.co.hanwha.hifive.enums.BaseToolbarType;
import kr.co.hanwha.hifive.screen.main.setting.contract.HelpdeskContract;

public class HelpdeskActivity extends BaseActivity implements HelpdeskContract.View {
    private EditText mEditText;

    private HelpdeskContract.Presenter mPresenter;

    @Override
    protected int getContentViewResource() {
        return R.layout.activity_helpdesk;
    }

    @Override
    protected BaseToolbarType isToolbarStyle() {
        return BaseToolbarType.ONLY_BACK;
    }

    @Override
    protected BaseAnimationType isShowActivityAnimation() {
        return BaseAnimationType.RIGHT;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(getString(R.string.main_setting_helpdesk));

        initView();

        initCallback();

        showKeyboard();

        mPresenter = new HelpdeskPresenter(this);
        mPresenter.initData();
    }

    @Override
    public void initView() {
        mEditText = (EditText) findViewById(R.id.editText);
    }

    @Override
    public void initCallback() {
        findViewById(R.id.register_textView).setOnClickListener(onClickListener);
    }

    private void showKeyboard() {
        mEditText.requestFocus();
        mEditText.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                input.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
            }
        }, 100);
    }

    private String getTaskString() {
        return mEditText.getText().toString();
    }

    /**************************************************
     * View.OnClickListener
     **************************************************/
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.register_textView:
                    mPresenter.requestSendTask(getTaskString());
                    break;
            }
        }
    };
}
