package com.xplora.xpsettings.Activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
//import android.os.SystemProperties;
import android.os.SystemProperties;
import android.view.View;
import android.widget.AdapterView;
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.util.ArrayList;
import java.util.List;


public class CameraResolutionActivity extends BaseActivity {
    public int mViewType = 0;

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

        mViewType = getIntent().getIntExtra(Constant.INENT_VIEW_TYPE, 0);
        setWatchTitle(getResources().getStringArray(R.array.camero_titls_array)[mViewType]);
        initData();
        initView();
    }

    private void initData() {
        String photo_resolution = DataManager.getPhotoResolution();
        String video_resolution = DataManager.getVideoResolution();

        int titleId = mViewType == 0 ? R.array.photo_resolution_set_array : R.array.video_resolution_set_array;
        String[] stringList = getResources().getStringArray(titleId);

        for (int i = 0; i < stringList.length; i++) {
            BaseModel model = new BaseModel();
            model.title = stringList[i].trim();
            model.cellType = Constant.CellType.TITLE_CENTER;
            mDataList.add(model);
        }
    }

    private void initView() {
        mAdapter = new BaseListAdapter(this, 0, mDataList);
        ListView listView = findViewById(R.id.activity_listview);
        listView.setAdapter(mAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int titleId = mViewType == 0 ? R.array.photo_resolution_set_array : R.array.video_resolution_set_array;
                String[] stringList = getResources().getStringArray(titleId);
                String value = stringList[position];

                //保存
                if (mViewType == 0) {
                    DataManager.setPhotoResolution(value);
                } else {
                    DataManager.setVideoResolution(value);
                }

                //返回
                Intent intent = new Intent();
                intent.setAction(Constant.INENT_RESULT_ACTION);
                intent.putExtra(Constant.INENT_VIEW_TYPE, mViewType);
                intent.putExtra(Constant.INENT_RESULT_VALUE, value);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}