package com.taikor.investment.modules.user;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.taikor.investment.R;
import com.taikor.investment.base.BaseActivity;
import com.taikor.investment.event.BooleanEvent;
import com.taikor.investment.utils.CacheUtils;
import com.taikor.investment.utils.SharedPreferenceUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 设置
 * Created by Any on 2017/5/3.
 */
public class SettingActivity extends BaseActivity {

    @BindView(R.id.tv_bar_title)
    TextView tvBarTitle;//标题
    @BindView(R.id.iv_switch_button)
    ImageView ivSwitchButton;//开关
    @BindView(R.id.tv_version)
    TextView tvVersion;//版本
    @BindView(R.id.tv_cache)
    TextView tvCache;//缓存

    private boolean flag = true;

    @Override
    public int getContentViewId() {
        return R.layout.activity_user_setting;
    }

    @Override
    public void initView() {
        tvBarTitle.setText(getString(R.string.set));
        try {
            String totalCacheSize = CacheUtils.getTotalCacheSize(this);
            tvCache.setText(totalCacheSize);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @OnClick({R.id.tv_bar_back, R.id.iv_switch_button, R.id.bt_quit, R.id.rl_update_version, R.id.rl_clear_cache})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_bar_back:
                finish();
                break;
            case R.id.iv_switch_button://推送开关
                if (flag) {
                    ivSwitchButton.setImageResource(R.drawable.switch_off);
                    flag = false;
                } else {
                    ivSwitchButton.setImageResource(R.drawable.switch_on);
                    flag = true;
                }
                break;
            case R.id.bt_quit:
                //再次打开app时显示的登录页面
                SharedPreferenceUtils.saveBoolean(SettingActivity.this, "login", false);
                //发送标记，使显示登录页面
                EventBus.getDefault().post(new BooleanEvent(true,"user"));
                finish();
                break;
            case R.id.rl_update_version://更新版本
                break;
            case R.id.rl_clear_cache://清除缓存
                CacheUtils.clearAllCache(SettingActivity.this);
                tvCache.setText("0");
                break;
        }
    }
}
