package com.hainaos.vc.activity.vip;

import android.content.Intent;
import android.view.View;

import androidx.lifecycle.Observer;

import com.hainaos.vc.BuildConfig;
import com.hainaos.vc.R;
import com.hainaos.vc.activity.privacy.PrivacyActivity;
import com.hainaos.vc.base.mvvm.BaseMvvmActivity;
import com.hainaos.vc.bean.SpaceInfo;
import com.hainaos.vc.databinding.ActivityVipBinding;
import com.hainaos.vc.utils.FileUtils;

public class VipActivity extends BaseMvvmActivity<VipViewModel, ActivityVipBinding> {


    /**
     * 设置布局
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_vip;
    }

    /**
     * @return 是否是黑色状态栏
     */
    @Override
    public boolean setNightMode() {
        return false;
    }

    @Override
    protected void initDataBinding() {
        mViewModel.setCtx(this);
        mViewModel.setVDBinding(mViewDataBinding);
        mViewModel.setLifecycle(getLifecycleSubject());
        mViewDataBinding.setClick(new Click());
    }

    /**
     * 初始化视图
     */
    @Override
    protected void initView() {
        mViewDataBinding.tvVersion.setText("版本:V" + BuildConfig.VERSION_NAME);
    }

    /**
     * 初始化数据
     */
    @Override
    protected void initData() {
        mViewModel.mSpaceInfoData.observe(this, new Observer<SpaceInfo>() {
            @Override
            public void onChanged(SpaceInfo spaceInfo) {
                if (spaceInfo == null) {
//                    tv_rank.setText("普通");
                    mViewDataBinding.tvSpaceFree.setText("0GB/0GB");
                    mViewDataBinding.tvSpaceUsed.setText("0%");

                } else {
                    String home_video_grade = spaceInfo.getHome_video_grade();
                    long quota = spaceInfo.getQuota();
                    long use_quota = spaceInfo.getUse_quota();
//                    tv_rank.setText(home_video_grade);
                    mViewDataBinding.tvSpaceFree.setText(String.format(getString(R.string.space_free), FileUtils.formatFileSize(quota)));
                    mViewDataBinding.tvSpaceUsed.setText(String.format(getString(R.string.space_used), FileUtils.formatFileSize(use_quota)));
                }
            }
        });
        mViewModel.getHomeSpaceInfo();

        mViewModel.getActivationInfo();

    }

    public class Click {
        public void exit(View view) {
            finish();
        }

        public void empty(View view) {

        }

        public void openEULA(View view) {
            startActivity(new Intent(VipActivity.this, PrivacyActivity.class));
        }
    }

}
