package com.philisense.rdgo.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;

import com.philisense.rdgo.R;
import com.philisense.rdgo.databinding.ActivityAboutBinding;
import com.philisense.rdgo.ui.user.PasswordActivity;

public class AboutActivity extends AppCompatActivity {

    private ActivityAboutBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_about);

        // toolbar
        Toolbar toolbar = mBinding.include.toolbar;
        toolbar.setTitle("关于");
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {finish();}
        });

        mBinding.aboutVersionText.setText(getAppVersionName());

    }

    /**
     * 返回当前程序版本名
     */
    public String getAppVersionName() {
        String versionName = "";
        try {
            PackageManager pm = this.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(this.getPackageName(), 0);
            versionName = pi.versionName;
            versionName = versionName + "（"+ pi.versionCode + "）";
            if (versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        return versionName;
    }

    public static void start(Activity context) {
        Intent intent = new Intent(context, AboutActivity.class);
        ActivityCompat.startActivity(context, intent,null);
    }

}
