package com.kfzs.cfyl.media.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.kfzs.cfyl.media.BaseActivity;
import com.kfzs.cfyl.media.R;
import com.kfzs.cfyl.media.util.ListUtil;
import com.kfzs.cfyl.share_library.util.CallBackAPI;
import com.sheep.gamegroup.model.entity.Video;

import java.util.ArrayList;
import java.util.List;

import cn.finalteam.rxgalleryfinal.bean.MediaBean;
import cn.finalteam.rxgalleryfinal.utils.MediaUtils;

/**
 * Created by realicing on 2018/12/6.
 * realicing@sina.com
 */
public class MainActivity extends BaseActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.main_activity;
    }

    @Override
    public void initView() {
        onClickHelloWorld(null);
    }

    private void goCut() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<MediaBean> mediaBeanList = MediaUtils.getMediaWithVideoList(getApplicationContext(), page++, 1);
                MediaBean mediaBean = ListUtil.getItem(mediaBeanList, 0);
                if(mediaBean != null) {
                    final Video video = Video.from(mediaBean);
                    final ArrayList<String> list = new ArrayList<>();
                    list.add("1asdfaqewfawe");
                    list.add("2asdfaqewfawe");
                    list.add("3asdfaqewfawe");
                    list.add("4asdfaqewfawe");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CallBackAPI.get().goCutVideo(MainActivity.this, video, list);
                        }
                    });
                }
            }
        }).start();
    }
    private int page = 1;
    private void goEdit() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<MediaBean> mediaBeanList = MediaUtils.getMediaWithVideoList(getApplicationContext(), page++, 1);
                MediaBean mediaBean = ListUtil.getItem(mediaBeanList, 0);
                if(mediaBean != null) {
                    final Video video = Video.from(mediaBean);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CallBackAPI.get().goEditVideo(MainActivity.this, video);
                        }
                    });
                }
            }
        }).start();
    }

    public void onClickHelloWorld(View view) {
        Activity activity = this;
        final String[] items = {"剪切视频", "编辑视频"};
        AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("请选择测试项目")
                .setItems(items, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (items[which]) {
                            case "剪切视频":
                                goCut();
                                break;
                            case "编辑视频":
                                goEdit();
                                break;
                        }
                    }
                }).create();
        dialog.show();
    }
}
