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 CameraActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_title);
        setWatchTitle(getResources().getStringArray(R.array.settings_title_array)[11]);
        initData();
        initView();
    }

    private void initData() {
        String photo_resolution = DataManager.getPhotoResolution();
        String video_resolution = DataManager.getVideoResolution();
        String[] stringList = getResources().getStringArray(R.array.camero_titls_array);
        String[] valueList = {photo_resolution, video_resolution};

        for (int i = 0; i < stringList.length; i++) {
            BaseModel model = new BaseModel();
            model.title = stringList[i].trim();
            model.subTitle = valueList[i];
            model.isShowArrow = true;
            model.cellType = Constant.CellType.TITLE_SUBTITLE;
            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) {
                Intent intent = new Intent(CameraActivity.this, CameraResolutionActivity.class);
                intent.putExtra(Constant.INENT_VIEW_TYPE, position);
                startActivityForResult(intent, 0);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null)
            return;
        if (data.getAction().equals(Constant.INENT_RESULT_ACTION)) {
            int viewType = data.getIntExtra(Constant.INENT_VIEW_TYPE, 0);
            String value = data.getStringExtra(Constant.INENT_RESULT_VALUE);
            BaseModel model = mDataList.get(viewType);
            model.subTitle = value;
            mAdapter.setBaseObjects(mDataList);
            mAdapter.notifyDataSetInvalidated();
        }
    }
}