package com.kuaiyun.mask_talk.base
|
|
import android.app.Activity
|
import android.content.Intent
|
import com.fuban.driver.base.MyBaseActivity
|
import com.umeng.socialize.*
|
import com.umeng.socialize.bean.SHARE_MEDIA
|
import com.umeng.socialize.media.UMImage
|
import com.umeng.socialize.media.UMWeb
|
import org.jetbrains.anko.toast
|
|
/***
|
* qq weixin 等必须添加onResultActivity 不然没有回调
|
*/
|
abstract class ShareActivity : MyBaseActivity(), UMAuthListener {
|
|
open fun share(
|
context: Activity,
|
platform: SHARE_MEDIA?,
|
content: String?,
|
title: String?,
|
tagUrl: String?,
|
image: UMImage?,
|
listener: UMShareListener?
|
) {
|
var image = image
|
try {
|
val icon = context.resources
|
.getIdentifier("ic_launcher", "mipmap", context.packageName)
|
if (image == null) {
|
image = UMImage(context, icon)
|
}
|
val web = UMWeb(tagUrl, title, content, image)
|
val shareContent = ShareContent()
|
shareContent.mMedia = web
|
ShareAction(context).setPlatform(platform)
|
.setShareContent(shareContent)
|
.setCallback(listener)
|
.share()
|
} catch (e: Exception) {
|
e.printStackTrace()
|
}
|
}
|
|
open fun share(
|
context: Activity,
|
content: String?,
|
title: String?,
|
tagUrl: String?
|
) {
|
val displayList = arrayOf(
|
SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
|
SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE
|
)
|
try {
|
val icon = context.resources
|
.getIdentifier("ic_launcher", "mipmap", context.packageName)
|
val image = UMImage(context, icon)
|
val web = UMWeb(tagUrl, title, content, image)
|
val shareContent = ShareContent()
|
shareContent.mMedia = web
|
ShareAction(context).setDisplayList(*displayList)
|
.setShareContent(shareContent)
|
.open()
|
} catch (e: java.lang.Exception) {
|
e.printStackTrace()
|
}
|
}
|
|
open fun share(
|
context: Activity?,
|
content: String?,
|
title: String?,
|
tagUrl: String?,
|
image: UMImage?,
|
listener: UMShareListener?
|
) {
|
val displayList = arrayOf(
|
SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
|
SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE
|
)
|
val web = UMWeb(tagUrl, title, content, image)
|
val shareContent = ShareContent()
|
shareContent.mMedia = web
|
ShareAction(context).setDisplayList(*displayList)
|
.setShareContent(shareContent)
|
.setCallback(listener)
|
.open()
|
}
|
|
open fun share(
|
context: Activity?,
|
platform: SHARE_MEDIA?,
|
content: String?,
|
title: String?,
|
tagUrl: String?,
|
listener: UMShareListener?
|
) {
|
share(context!!, platform, content, title, tagUrl, null, listener)
|
}
|
|
|
/**
|
* 获取用户信息
|
*
|
* 例子 SHARE_MEDIA。sina
|
* */
|
|
var currentShare: SHARE_MEDIA? = null
|
var num = 0
|
|
fun getInfo(shareMedia: SHARE_MEDIA) {
|
currentShare = shareMedia
|
var mShareAPI: UMShareAPI = UMShareAPI.get(mContext)
|
mShareAPI.getPlatformInfo(ShareActivity@this, shareMedia, this)
|
}
|
|
override fun onComplete(p0: SHARE_MEDIA?, p1: Int, p2: MutableMap<String, String>?) {
|
|
}
|
|
override fun onCancel(p0: SHARE_MEDIA?, p1: Int) {
|
toast("已取消")
|
}
|
|
override fun onError(p0: SHARE_MEDIA?, p1: Int, p2: Throwable?) {
|
if (currentShare != null) {
|
num++
|
if (num <= 3) {
|
getInfo(currentShare!!)
|
}else{
|
num = 0
|
toast("失败,请重试")
|
}
|
}
|
}
|
|
override fun onStart(p0: SHARE_MEDIA?) {
|
}
|
|
override fun onActivityResult(
|
requestCode: Int,
|
resultCode: Int,
|
data: Intent?
|
) {
|
super.onActivityResult(requestCode, resultCode, data)
|
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data)
|
}
|
|
}
|