package com.wisewoods.eduandroid.app;

import android.content.pm.ActivityInfo;
import android.text.TextUtils;

import androidx.viewbinding.ViewBinding;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.wisewoods.base.base.BaseActivity;
import com.wisewoods.base.utils.GlideEngine;
import com.wisewoods.eduandroid.R;
import com.wisewoods.eduandroid.ui.JzVideoActivity;
import com.wisewoods.eduandroid.ui.adapter.photo.GridImageAdapter;

import java.util.List;

//自定义媒体处理activity
public abstract class BasePhotoActivity<VB extends ViewBinding> extends BaseActivity<VB> {

    protected final GridImageAdapter.MyOnItemClickListener listener = (adapter, v, position) -> {
        List<LocalMedia> selectList = adapter.getData();
        if (selectList.size() > 0) {
            LocalMedia media = selectList.get(position);
            String mimeType = media.getMimeType();
            int mediaType = PictureMimeType.getMimeType(mimeType);
            switch (mediaType) {
                case PictureConfig.TYPE_VIDEO:
                    // 预览视频
//                    PictureSelector.create(activity)
//                            .externalPictureVideo(TextUtils.isEmpty(media.getAndroidQToPath()) ?
//                                    media.getCompressPath() : media.getAndroidQToPath());
                    JzVideoActivity.start(TextUtils.isEmpty(media.getAndroidQToPath()) ?
                            media.getCompressPath() : media.getAndroidQToPath());
                    break;
                default:
                    PictureSelector.create(activity)
                            .themeStyle(R.style.picture_default_style) // xml设置主题
                            .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                            // 设置相册Activity方向，不设置默认使用系统
                            .isNotPreviewDownload(true)// 预览图片长按是否可以下载
                            .imageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                            .openExternalPreview(position, selectList);
                    break;
            }
        }
    };

}
