package com.hoolai.access.demo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Toast;
import com.hoolai.access.open.fastaccess.channel.FastSdk;
import com.hoolai.access.open.fastaccess.channel.request.ShareParams;
import com.hoolai.access.open.fastaccess.channel.request.ShareType;
import com.hoolai.access.open.fastaccess.interf.HLShareListener;
import com.hoolai.access.open.fastaccess.utils.Logger;
import com.hoolai.access.open.fastaccess.utils.ToastUtils;

/**
 * @author gaor
 * @date 2023/12/14 20:22
 * @description 分享
 */
public class ShareActivity extends Activity {

    private static int REQUEST_PHOTO_PICKER_SINGLE_SELECT = 1008611;
    private static int REQUEST_VIDEO_PICKER_SINGLE_SELECT = 1008612;

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

        FastSdk.hlShareListener = new HLShareListener() {

            @Override
            public void onShareSuccess() {
                ToastUtils.showToast("分享成功", Toast.LENGTH_SHORT);
            }

            @Override
            public void onShareFailed(String s) {
                ToastUtils.showToast("分享失败:" + s, Toast.LENGTH_SHORT);
            }
        };
    }

    public void shareText(View view) {
        ShareParams shareParams = new ShareParams();
        shareParams.setTitle("测试链接");
        shareParams.setContent("https://www.baidu.com");
        FastSdk.share(ShareType.SYSTEM, ShareType.ChildType.SYSTEM_TEXT, shareParams);
    }

    public void shareVideo(View view) {
        Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
        startActivityForResult(intent, REQUEST_VIDEO_PICKER_SINGLE_SELECT);
    }

    public void sharePhoto(View view) {
        Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
        startActivityForResult(intent, REQUEST_PHOTO_PICKER_SINGLE_SELECT);
    }

    public void fbShareText(View view) {
        ShareParams shareParams = new ShareParams();
        shareParams.setTitle("测试链接");
        shareParams.setShareUrl("https://www.baidu.com");
        FastSdk.share(ShareType.FACEBOOK, ShareType.ChildType.FACEBOOK_LINK, shareParams);
    }

    public void fbPhotoShare(View view) {
        Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
        startActivityForResult(intent, REQUEST_PHOTO_PICKER_SINGLE_SELECT);
    }

    public void fbShareVideo(View view) {
        Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
        startActivityForResult(intent, REQUEST_VIDEO_PICKER_SINGLE_SELECT);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data==null){
            return;
        }
        Uri data1 = data.getData();
        if (data1==null){
            return;
        }
        Logger.i("shareActivity onActivityResult:" + data1.toString());
        if (requestCode == REQUEST_PHOTO_PICKER_SINGLE_SELECT) {
            /*
            //系统图片分享
            ShareParams shareParams = new ShareParams();
            shareParams.setTitle("系统图片分享");
            shareParams.setPicPath(data1.toString());
            FastSdk.share(ShareType.SYSTEM, ShareType.ChildType.SYSTEM_IMG, shareParams);*/

            //Facebook图片分享
            ShareParams shareParams = new ShareParams();
            shareParams.setTitle("泰裤辣");
            shareParams.setPicPath(data1.toString());
            FastSdk.share(ShareType.FACEBOOK, ShareType.ChildType.FACEBOOK_IMG, shareParams);

        } else if (requestCode == REQUEST_VIDEO_PICKER_SINGLE_SELECT) {
            /*
            //系统视频分享
            ShareParams shareParams = new ShareParams();
            shareParams.setTitle("系统视频分享");
            shareParams.setPicPath(data1.toString());
            FastSdk.share(ShareType.SYSTEM, ShareType.ChildType.SYSTEM_FILE, shareParams);*/

            //Facebook视频分享
            ShareParams shareParams = new ShareParams();
            shareParams.setTitle("泰裤辣");
            shareParams.setPicPath(data1.toString());
            FastSdk.share(ShareType.FACEBOOK, ShareType.ChildType.FACEBOOK_VIDEO, shareParams);
        }
    }
}
