package com.xplora.xpsettings.Activity;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
//import android.os.SystemProperties;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemProperties;
import android.widget.ListView;

import com.xplora.xpsettings.Adapter.BaseListAdapter;
import com.xplora.xpsettings.Adapter.ListAdapter;
import com.xplora.xpsettings.Model.BaseModel;
import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Data.DataManager;
import com.xplora.xpsettings.Utils.Constant;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


public class AboutActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        initData();
        initView();
    }

    private void initData() {
        String[] stringList = getResources().getStringArray(R.array.about_titls_array);
//        String selfName = SystemProperties.get("persist.zs.model");
//        String btName = SystemProperties.get("persist.zs.bt.name");
//        String name = selfName.trim().isEmpty() ? btName : selfName;
//        String sn = SystemProperties.get("persist.zs.sn.number");
//        String bt = SystemProperties.get("persist.zs.bt.address");
//        String version = SystemProperties.get("ro.product.version.release");
        String modelName = Build.MODEL;
        String cpu = Build.SUPPORTED_ABIS[0];
        String ram = "512M";
        String storage = "aaaaa";
        String firmware_version = SystemProperties.get("ro.product.version.release");
        String imei = Build.HARDWARE;
        String wifi = SystemProperties.get("persist.zs.wifi.address");

        String[] valueList = {modelName, cpu, ram, storage, firmware_version, imei, wifi};
        for (int i = 0; i < stringList.length; i++) {
            BaseModel model = new BaseModel();
            model.title = stringList[i].trim();
            model.subTitle = valueList[i];
            model.isShowArrow = false;
            model.cellType = Constant.CellType.TITLE_SUBTITLE;
            mDataList.add(model);
        }
    }

    private void initView() {
        mAdapter = new BaseListAdapter(AboutActivity.this, 0, mDataList);
        ListView listView = findViewById(R.id.activity_listview);
        listView.setAdapter(mAdapter);
    }

    public long getTotalInternalMemorySize() {
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long totalBlocks = stat.getBlockCountLong();
        return totalBlocks * blockSize;
    }

    public long[] getRomMemroy() {
        long[] romInfo = new long[2];
        //Total rom memory
        romInfo[0] = getTotalInternalMemorySize();
        //Available rom memory
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        romInfo[1] = blockSize * availableBlocks;
        return romInfo;
    }

    public String getWifiMac() {
        WifiManager wifiManager = (WifiManager) getApplicationContext()
                .getSystemService(WIFI_SERVICE);
        String bssid = wifiManager.getConnectionInfo().getBSSID();
        return "02:00:00:00:00:00".equals(bssid) ? null : bssid;
    }
}