package com.xplora.xpsettings.Activity;

import android.content.Intent;
import android.os.Bundle;
//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.Model.BaseModel;
import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Data.DataManager;
import com.xplora.xpsettings.Utils.Constant;
import com.xplora.xpsettings.Utils.ResUtils;


public class CameraActivity extends BaseActionActivity {
    private String[] valueList = null;

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

        String[] array = ResUtils.getStringArray("settings_title_array_", 13);
        setWatchTitle(array[3]);

        initData();
        initView();
    }

    private void initData() {
        String photo_resolution = DataManager.getPhotoResolution();
        String video_resolution = DataManager.getVideoResolution();
        String[] stringList = ResUtils.getStringArray("camera_title_array_", 2);
        valueList = new String[]{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.subColor = R.color.xp_yellow;
            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.INTENT_VIEW_TYPE, position);
                intent.putExtra(Constant.INTENT_VIEW_VALUE, valueList[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.INTENT_RESULT_ACTION)) {
            int viewType = data.getIntExtra(Constant.INTENT_VIEW_TYPE, 0);
            String value = data.getStringExtra(Constant.INTENT_RESULT_VALUE);
            valueList[viewType] = value;

            BaseModel model = mDataList.get(viewType);
            model.subTitle = valueList[viewType];
            mAdapter.setBaseObjects(mDataList);
            mAdapter.notifyDataSetInvalidated();
        }
    }
}