package com.xplora.xpsettings.Activity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ListView;

import androidx.annotation.NonNull;

import com.xplora.xpsettings.Adapter.BaseListAdapter;
import com.xplora.xpsettings.Data.DataManager;
import com.xplora.xpsettings.Fragment.SelectFragment;
import com.xplora.xpsettings.Fragment.ShutdownningFragment;
import com.xplora.xpsettings.Model.IconProgressModel;
import com.xplora.xpsettings.Observer.Listener;
import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Utils.Constant;
import com.xplora.xpsettings.Utils.Macros;
import com.xplora.xpsettings.Utils.ResUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;


public class SystemActivity extends BaseActionActivity {
    private final List<IconProgressModel> mDataList = new ArrayList<>();

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

    @Override
    protected void onResume() {
        super.onResume();
        mDataList.clear();
        initData();
        mAdapter.setBaseObjects(mDataList);
        mAdapter.notifyDataSetInvalidated();
    }

    private void initData() {
        String[] stringList = ResUtils.getStringArray("system_title_array_", 5);
        for (int i = 0; i < stringList.length; i++) {
            IconProgressModel model = new IconProgressModel();
            model.title = stringList[i].trim();
            model.isShowArrow = false;
            model.cellType = Constant.CellType.TITLE;
            mDataList.add(model);
        }
    }

    private void initView() {
        ListView listView = findViewById(R.id.activity_listview);
        mAdapter = new BaseListAdapter(this, R.layout.item_xpstyle, mDataList);
        listView.setAdapter(mAdapter);
        listView.setDivider(new ColorDrawable(Color.TRANSPARENT));
        listView.setDividerHeight(0);
        listView.setOnItemClickListener((adapterView, view, i, l) -> {
            Intent intent;
            switch (i) {
                case 0:
                    gotoUpdate();
                    break;
                case 1:
                    intent = new Intent(this, AboutActivity.class);
                    startActivity(intent);
                    break;
                case 2:
                    //Monkey测试时，屏蔽关机
                    if (DataManager.getLockShutDown() == 1)
                        break;
                    SelectFragment fragment2 = SelectFragment.newInstance(this);
                    fragment2.setItemInfo(102, getString(R.string.restore_factory_settings), getString(R.string.confirm_to_restore_factory));
                    fragment2.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
                    break;
                case 3:
                    //Monkey测试时，屏蔽关机
                    if (DataManager.getLockShutDown() == 1)
                        break;
                    SelectFragment fragment3 = SelectFragment.newInstance(this);
                    fragment3.setItemInfo(101, getString(R.string.shut_down), getString(R.string.confirm_to_shut_down));
                    fragment3.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
                    break;
                case 4:
                    //Monkey测试时，屏蔽关机
                    if (DataManager.getLockShutDown() == 1)
                        break;
                    SelectFragment fragment4 = SelectFragment.newInstance(this);
                    fragment4.setItemInfo(100, getString(R.string.restart), getString(R.string.confirm_to_restart));
                    fragment4.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
                    break;
                case 5:
                    intent = new Intent(this, AlertActivity.class);
                    startActivity(intent);
                    break;
                default:
                    break;
            }
        });
    }
}