package com.xplora.xpsettings.Activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
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;


public class SettingsActivity extends BaseActionActivity {
    private boolean isLockClick = false; //防止快速多次点击不同item

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_title);
        initData();
        initView();
    }

    private void initData() {
        String[] stringList = ResUtils.getStringArray("sk_settings_title_array_", 8);
        for (int i = 0; i < stringList.length; i++) {
            BaseModel model = new BaseModel();
            //model.backgroundImage = ResUtils.getImageId("settings_bg_", i);
            model.title = stringList[i].trim();
            model.icon = ResUtils.getImageId("settings_icon_", i);
            model.cellType = Constant.CellType.XPSTYLE2;
            model.isShowArrow = false;
            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.setDivider(new ColorDrawable(Color.TRANSPARENT));
        listView.setDividerHeight(0);
        listView.setOnItemClickListener((adapterView, view, i, l) -> {
            if (isLockClick) {
                Log.d(TAG, "initView: listView click lock");
                return;
            }
            isLockClick = true;

            Intent intent;
            switch (i) {
                case 0:
                    intent = new Intent(this, ConnectionsActivity.class);
                    startActivity(intent);
                    break;
                case 1:
                    intent = new Intent(this, TelephoneActivity.class);
                    startActivity(intent);
                    break;
                case 2:
                    intent = new Intent(this, SoundModeActivity.class);
                    startActivity(intent);
                    break;
                case 3:
                    intent = new Intent(this, DisplayActivity.class);
                    startActivity(intent);
                    break;
                case 4:
                    intent = new Intent(this, SystemActivity.class);
                    startActivity(intent);
                    break;
                case 5:
                    intent = new Intent(this, LanguageActivity.class);
                    startActivity(intent);
                    break;
                case 6:
                    gotoQRcode();
                    break;
                case 7:
                    gotoPws();
                    break;

                case 100:
                    intent = new Intent(this, OpenCloseActivity.class);
                    intent.putExtra(Constant.INTENT_ACTION_TYPE, ACTION_TYPE.AIRPLANE_MODE.ordinal());
                    startActivity(intent);
                    break;

                default:
                    break;
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        isLockClick = false;
    }
}
