package com.android.chmo.ui.activity;

import android.widget.ImageView;

import com.android.chmo.R;
import com.android.chmo.app.ChmoApplication;
import com.android.chmo.app.SpManager;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.im.IMManager;
import com.android.chmo.model.LoginUser;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/31.
 */

public class WelcomeActivity extends BaseActivity {
    @BindView(R.id.image)
    ImageView imageView;
    private Runnable runnable;

    @Override
    protected int getContentResId() {
        return R.layout.activity_welcome;
    }

    @Override
    public void initView() {
        runnable = () -> {
            ChmoApplication.isInit = true;
            if (SpManager.getInstance().getBoolean("appStarted")) {
                LoginUser user = ChmoApplication.getApp().getLoginUser();
                if (null != user) {
                    IMManager.login();
                    openPage(MainActivity.class);
                } else {
                    openPage(LoginActivity.class);
                }
            } else {
                openPage(GuideActivity.class);
            }

            finish();
        };
        imageView.postDelayed(runnable, ChmoApplication.isInit ? 100 : 1000);
    }

    @OnClick(R.id.btn_skip)
    void onClick() {
        imageView.removeCallbacks(runnable);
        ChmoApplication.isInit = true;
        if (SpManager.getInstance().getBoolean("appStarted")) {
            LoginUser user = ChmoApplication.getApp().getLoginUser();
            if (null != user) {
                IMManager.login();
                openPage(MainActivity.class);
            } else {
                openPage(LoginActivity.class);
            }
        } else {
            openPage(GuideActivity.class);
        }
        finish();
    }

    @Override
    protected boolean hideNavigationBar() {
        return true;
    }
}
