package com.yutou.jianr_mg.views;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.yutou.jianr_mg.Application;
import com.yutou.jianr_mg.Network.HttpApi;
import com.yutou.jianr_mg.R;
import com.yutou.jianr_mg.Tools.JianRUtils;
import com.yutou.jianr_mg.Tools.RootUtils;
import com.yutou.jianr_mg.Tools.Utils;

import java.util.ArrayList;
import java.util.List;

public class ConfigActivity extends AppCompatActivity {
    private ListView listView;
    private List<String> config;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        initCofig();
        initView();
    }

    private void initView() {
        listView = findViewById(R.id.listView);
        listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, config));
        listView.setOnItemClickListener((parent, view, position, id) -> {
            Intent intent = null;
            switch (position) {
                case 0:
                    RootUtils.setRootInstallModel(ConfigActivity.this);
                    break;
                case 1:
                    Utils.initImageLoader(ConfigActivity.this).clearDiskCache();
                    Toast.makeText(ConfigActivity.this, "咕", Toast.LENGTH_LONG).show();
                    break;
                case 2:
                    intent = new Intent(this, WebActivity.class);
                    intent.putExtra("url", HttpApi.HOME_URL + "../html/join.jsp");
                    break;
                case 3:
                    intent = new Intent(this, WebActivity.class);
                    intent.putExtra("url", HttpApi.HOME_URL + "../html/about.jsp");
                    break;
                case 4:
                    intent = new Intent(this, LicenseActivity.class);
                    break;
                case 5:
                    if (JianRUtils.readClientVersion(Application.application)) {
                        JianRUtils.changeClientVersion(true,Application.application);
                        Utils.toast(Application.application,"已切换至覆盖版兼容模式");
                    }else {
                        JianRUtils.changeClientVersion(false,Application.application);
                        Utils.toast(Application.application,"已切换至共存版兼容模式");
                    }
                    break;
                case 6:
                    intent=new Intent(this,WebActivity.class);
                    intent.putExtra("url","http://debugtbs.qq.com");
                    break;
            }
            if (intent != null) {
                startActivity(intent);
            }
        });
    }

    private void initCofig() {
        config = new ArrayList<>();
        config.add("设置ROOT安装模式");
        config.add("清空图片缓存");
        config.add("加群");
        config.add("关于我们");
        config.add("开源项目协议");
        config.add("切换专用客户端版本");
        config.add("设置TBS内核");
    }
}
