package com.kfzs.duanduan.utils;

import android.app.Activity;

import com.sheep.jiuyan.samllsheep.utils.G;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

/**
 * Created by Howie on 2017/4/10.
 * 分享工具类
 */

public class ShareUtils {
    public static final String SHARE_START = "创建分享数据中";
    public static final String SHARE_SUCCESS = "分享成功";
    public static final String SHARE_FAILURE = "分享失败";
    public static final String SHARE_CANCEL = "分享取消";


    /**
     * 分享方法
     *
     * @param activity
     * @param link     网页地址
     * @param title
     * @param img
     * @param content
     * @param listener
     */
    public void showShareView(final Activity activity, final String link,
                              final String title, final String img, final String content, final UMShareListener listener) {
        new ShareAction(activity)
                //SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,新浪，QQ
//                .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .setDisplayList(SHARE_MEDIA.SINA)
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                        UMWeb web = new UMWeb(link);
                        web.setTitle(title);
                        web.setDescription(content);
                        web.setThumb(new UMImage(activity, img));
                        new ShareAction(activity).withMedia(web)
                                .setPlatform(share_media)
                                .setCallback(listener)
                                .share();
                    }
                }).open();

    }


    public void showShareView(final Activity activity, final String link,
                              final String title, final String img, final String content) {
        new ShareAction(activity)
                //SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,新浪，QQ
//                .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .setDisplayList(SHARE_MEDIA.SINA)
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                        UMWeb web = new UMWeb(link);
                        web.setTitle(title);
                        web.setDescription(content);
                        web.setThumb(new UMImage(activity, img));
                        new ShareAction(activity).withMedia(web)
                                .setPlatform(share_media)
                                .setCallback(new UMShareListener() {
                                    @Override
                                    public void onStart(SHARE_MEDIA share_media) {
                                        G.showToast(SHARE_START);
                                    }

                                    @Override
                                    public void onResult(SHARE_MEDIA share_media) {
                                        G.showToast(SHARE_SUCCESS);
                                    }

                                    @Override
                                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                        G.showToast(SHARE_FAILURE);
                                    }

                                    @Override
                                    public void onCancel(SHARE_MEDIA share_media) {
                                        G.showToast(SHARE_CANCEL);
                                    }
                                })
                                .share();
                    }
                }).open();

    }
}
