package com.xplora.xpsettings.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.xplora.xpsettings.Adapter.BaseListAdapter;
import com.xplora.xpsettings.Model.BaseModel;
import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Utils.Constant;
import com.xplora.xpsettings.Utils.ResUtils;

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


public class SettingsActivity 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.settings_title_array);
        for (int i = 0; i < stringList.length; i++) {
            BaseModel model = new BaseModel();
            model.background = ResUtils.getImageId("settings_bg_", i);
            model.title = stringList[i].trim();
            model.icon = ResUtils.getImageId("settings_icon_", i);
            model.cellType = Constant.CellType.XPSTYLE;
            mDataList.add(model);
        }
    }

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

        listView.setOnItemClickListener((adapterView, view, i, l) -> {
            Intent intent;
            switch (i) {
                case 0:
                    intent = new Intent(this, ConnectionsActivity.class);
                    startActivity(intent);
                    break;
                case 1:
                    intent = new Intent(this, SoundModeActivity.class);
                    startActivity(intent);
                    break;
                case 2:
                    intent = new Intent(this, DisplayActivity.class);
                    startActivity(intent);
                    break;
                case 3:
                    intent = new Intent(this, LanguageActivity.class);
                    startActivity(intent);
                    break;
                case 4:
                    intent = new Intent(this, QRActivity.class);
                    startActivity(intent);
                    break;
                case 5:
                    break;
                case 6:
                    restart();
                    break;
                case 7:
                    shutdown();
                    break;
                case 8:
                    intent = new Intent(this, AboutActivity.class);
                    startActivity(intent);
                    break;
                case 9:
                    intent = new Intent(this, ApnListActivity.class);
                    startActivity(intent);
                    break;
                case 10:
                    intent = new Intent(this, ScreenTimeActivity.class);
                    startActivity(intent);
                    break;
                case 11:
                    intent = new Intent(this, CameraActivity.class);
                    startActivity(intent);
                    break;
                default:
                    break;
            }
        });
    }

    public void restart() {
        if (Constant.DEBUG) {
            return;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                Intent intent2 = new Intent(Intent.ACTION_REBOOT);
                intent2.putExtra("nowait ", 1);
                intent2.putExtra("interval ", 1);
                intent2.putExtra("window ", 0);
                sendBroadcast(intent2);
            }
        }).start();
    }

    public void shutdown() {
        if (Constant.DEBUG) {
            return;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                Intent intent2 = new Intent(Intent.ACTION_SHUTDOWN);
                intent2.putExtra("nowait ", 1);
                intent2.putExtra("interval ", 1);
                intent2.putExtra("window ", 0);
                sendBroadcast(intent2);
            }
        }).start();
    }
}