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

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.MainOKRListAdapter;
import kr.co.hanwha.hifive.base.BaseActivity;
import kr.co.hanwha.hifive.base.FirebaseAnalyticsInterface;
import kr.co.hanwha.hifive.enums.BaseAnimationType;
import kr.co.hanwha.hifive.enums.BaseToolbarType;
import kr.co.hanwha.hifive.screen.main.home.contract.MainOKRContract;
import kr.co.hanwha.hifive.util.HFAnalyticsUtil;

/**
 * 개인 OKR 목록 조회 View
 *
 * @see MainOKRPresenter
 */
public class MainOKRActivity extends BaseActivity implements MainOKRContract.View, FirebaseAnalyticsInterface {
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private RecyclerView mRecyclerView;

    private MainOKRListAdapter mAdapter;
    private MainOKRPresenter mPresenter;

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

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

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

    @Override
    public String getClassUri() {
        return HFAnalyticsUtil.HF_MY_OKRS;
    }

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

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

        mAdapter = new MainOKRListAdapter();
        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
        mSwipeRefreshLayout.setOnRefreshListener(onRefreshListener);

        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        mPresenter = new MainOKRPresenter(this, mAdapter, mAdapter);
        mPresenter.initData(true);

    }

    @Override
    public void setRefreshing(boolean refreshing) {
        mSwipeRefreshLayout.setRefreshing(refreshing);
    }

    @Override
    public void setEmptyView(boolean isEmpty) {
        if (isEmpty) {
            findViewById(R.id.empty_textView).setVisibility(View.VISIBLE);
            findViewById(R.id.swipeRefreshLayout).setVisibility(View.GONE);
        } else {
            findViewById(R.id.empty_textView).setVisibility(View.GONE);
            findViewById(R.id.swipeRefreshLayout).setVisibility(View.VISIBLE);
        }
    }

    /**************************************************
     * SwipeRefreshLayout.OnRefreshListener
     **************************************************/
    SwipeRefreshLayout.OnRefreshListener onRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mPresenter.initData(false);
        }
    };
}
