package com.fxy.mine;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.fxy.common.VersionUpgrades;
import com.fxy.baselibrary.base.BaseActivity;
import com.fxy.baselibrary.views.MarqueeTextView;
import com.fxy.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 版本内容以及更新
 *
 * @author James.Jiang
 * @date 2020-03-10
 */
public class VersionContentActivity extends BaseActivity {
    private Context mContext = this;
    @BindView(R.id.mt_version_name)
    MarqueeTextView mtVersionName;

    @BindView(R.id.mt_version_updatetime)
    MarqueeTextView mtVersionUpdatetime;

    @BindView(R.id.tv_update_content)
    TextView tvUpdateContent;

    private VersionUpgrades versionUpgrades;

    private Unbinder unbinder;

    @Override
    public int getContentViewResId() {
        return R.layout.activity_version_content;
    }

    @Override
    public boolean showToolBar() {
        return true;
    }

    @Override
    public boolean openEventBus() {
        return false;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    public boolean isPlayMusic() {
        return true;
    }

    @Override
    protected void initView() {
        unbinder = ButterKnife.bind(this);
        setTitleName(getString(R.string.str_about_version));
        //CheckUpgrades();
        versionUpgrades = new VersionUpgrades(mContext);
        versionUpgrades.checkUpgrades(mtVersionName,tvUpdateContent);
        iniData();

    }

    public void iniData(){
        mtVersionUpdatetime.setText(versionUpgrades.getLastUpdateTime());
        tvUpdateContent.setText(versionUpgrades.getCurrentVersionContent());
        mtVersionName.setText(versionUpgrades.getCurrentVersionName());

    }


    @Override
    protected void onDestroy() {
        unbinder.unbind();
        super.onDestroy();
    }


    // 信息处理
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            Bundle data = msg.getData();
            if (msg.what == 2) {
                mtVersionName.setText(data.getString("versionName"));
                mtVersionUpdatetime.setText(data.getString("updateTime"));
                tvUpdateContent.setText(data.getString("updateContent"));
            }
        }
    };
}
