package com.android.chmo.ui.activity;

import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
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;
import butterknife.OnTouch;

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

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

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

    @Override
    public void initView() {
        handler = new Handler();
        runnable = this::start;
        handler.postDelayed(runnable, 4000);
    }

    @OnClick(R.id.fl_skip)
    void OnClick() {
        if (!start) {
            handler.removeCallbacks(runnable);
            start();
            start = true;
        }
    }

    private void start() {
        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);
            // }
            IMManager.login();
            openPage(MainActivity.class);
        } else {
            openPage(MainActivity.class);
        }
        finish();
        overridePendingTransition(R.anim.push_right_in, R.anim.push_left_out);
    }

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