package com.gensee.playerdemo;

import android.Manifest;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;

import com.gensee.fragement.InitParamFragment;
import com.gensee.utils.FileUtil;
import com.gensee.utils.GenseeLog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
	private static final int PERMISSION_RESULT_CODE= 10000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
//		CrashReport.initCrashReport(this,"3c3de5bba8",true);
		InitParamFragment fragment =  new InitParamFragment();
		FragmentManager fragmentManager = getFragmentManager();
	    FragmentTransaction ft = fragmentManager.beginTransaction();
	    ft.add(R.id.frameLayout,fragment);
	    ft.commit();

//		GenseeConfig.isTargetVerLessQ = true;
		String dir = FileUtil.getFileDir(this,"test");
		boolean ok = new File(dir).mkdirs();
		GenseeLog.d("MainActivity","Build.VERSION.SDK_INT = " + Build.VERSION.SDK_INT + " dircreate = " + ok);

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
			List<String> permissions = new ArrayList<>();
			if (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
				permissions.add(Manifest.permission.RECORD_AUDIO);
			}
			if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
				permissions.add(Manifest.permission.CAMERA);
			}
			if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
				permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
			}
			int size = permissions.size();
			if (size > 0) {
				String[] ps = new String[size];
				permissions.toArray(ps);
				requestPermissions(ps, PERMISSION_RESULT_CODE);
			}
		}
//		findViewById(R.id.live_btn).setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				startActivity(new Intent(MainActivity.this, PlayerDemoActivity.class));
//			}
//		});
//		
//		findViewById(R.id.vod_btn).setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				startActivity(new Intent(MainActivity.this, VodActivity.class));
//			}
//		});

	}
}
