private void initListener(Context context, IShareResult listener) { Util.setListener( result -> { if (result.contains(WEIXIN_RESULT_SUCCESS)) { RemindControl.showSimpleToast(context, "分享成功"); // 分享成功后统计次数 listener.onShareResult(5); } }); }
public void share( Context context, String desc, String title, String imgUrl, String contentUrl, IShareResult listener) { if (!AppContext.isNetworkAvailable()) { RemindControl.showSimpleToast( context, context.getResources().getString(R.string.not_network)); return; } final ShareDialog dialog = ShareDialog.show(context); dialog.setOnClickListener( new ShareDialog.OnClickListener() { @Override public void onShare(final Extra extra) { if (!AppContext.isNetworkAvailable()) { RemindControl.showSimpleToast( context, context.getResources().getString(R.string.not_network)); return; } if (extra == null) { copyUrl(context, contentUrl); RemindControl.showSimpleToast( context, context.getResources().getString(R.string.copySuccess)); return; } RemindControl.showSimpleToast(context, "分享中..."); DataDiskProvider.getInstance() .getImageLoader() .loadImage( imgUrl, new ImageLoader.OnLoadListener() { @Override public void onSuccess(Drawable drawable, boolean immediate) { if (drawable == null) { return; } if (extra.belong() == Platform.WEIXIN) { initListener(context, listener); // 微信回调 } ShareBean shareBean = new ShareBean(); shareBean.setContentUrl(contentUrl); shareBean.setDesc(desc); shareBean.setTitle(title); shareBean.setDrawable(drawable); shareBean.setImgUrl(imgUrl); SocialComponent.create(extra.belong(), ((android.app.Activity) context)) .share( createEntity(extra, shareBean), extra, new ResultListener() { @Override public void onResult(boolean isSuccess, String result) { if (isSuccess) { RemindControl.showSimpleToast(context, "分享成功"); // 分享成功后统计次数 listener.onShareResult(5); } else { if (extra.belong() != Platform.QQ) { RemindControl.showSimpleToast(context, result); } } } }); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(true); dialog.dismiss(); } @Override public void onFail() {} }); } @Override public void onCancel() { dialog.dismiss(); } }); }