Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
9e69e5db
Commit
9e69e5db
authored
Aug 25, 2022
by
霍志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:分享添加
parent
0af98d7e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1028 additions
and
852 deletions
+1028
-852
config.gradle
config.gradle
+5
-5
build.gradle
ydl-platform/build.gradle
+4
-4
ShareUtils.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/actions/share/ShareUtils.kt
+325
-284
CustomShareDialog.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/view/dialog/CustomShareDialog.kt
+179
-144
YDLShareDialog.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/view/dialog/YDLShareDialog.kt
+515
-415
No files found.
config.gradle
View file @
9e69e5db
ext
{
kotlin_version
=
"1.3.21"
dev_mode
=
fals
e
dev_mode
=
tru
e
ydlPublishVersion
=
[
// -------------- 业务模块 --------------
...
...
@@ -234,13 +234,13 @@ ext {
"umeng-common"
:
"com.umeng.umsdk:common:9.5.1"
,
"umeng-asms"
:
"com.umeng.umsdk:asms:1.4.1"
,
// //友盟社会化分享
//
"umeng-share-core" : "com.umeng.umsdk:share-core:7.1.4",
//
"umeng-share-qq" : "com.umeng.umsdk:share-qq:7.1.4",
"umeng-share-core"
:
"com.umeng.umsdk:share-core:7.1.4"
,
"umeng-share-qq"
:
"com.umeng.umsdk:share-qq:7.1.4"
,
"umeng-share-wechat"
:
"com.umeng.umsdk:share-wx:7.1.4"
,
// //分享面板
//
"umeng-shareboard" : "com.umeng.umsdk:share-board:7.1.4",
"umeng-shareboard"
:
"com.umeng.umsdk:share-board:7.1.4"
,
"umeng-wx-guanfang"
:
"com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.6.5"
,
//
"umeng-qq-guanfang" : "com.tencent.tauth:qqopensdk:3.51.2",
"umeng-qq-guanfang"
:
"com.tencent.tauth:qqopensdk:3.51.2"
,
"tablayout"
:
"com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar"
,
"stetho"
:
"com.facebook.stetho:stetho:1.5.0"
,
"stetho-okhttp3"
:
"com.facebook.stetho:stetho-okhttp3:1.4.1"
,
...
...
ydl-platform/build.gradle
View file @
9e69e5db
...
...
@@ -143,12 +143,12 @@ dependencies {
api
rootProject
.
ext
.
dependencies
[
"eventbus"
]
api
rootProject
.
ext
.
dependencies
[
"umeng-common"
]
api
rootProject
.
ext
.
dependencies
[
"umeng-asms"
]
//
api rootProject.ext.dependencies["umeng-share-core"]
//
api rootProject.ext.dependencies["umeng-share-qq"]
api
rootProject
.
ext
.
dependencies
[
"umeng-share-core"
]
api
rootProject
.
ext
.
dependencies
[
"umeng-share-qq"
]
api
rootProject
.
ext
.
dependencies
[
"umeng-share-wechat"
]
//
api rootProject.ext.dependencies["umeng-shareboard"]
api
rootProject
.
ext
.
dependencies
[
"umeng-shareboard"
]
api
rootProject
.
ext
.
dependencies
[
"umeng-wx-guanfang"
]
//
api rootProject.ext.dependencies["umeng-qq-guanfang"]
api
rootProject
.
ext
.
dependencies
[
"umeng-qq-guanfang"
]
api
rootProject
.
ext
.
dependencies
[
"stetho"
]
api
rootProject
.
ext
.
dependencies
[
"stetho-okhttp3"
]
api
rootProject
.
ext
.
dependencies
[
"bugly-crashreport"
]
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/actions/share/ShareUtils.kt
View file @
9e69e5db
//package com.ydl.ydlcommon.actions.share
package
com.ydl.ydlcommon.actions.share
import
android.app.Activity
import
android.graphics.Bitmap
import
android.text.TextUtils
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.UMMin
import
com.umeng.socialize.media.UMWeb
import
com.umeng.socialize.shareboard.ShareBoardConfig
import
com.ydl.ydlcommon.utils.remind.ToastHelper
import
com.ydl.ydlcommon.view.dialog.CustomShareDialog
import
com.yidianling.common.tools.LogUtil
import
com.yidianling.common.tools.ToastUtil
/**
* 分享工具类
*/
object
ShareUtils
{
var
platform
:
SHARE_MEDIA
?
=
null
var
callBack
:
ShareActionCallBack
?
=
null
/**
* 直接分享到指定平台
* @param platform
*/
fun
shareTo
(
platform
:
SHARE_MEDIA
?,
context
:
Activity
,
share_title
:
String
,
share_url
:
String
,
share_context
:
String
?,
share_head
:
String
?
)
{
LogUtil
.
d
(
"shareTo"
)
val
web
=
UMWeb
(
share_url
)
web
.
title
=
share_title
//标题
if
(
platform
==
SHARE_MEDIA
.
WEIXIN_CIRCLE
)
{
web
.
title
=
"$share_title\n$share_context"
}
web
.
setThumb
(
UMImage
(
context
,
share_head
?:
"http://static.ydlcdn.com/v1/images/logo320.png"
)
)
//缩略图
web
.
description
=
share_context
//描述
ShareAction
(
context
)
.
setPlatform
(
platform
)
.
setCallback
(
object
:
UMShareListener
{
override
fun
onStart
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"开始分享------"
)
}
override
fun
onResult
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享结束------"
)
callBack
?.
onShareSuccessed
(
share_media
)
callBack
=
null
}
override
fun
onError
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
{
LogUtil
.
e
(
"ydl"
,
"分享出错------"
+
throwable
.
message
)
try
{
var
message
=
handleMessage
(
throwable
.
message
!!
)
ToastUtil
.
toastShort
(
"分享失败,"
+
message
)
}
catch
(
e
:
Exception
)
{
ToastUtil
.
toastShort
(
"分享错误"
)
}
callBack
?.
onShareFailed
(
share_media
,
throwable
)
callBack
=
null
}
override
fun
onCancel
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享取消------"
)
}
})
.
withMedia
(
web
)
.
share
()
}
/**
* 分享纯图片到微信
*/
fun
sharePicToWeiXin
(
context
:
Activity
,
bitmap
:
Bitmap
?)
{
if
(
bitmap
==
null
)
{
ToastUtil
.
toastShort
(
"数据异常,请重试"
)
return
}
if
(
platform
==
null
)
{
ToastUtil
.
toastShort
(
"分享异常,请重试"
)
return
}
val
image
=
UMImage
(
context
,
bitmap
)
//bitmap文件
val
thumb
=
UMImage
(
context
,
bitmap
)
image
.
setThumb
(
thumb
)
image
.
compressStyle
=
UMImage
.
CompressStyle
.
SCALE
//大小压缩,默认为大小压缩,适合普通很大的图
image
.
compressStyle
=
UMImage
.
CompressStyle
.
QUALITY
//质量压缩,适合长图的分享
ShareAction
(
context
)
.
setPlatform
(
platform
)
.
setCallback
(
object
:
UMShareListener
{
override
fun
onStart
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"开始分享------"
)
}
override
fun
onResult
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享结束------"
)
callBack
?.
onShareSuccessed
(
share_media
)
callBack
=
null
}
override
fun
onError
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
{
LogUtil
.
e
(
"ydl"
,
"分享出错------"
+
throwable
.
message
)
try
{
var
message
=
handleMessage
(
throwable
.
message
!!
)
ToastUtil
.
toastShort
(
"分享失败,"
+
message
)
}
catch
(
e
:
Exception
)
{
ToastUtil
.
toastShort
(
"分享错误"
)
}
callBack
?.
onShareFailed
(
share_media
,
throwable
)
callBack
=
null
}
override
fun
onCancel
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享取消------"
)
}
})
.
withMedia
(
image
)
.
share
()
}
/**
* 分享小程序类型
*/
fun
shareSmailWeixin
(
context
:
Activity
,
share_title
:
String
,
share_url
:
String
,
share_context
:
String
?,
image
:
String
?,
path
:
String
?,
id
:
String
?,
shareListener
:
UMShareListener
?
)
{
val
umMin
=
UMMin
(
share_url
)
//兼容低版本的网页链接
val
img
=
UMImage
(
context
,
image
)
img
.
compressStyle
=
UMImage
.
CompressStyle
.
SCALE
umMin
.
setThumb
(
img
)
// 小程序消息封面图片
umMin
.
title
=
share_title
// 小程序消息title
umMin
.
description
=
share_context
// 小程序消息描述
umMin
.
path
=
path
//小程序页面路径
umMin
.
userName
=
id
// 小程序原始id,在微信平台查询
ShareAction
(
context
)
.
withMedia
(
umMin
)
.
setPlatform
(
SHARE_MEDIA
.
WEIXIN
)
.
setCallback
(
shareListener
)
.
share
()
}
/**
* 自定义分享弹出框
* author harvie
* @param activity
* @param actions 扩展按钮
* @param share_title
* @param share_url
* @param share_context
* @param share_head
*/
fun
share
(
activity
:
Activity
,
share_title
:
String
?,
share_url
:
String
?,
share_context
:
String
?,
share_head
:
String
?,
actions
:
List
<
ShareMoreBean
>
)
{
var
content
=
share_context
var
image
=
share_head
if
(
share_title
==
null
||
share_url
==
null
)
{
ToastHelper
.
show
(
"缺少分享参数"
)
return
}
if
(
TextUtils
.
isEmpty
(
share_head
))
{
image
=
"http://static.ydlcdn.com/v1/images/logo320.png"
}
if
(
TextUtils
.
isEmpty
(
content
))
content
=
share_title
val
dialog
=
CustomShareDialog
(
activity
)
dialog
.
setShareBody
(
share_title
,
share_url
,
content
?:
""
,
image
!!
)
dialog
.
addActions
(
actions
)
dialog
.
show
()
}
/**
* 友盟自带分享弹框
*/
fun
share
(
activity
:
Activity
,
share_title
:
String
?,
share_url
:
String
?,
share_context
:
String
?,
share_head
:
String
?
)
{
LogUtil
.
d
(
"share"
)
var
content
=
share_context
var
image
=
share_head
if
(
share_title
==
null
||
share_url
==
null
)
{
ToastHelper
.
show
(
"缺少分享参数"
)
return
}
if
(
share_head
==
null
||
share_head
==
""
)
{
image
=
"http://static.ydlcdn.com/v1/images/logo320.png"
}
if
(
TextUtils
.
isEmpty
(
content
))
content
=
share_title
val
web
=
UMWeb
(
share_url
)
web
.
title
=
share_title
//标题
web
.
setThumb
(
UMImage
(
activity
,
image
))
//缩略图
web
.
description
=
content
//描述
val
config
=
ShareBoardConfig
()
config
.
setIndicatorVisibility
(
false
)
if
(
activity
.
packageName
.
endsWith
(
"yidianling_atk9"
))
{
ShareAction
(
activity
).
withMedia
(
web
)
.
setDisplayList
(
SHARE_MEDIA
.
QQ
,
SHARE_MEDIA
.
QZONE
)
.
setCallback
(
object
:
UMShareListener
{
override
fun
onStart
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"开始分享------"
)
}
override
fun
onResult
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享结束------"
)
}
override
fun
onError
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
{
LogUtil
.
e
(
"ydl"
,
"分享出错------"
+
throwable
.
message
)
try
{
var
message
=
handleMessage
(
throwable
.
message
!!
)
ToastUtil
.
toastShort
(
"分享失败,"
+
message
)
}
catch
(
e
:
Exception
)
{
ToastUtil
.
toastShort
(
"分享错误"
)
}
}
override
fun
onCancel
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享取消------"
)
}
})
.
open
(
config
)
}
else
{
ShareAction
(
activity
).
withMedia
(
web
)
.
setDisplayList
(
SHARE_MEDIA
.
WEIXIN
,
SHARE_MEDIA
.
WEIXIN_CIRCLE
,
SHARE_MEDIA
.
QQ
,
SHARE_MEDIA
.
QZONE
)
.
setCallback
(
object
:
UMShareListener
{
override
fun
onStart
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"开始分享------"
)
}
override
fun
onResult
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享结束------"
)
callBack
?.
onShareSuccessed
(
share_media
)
callBack
=
null
}
override
fun
onError
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
{
LogUtil
.
e
(
"ydl"
,
"分享出错------"
+
throwable
.
message
)
try
{
var
message
=
handleMessage
(
throwable
.
message
!!
)
ToastUtil
.
toastShort
(
"分享失败,"
+
message
)
}
catch
(
e
:
Exception
)
{
ToastUtil
.
toastShort
(
"分享错误"
)
}
callBack
?.
onShareFailed
(
share_media
,
throwable
)
callBack
=
null
}
override
fun
onCancel
(
share_media
:
SHARE_MEDIA
)
{
LogUtil
.
e
(
"ydl"
,
"分享取消------"
)
}
})
.
open
(
config
)
}
}
/**
* 强制处理分享失败消息
*/
fun
handleMessage
(
msg
:
String
):
String
{
var
index
=
msg
.
indexOf
(
"错误信息"
)
var
message
=
msg
.
substring
(
index
,
msg
!!
.
length
)
var
lastIndex
=
message
.
indexOf
(
" "
)
message
=
message
.
substring
(
0
,
lastIndex
)
return
message
}
}
//
//import android.app.Activity
//import android.graphics.Bitmap
//import android.text.TextUtils
//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.UMMin
//import com.umeng.socialize.media.UMWeb
//import com.umeng.socialize.shareboard.ShareBoardConfig
//import com.ydl.ydlcommon.utils.remind.ToastHelper
//import com.ydl.ydlcommon.view.dialog.CustomShareDialog
//import com.yidianling.common.tools.LogUtil
//import com.yidianling.common.tools.ToastUtil
///**
// * 分享工具类
// */
//
//object ShareUtils {
//
// var platform: SHARE_MEDIA? = null
//
// var callBack: ShareActionCallBack? = null
//
// /**
// * 直接分享到指定平台
// * @param platform
// */
// fun shareTo(platform: SHARE_MEDIA?, context: Activity, share_title: String, share_url: String, share_context: String?, share_head: String?) {
// LogUtil.d("shareTo")
// val web = UMWeb(share_url)
// web.title = share_title //标题
// if (platform == SHARE_MEDIA.WEIXIN_CIRCLE) {
// web.title = "$share_title\n$share_context"
// }
// web.setThumb(UMImage(context, share_head
// ?: "http://static.ydlcdn.com/v1/images/logo320.png")) //缩略图
// web.description = share_context//描述
// ShareAction(context)
// .setPlatform(platform)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .withMedia(web)
// .share()
// }
//
// /**
// * 分享纯图片到微信
// */
// fun sharePicToWeiXin(context: Activity, bitmap: Bitmap?) {
// if (bitmap == null) {
// ToastUtil.toastShort("数据异常,请重试")
// return
// }
// if (platform == null) {
// ToastUtil.toastShort("分享异常,请重试")
// return
// }
// val image = UMImage(context, bitmap)//bitmap文件
//
// val thumb = UMImage(context, bitmap)
// image.setThumb(thumb)
//
// image.compressStyle = UMImage.CompressStyle.SCALE//大小压缩,默认为大小压缩,适合普通很大的图
// image.compressStyle = UMImage.CompressStyle.QUALITY//质量压缩,适合长图的分享
// ShareAction(context)
// .setPlatform(platform)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .withMedia(image)
// .share()
// }
//
// /**
// * 分享小程序类型
// */
// fun shareSmailWeixin(context: Activity, share_title: String, share_url: String, share_context: String?, image: String?, path: String?, id: String?, shareListener: UMShareListener?) {
// val umMin = UMMin(share_url) //兼容低版本的网页链接
// val img = UMImage(context, image)
// img.compressStyle = UMImage.CompressStyle.SCALE
// umMin.setThumb(img) // 小程序消息封面图片
// umMin.title = share_title // 小程序消息title
// umMin.description = share_context // 小程序消息描述
// umMin.path = path //小程序页面路径
// umMin.userName = id // 小程序原始id,在微信平台查询
// ShareAction(context)
// .withMedia(umMin)
// .setPlatform(SHARE_MEDIA.WEIXIN)
// .setCallback(shareListener)
// .share()
// }
//
// /**
// * 自定义分享弹出框
// * author harvie
// * @param activity
// * @param actions 扩展按钮
// * @param share_title
// * @param share_url
// * @param share_context
// * @param share_head
// */
// fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?, actions: List<ShareMoreBean>) {
// var content = share_context
// var image = share_head
// if (share_title == null || share_url == null) {
// ToastHelper.show("缺少分享参数")
// return
// }
// if (TextUtils.isEmpty(share_head)) {
// image = "http://static.ydlcdn.com/v1/images/logo320.png"
// }
// if (TextUtils.isEmpty(content)) content = share_title
// val dialog = CustomShareDialog(activity)
// dialog.setShareBody(share_title, share_url, content ?: "", image!!)
// dialog.addActions(actions)
// dialog.show()
//
// }
//
// /**
// * 友盟自带分享弹框
// */
// fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?) {
// LogUtil.d("share")
// var content = share_context
// var image = share_head
// if (share_title == null || share_url == null) {
// ToastHelper.show("缺少分享参数")
// return
// }
// if (share_head == null || share_head == "") {
// image = "http://static.ydlcdn.com/v1/images/logo320.png"
// }
// if (TextUtils.isEmpty(content)) content = share_title
//
// val web = UMWeb(share_url)
// web.title = share_title//标题
// web.setThumb(UMImage(activity, image)) //缩略图
// web.description = content//描述
// val config = ShareBoardConfig()
// config.setIndicatorVisibility(false)
// if (activity.packageName.endsWith("yidianling_atk9")) {
// ShareAction(activity).withMedia(web)
// .setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .open(config)
// } else {
// ShareAction(activity).withMedia(web)
// .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .open(config)
// }
//
// }
//
//
// /**
// * 强制处理分享失败消息
// */
// fun handleMessage(msg: String): String {
// var index = msg.indexOf("错误信息")
// var message = msg.substring(index, msg!!.length)
// var lastIndex = message.indexOf(" ")
// message = message.substring(0, lastIndex)
// return message
// }
//}
//
////
///**
// *
// */
//class ShareMoreBean(var imageResId: Int, var actionName: String, //扩展按钮动作
// var shareMoreAction: ShareMoreAction?)
//
////分享动作
//interface ShareMoreAction {
// fun onClick()
//}
//
//interface ShareActionCallBack {
// fun onShareSuccessed(share_media: SHARE_MEDIA)
// fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable)
//}
/**
*
*/
class
ShareMoreBean
(
var
imageResId
:
Int
,
var
actionName
:
String
,
//扩展按钮动作
var
shareMoreAction
:
ShareMoreAction
?
)
//分享动作
interface
ShareMoreAction
{
fun
onClick
()
}
interface
ShareActionCallBack
{
fun
onShareSuccessed
(
share_media
:
SHARE_MEDIA
)
fun
onShareFailed
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
}
ydl-platform/src/main/java/com/ydl/ydlcommon/view/dialog/CustomShareDialog.kt
View file @
9e69e5db
//package com.ydl.ydlcommon.view.dialog
//
//import android.app.Activity
//import android.app.Dialog
//import android.os.Bundle
//import android.view.View
//import android.view.ViewGroup
//import android.widget.AdapterView
//import android.widget.ImageView
//import com.umeng.socialize.bean.SHARE_MEDIA
//import com.ydl.ydlcommon.R
//import com.ydl.ydlcommon.actions.share.ShareMoreBean
//import com.ydl.ydlcommon.actions.share.ShareUtils
//import com.ydl.ydlcommon.adapter.CommonAdapter
//import com.ydl.ydlcommon.view.BaseViewHolder
//import kotlinx.android.synthetic.main.platform_share_custom_ui.*
//
///**
// * 自定义分享Dialog
// * Created by hgw on 2017/3/22.
// */
//
//class CustomShareDialog(private val context: Activity) : Dialog(context, R.style.platform_transparentFrameWindowStyle), View.OnClickListener {
//
//
// private var share_title: String? = null
// private var share_url: String? = null
// private var share_context: String? = null
// private var share_head: String? = null
// private var list: List<ShareMoreBean>? = null
//
// private var adapter: CommonAdapter<ShareMoreBean>? = null
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// setContentView(R.layout.platform_share_custom_ui)
//
// initView()
//
// val window = window
// // 设置显示动画
// window!!.setWindowAnimations(R.style.platform_main_menu_animstyle)
// val wl = window.attributes
// wl.x = 0
// wl.y = context.windowManager.defaultDisplay.height
// // 以下这两句是为了保证按钮可以水平满屏
// wl.width = ViewGroup.LayoutParams.MATCH_PARENT
// wl.height = ViewGroup.LayoutParams.WRAP_CONTENT
//
// // 设置显示位置
// onWindowAttributesChanged(wl)
// // 设置点击外围解散
// setCanceledOnTouchOutside(true)
// }
//
// private fun initView() {
//
// share_weichat.setOnClickListener(this)
// share_pyq.setOnClickListener(this)
// share_qqzone.setOnClickListener(this)
// share_qq.setOnClickListener(this)
//
//
// if (list == null || list!!.isEmpty()) {
// grid_view!!.visibility = View.GONE
// return
// } else {
// grid_view!!.visibility = View.VISIBLE
// }
// adapter = object : CommonAdapter<ShareMoreBean>() {
// override fun getView(position: Int, convertView1: View?, parent: ViewGroup): View {
// var convertView = convertView1
// val holder: BaseViewHolder
// if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.platform_item_custom_share_ui, null)
// holder = BaseViewHolder(convertView)
// convertView!!.tag = holder
// } else {
// holder = convertView.tag as BaseViewHolder
// }
// val imageView = holder.getView<ImageView>(R.id.share_img)
// //加载图标
// imageView.setImageResource(mDataList[position].imageResId)
// //设置title
// holder.setText(R.id.text_title, mDataList[position].actionName)
// return convertView
// }
// }
// grid_view!!.adapter = adapter
// grid_view!!.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
// val action = adapter!!.dataList[position].shareMoreAction
// action?.onClick()
// dismiss()
// }
// adapter!!.update(list)
// }
//
// //设置分享内容
// fun setShareBody(share_title: String, share_url: String, share_context: String, share_head: String) {
// this.share_title = share_title
// this.share_url = share_url
// this.share_context = share_context
// this.share_head = share_head
// }
//
// //添加扩展按钮
// fun addActions(list1: List<ShareMoreBean>) {
// this.list = list1
// }
//
// override fun onClick(v: View) {
// when (v.id) {
// R.id.share_weichat -> {
// ShareUtils.shareTo(SHARE_MEDIA.WEIXIN, context, share_title!!, share_url!!, share_context!!, share_head)
// dismiss()
// }
// R.id.share_pyq -> {
// ShareUtils.shareTo(SHARE_MEDIA.WEIXIN_CIRCLE, context, share_title!!, share_url!!, share_context!!, share_head)
// dismiss()
// }
// R.id.share_qq -> {
// ShareUtils.shareTo(SHARE_MEDIA.QQ, context, share_title!!, share_url!!, share_context!!, share_head)
// dismiss()
// }
// R.id.share_qqzone -> {
// ShareUtils.shareTo(SHARE_MEDIA.QZONE, context, share_title!!, share_url!!, share_context!!, share_head)
// dismiss()
// }
// }
// }
//
// override fun show() {
// if (null == context) {
// return
// }
// if (context is Activity) {
// if (context.isFinishing) {
// return
// }
// }
// super.show()
// }
//}
//
package
com.ydl.ydlcommon.view.dialog
import
android.app.Activity
import
android.app.Dialog
import
android.os.Bundle
import
android.view.View
import
android.view.ViewGroup
import
android.widget.AdapterView
import
android.widget.ImageView
import
com.umeng.socialize.bean.SHARE_MEDIA
import
com.ydl.ydlcommon.R
import
com.ydl.ydlcommon.actions.share.ShareMoreBean
import
com.ydl.ydlcommon.actions.share.ShareUtils
import
com.ydl.ydlcommon.adapter.CommonAdapter
import
com.ydl.ydlcommon.view.BaseViewHolder
import
kotlinx.android.synthetic.main.platform_share_custom_ui.*
/**
* 自定义分享Dialog
* Created by hgw on 2017/3/22.
*/
class
CustomShareDialog
(
private
val
context
:
Activity
)
:
Dialog
(
context
,
R
.
style
.
platform_transparentFrameWindowStyle
),
View
.
OnClickListener
{
private
var
share_title
:
String
?
=
null
private
var
share_url
:
String
?
=
null
private
var
share_context
:
String
?
=
null
private
var
share_head
:
String
?
=
null
private
var
list
:
List
<
ShareMoreBean
>?
=
null
private
var
adapter
:
CommonAdapter
<
ShareMoreBean
>?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
platform_share_custom_ui
)
initView
()
val
window
=
window
// 设置显示动画
window
!!
.
setWindowAnimations
(
R
.
style
.
platform_main_menu_animstyle
)
val
wl
=
window
.
attributes
wl
.
x
=
0
wl
.
y
=
context
.
windowManager
.
defaultDisplay
.
height
// 以下这两句是为了保证按钮可以水平满屏
wl
.
width
=
ViewGroup
.
LayoutParams
.
MATCH_PARENT
wl
.
height
=
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
// 设置显示位置
onWindowAttributesChanged
(
wl
)
// 设置点击外围解散
setCanceledOnTouchOutside
(
true
)
}
private
fun
initView
()
{
share_weichat
.
setOnClickListener
(
this
)
share_pyq
.
setOnClickListener
(
this
)
share_qqzone
.
setOnClickListener
(
this
)
share_qq
.
setOnClickListener
(
this
)
if
(
list
==
null
||
list
!!
.
isEmpty
())
{
grid_view
!!
.
visibility
=
View
.
GONE
return
}
else
{
grid_view
!!
.
visibility
=
View
.
VISIBLE
}
adapter
=
object
:
CommonAdapter
<
ShareMoreBean
>()
{
override
fun
getView
(
position
:
Int
,
convertView1
:
View
?,
parent
:
ViewGroup
):
View
{
var
convertView
=
convertView1
val
holder
:
BaseViewHolder
if
(
convertView
==
null
)
{
convertView
=
layoutInflater
.
inflate
(
R
.
layout
.
platform_item_custom_share_ui
,
null
)
holder
=
BaseViewHolder
(
convertView
)
convertView
!!
.
tag
=
holder
}
else
{
holder
=
convertView
.
tag
as
BaseViewHolder
}
val
imageView
=
holder
.
getView
<
ImageView
>(
R
.
id
.
share_img
)
//加载图标
imageView
.
setImageResource
(
mDataList
[
position
].
imageResId
)
//设置title
holder
.
setText
(
R
.
id
.
text_title
,
mDataList
[
position
].
actionName
)
return
convertView
}
}
grid_view
!!
.
adapter
=
adapter
grid_view
!!
.
onItemClickListener
=
AdapterView
.
OnItemClickListener
{
_
,
_
,
position
,
_
->
val
action
=
adapter
!!
.
dataList
[
position
].
shareMoreAction
action
?.
onClick
()
dismiss
()
}
adapter
!!
.
update
(
list
)
}
//设置分享内容
fun
setShareBody
(
share_title
:
String
,
share_url
:
String
,
share_context
:
String
,
share_head
:
String
)
{
this
.
share_title
=
share_title
this
.
share_url
=
share_url
this
.
share_context
=
share_context
this
.
share_head
=
share_head
}
//添加扩展按钮
fun
addActions
(
list1
:
List
<
ShareMoreBean
>)
{
this
.
list
=
list1
}
override
fun
onClick
(
v
:
View
)
{
when
(
v
.
id
)
{
R
.
id
.
share_weichat
->
{
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
WEIXIN
,
context
,
share_title
!!
,
share_url
!!
,
share_context
!!
,
share_head
)
dismiss
()
}
R
.
id
.
share_pyq
->
{
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
WEIXIN_CIRCLE
,
context
,
share_title
!!
,
share_url
!!
,
share_context
!!
,
share_head
)
dismiss
()
}
R
.
id
.
share_qq
->
{
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
QQ
,
context
,
share_title
!!
,
share_url
!!
,
share_context
!!
,
share_head
)
dismiss
()
}
R
.
id
.
share_qqzone
->
{
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
QZONE
,
context
,
share_title
!!
,
share_url
!!
,
share_context
!!
,
share_head
)
dismiss
()
}
}
}
override
fun
show
()
{
if
(
null
==
context
)
{
return
}
if
(
context
is
Activity
)
{
if
(
context
.
isFinishing
)
{
return
}
}
super
.
show
()
}
}
ydl-platform/src/main/java/com/ydl/ydlcommon/view/dialog/YDLShareDialog.kt
View file @
9e69e5db
//package com.ydl.ydlcommon.view.dialog
//
//import android.annotation.SuppressLint
//import android.app.Activity
//import android.app.DialogFragment
//import android.graphics.drawable.ColorDrawable
//import android.os.Bundle
//import android.text.TextUtils
//import android.util.Base64
//import android.view.*
//import android.widget.LinearLayout
//import com.bumptech.glide.load.engine.DiskCacheStrategy
//import com.umeng.socialize.bean.SHARE_MEDIA
//import com.ydl.ydl_image.module.GlideApp
//import com.ydl.ydlcommon.R
//import com.ydl.ydlcommon.actions.share.ShareActionCallBack
//import com.ydl.ydlcommon.actions.share.ShareUtils
//import com.ydl.ydlcommon.utils.ImageUtil
//import com.ydl.ydlcommon.utils.ScreenUtil
//import com.yidianling.common.tools.RxImageTool
//import kotlinx.android.synthetic.main.platform_dialog_share.*
//import java.util.concurrent.Executors
//
//
///**
// * @author yuanWai
// * @描述:分享弹窗
// * @Copyright Copyright (c) 2018
// * @Company 壹点灵
// * @date 2019/2/19
// */
//class YDLShareDialog : DialogFragment {
//
// private var mActivity: Activity? = null
// private var shareTitle: String? = null
// private var shareUrl: String? = null
// private var shareContent: String? = null
// private var base64DataStr: String? = null
// private var shareHead: String? = null
// private var mCallback: ICallBack? = null
// private var mShareCallBack: IShareCallBack? = null
//
// //小程序页面地址
// private var path: String? = null
// //小程序id
// private var minProgramId: String? = null
//
// private var dp55 = 0
// private var dp7 = 0
// private var llmargin = 0
//
// @SuppressLint("ValidFragment")
// constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?) : super() {
// this.mActivity = activity
// this.shareTitle = shareTitle
// this.shareUrl = shareUrl
// this.shareContent = shareContent
// this.shareHead = shareHead
// }
//
// //传递小程序参数
// @SuppressLint("ValidFragment")
// constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, path: String?, minProgramId: String?) : super() {
// this.mActivity = activity
// this.shareTitle = shareTitle
// this.shareUrl = shareUrl
// this.shareContent = shareContent
// this.shareHead = shareHead
// this.path = path
// this.minProgramId = minProgramId
// }
//
// constructor() : super() {}
//
// init {
// dp55 = RxImageTool.dip2px(55f)
// llmargin = (ScreenUtil.screenWidth - RxImageTool.dip2px(260f)) / 3
// dp7 = RxImageTool.dip2px(7.5f)
// }
//
// companion object {
// var typeStyle: Int = 0
// /**
// * 1.为显示1排(5个) 2.为显示2排(隐藏动态和举报)3.为显示2排(隐藏动态和删除) 4.为显示1排(4个)隐藏动态按钮 5:生成海报按钮、隐藏动态 6:保存海报按钮、隐藏动态 7.为显示1排(4个)隐藏动态按钮
// */
// const val TYPE1 = 1
// const val TYPE2 = 2
// const val TYPE3 = 3
// const val TYPE4 = 4
// const val TYPE5 = 5
// const val TYPE6 = 6
// const val TYPE7 = 7
// /**
// * 点击事件类型 1.动态 2.删除 3.举报 4.返回首页 5:生成海报 6:保存本地 7:分享纯图片
// */
// const val CLICK_DYNAMIC = 1
// const val CLICK_DELETE = 2
// const val CLICK_REPORT = 3
// const val CLICK_BACKHOME = 4
// const val CLICK_POSTER = 5
// const val CLICK_SAVE = 6
// const val CLICK_SHARE_IMAGE = 7
//
// fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE1
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// //支持分享小程序
// fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog {
// typeStyle = TYPE1
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId)
// }
//
// fun style2(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE2
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// fun style3(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE3
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// fun style4(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE4
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// fun style5(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE5
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// fun style6(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
// typeStyle = TYPE6
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
// }
//
// //支持分享小程序
// fun style7(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog {
// typeStyle = TYPE7
// return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId)
// }
// }
//
// override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
// //去掉dialog的标题,需要在setContentView()之前
// this.dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
// val window = this.dialog.window
// //去掉dialog默认的padding
// window!!.decorView.setPadding(0, 0, 0, 0)
// val lp = window.attributes
// lp.width = WindowManager.LayoutParams.MATCH_PARENT
// lp.height = WindowManager.LayoutParams.WRAP_CONTENT
// //设置dialog的位置在底部
// lp.gravity = Gravity.BOTTOM
// //设置dialog的动画
// lp.windowAnimations = R.style.platform_BottomDialogAnimation
// window.attributes = lp
// window.setBackgroundDrawable(ColorDrawable())
// return inflater!!.inflate(R.layout.platform_dialog_share, null)
// }
//
//
// /**
// * 设置咨询师海报的图片
// * @param base64DataStr base64数据
// */
// fun setPosterPicture(base64DataStr: String) {
// this.base64DataStr = base64DataStr
// }
//
// override fun onResume() {
// super.onResume()
// initView()
// initParams()
// }
//
// /**
// * 初始化样式
// */
// private fun initParams() {
// when (typeStyle) {
// TYPE1 -> {
// //样式1
// ll_layout2.visibility = View.GONE
// }
// TYPE2 -> {
// //样式2
// ll_dynamic.visibility = View.GONE
// ll_report.visibility = View.GONE
// setStyle()
// val deleteParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// deleteParams.setMargins(dp7, 0, llmargin, 0)
// deleteParams.weight = 0f
// ll_delete.layoutParams = deleteParams
// }
// TYPE3 -> {
// //样式3
// ll_dynamic.visibility = View.GONE
// ll_delete.visibility = View.GONE
// setStyle()
// val reportParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// reportParams.setMargins(dp7, 0, llmargin, 0)
// reportParams.weight = 0f
// ll_report.layoutParams = reportParams
// }
// TYPE4 -> {
// //样式4
// ll_dynamic.visibility = View.GONE
// ll_layout2.visibility = View.GONE
// setStyle()
// }
// TYPE5 -> {
// //样式5
// ll_dynamic.visibility = View.GONE
// ll_poster.visibility = View.VISIBLE
// ll_layout2.visibility = View.GONE
// }
// TYPE6 -> {
// //样式6
// ll_dynamic.visibility = View.GONE
// ll_save.visibility = View.VISIBLE
// ll_layout2.visibility = View.GONE
// }
// TYPE7 -> {
// //样式7
// ll_layout2.visibility = View.GONE
// ll_dynamic.visibility = View.GONE
// }
// }
//
// showPictureView()
// }
//
//
// private fun showPictureView() {
// if (TextUtils.isEmpty(base64DataStr)) {
// return
// }
// cv_pic.visibility = View.VISIBLE
//
// Executors.newCachedThreadPool().execute {
// var imageByte = Base64.decode(base64DataStr, Base64.DEFAULT)
// mActivity!!.runOnUiThread {
// GlideApp.with(this)
// .load(imageByte)
// .diskCacheStrategy(DiskCacheStrategy.NONE)
// .into(img_pic)
// }
// }
//
// tv_save_pic.setOnClickListener {
// ImageUtil.savePicture(mActivity, base64DataStr)
// }
// }
//
// private fun setStyle() {
// val weixinParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// weixinParams.setMargins(dp7, 0, 0, 0)
// weixinParams.weight = 0f
// ll_weixin.layoutParams = weixinParams
//
// val friendsParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// friendsParams.setMargins(llmargin, 0, 0, 0)
// friendsParams.weight = 0f
// ll_friends.layoutParams = friendsParams
//
// val qqzoneParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// qqzoneParams.setMargins(llmargin, 0, 0, 0)
// qqzoneParams.weight = 0f
// ll_qqzone.layoutParams = qqzoneParams
//
// val qqParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// qqParams.setMargins(llmargin, 0, dp7, 0)
// qqParams.weight = 0f
// ll_qq.layoutParams = qqParams
// ll_layout.invalidate()
//
// val backhomeParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
// backhomeParams.setMargins(0, 0, 0, 0)
// backhomeParams.weight = 0f
// ll_backhome.layoutParams = backhomeParams
// }
//
// fun setCallBack(callback: ICallBack) {
// this.mCallback = callback
// }
//
// fun setShareCallBack(callBack: IShareCallBack) {
// this.mShareCallBack = callBack
// }
//
// private fun initView() {
// ll_poster.setOnClickListener {
// //生成海报
// mCallback?.callBack(CLICK_POSTER)
// dismiss()
// }
//
// ll_save.setOnClickListener {
// //保存本地
// mCallback?.callBack(CLICK_SAVE)
// dismiss()
// }
// ll_dynamic.setOnClickListener {
// //动态
// mCallback?.callBack(CLICK_DYNAMIC)
// dismiss()
// }
// ll_weixin.setOnClickListener {
// //分享海报到微信:直接分享图片到微信
// if (typeStyle == TYPE6) {
// ShareUtils.platform = SHARE_MEDIA.WEIXIN
// mCallback?.callBack(CLICK_SHARE_IMAGE)
// } else {
// //微信
// if (TextUtils.isEmpty(minProgramId)) {
// share(SHARE_MEDIA.WEIXIN)
// } else {
// shareMinWeixin()
// }
// }
// }
// ll_friends.setOnClickListener {
// //分享海报到微信朋友圈:直接分享图片到微信朋友圈
// if (typeStyle == TYPE6) {
// ShareUtils.platform = SHARE_MEDIA.WEIXIN_CIRCLE
// mCallback?.callBack(CLICK_SHARE_IMAGE)
// } else {
// //微信朋友圈
// share(SHARE_MEDIA.WEIXIN_CIRCLE)
// }
// }
// ll_qqzone.setOnClickListener {
// //分享海报到qq空间:直接分享图片到qq空间
// if (typeStyle == TYPE6) {
// ShareUtils.platform = SHARE_MEDIA.QZONE
// mCallback?.callBack(CLICK_SHARE_IMAGE)
// } else {
// //qq空间
// share(SHARE_MEDIA.QZONE)
// }
// }
// ll_qq.setOnClickListener {
// //分享海报到qq:直接分享图片到qq
// if (typeStyle == TYPE6) {
// ShareUtils.platform = SHARE_MEDIA.QQ
// mCallback?.callBack(CLICK_SHARE_IMAGE)
// } else {
// //qq
// share(SHARE_MEDIA.QQ)
// }
// }
// if (TYPE2 == typeStyle || TYPE3 == typeStyle) {
// ll_delete.setOnClickListener {
// //删除
// mCallback?.callBack(CLICK_DELETE)
// dismiss()
// }
// ll_report.setOnClickListener {
// //举报
// mCallback?.callBack(CLICK_REPORT)
// dismiss()
// }
// ll_backhome.setOnClickListener {
// //返回首页
// mCallback?.callBack(CLICK_BACKHOME)
// dismiss()
// }
// }
// tv_cancel.setOnClickListener {
// //取消
// dismiss()
// }
// rl_root.setOnClickListener {
// //取消
// dismiss()
// }
// }
//
// private fun share(platform: SHARE_MEDIA) {
// ShareUtils.shareTo(platform, mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead)
// ShareUtils.callBack = object : ShareActionCallBack {
// override fun onShareSuccessed(share_media: SHARE_MEDIA) {
// mShareCallBack?.onShareSuccessed(share_media)
// }
//
// override fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable) {
// mShareCallBack?.onShareFailed(share_media, throwable)
// }
// }
// dismiss()
// }
//
// /**
// * 分享小程序
// */
// private fun shareMinWeixin() {
// //分享小程序到微信
// ShareUtils.shareSmailWeixin(mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead, path, minProgramId, null)
// dismiss()
// }
//
// interface ICallBack {
// fun callBack(type: Int)
// }
//
// interface IShareCallBack {
// fun onShareSuccessed(share_media: SHARE_MEDIA)
// fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable)
// }
//}
\ No newline at end of file
package
com.ydl.ydlcommon.view.dialog
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.app.DialogFragment
import
android.graphics.drawable.ColorDrawable
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Base64
import
android.view.*
import
android.widget.LinearLayout
import
com.bumptech.glide.load.engine.DiskCacheStrategy
import
com.umeng.socialize.bean.SHARE_MEDIA
import
com.ydl.ydl_image.module.GlideApp
import
com.ydl.ydlcommon.R
import
com.ydl.ydlcommon.actions.share.ShareActionCallBack
import
com.ydl.ydlcommon.actions.share.ShareUtils
import
com.ydl.ydlcommon.utils.ImageUtil
import
com.ydl.ydlcommon.utils.ScreenUtil
import
com.yidianling.common.tools.RxImageTool
import
kotlinx.android.synthetic.main.platform_dialog_share.*
import
java.util.concurrent.Executors
/**
* @author yuanWai
* @描述:分享弹窗
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2019/2/19
*/
class
YDLShareDialog
:
DialogFragment
{
private
var
mActivity
:
Activity
?
=
null
private
var
shareTitle
:
String
?
=
null
private
var
shareUrl
:
String
?
=
null
private
var
shareContent
:
String
?
=
null
private
var
base64DataStr
:
String
?
=
null
private
var
shareHead
:
String
?
=
null
private
var
mCallback
:
ICallBack
?
=
null
private
var
mShareCallBack
:
IShareCallBack
?
=
null
//小程序页面地址
private
var
path
:
String
?
=
null
//小程序id
private
var
minProgramId
:
String
?
=
null
private
var
dp55
=
0
private
var
dp7
=
0
private
var
llmargin
=
0
@SuppressLint
(
"ValidFragment"
)
constructor
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
)
:
super
()
{
this
.
mActivity
=
activity
this
.
shareTitle
=
shareTitle
this
.
shareUrl
=
shareUrl
this
.
shareContent
=
shareContent
this
.
shareHead
=
shareHead
}
//传递小程序参数
@SuppressLint
(
"ValidFragment"
)
constructor
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?,
path
:
String
?,
minProgramId
:
String
?
)
:
super
()
{
this
.
mActivity
=
activity
this
.
shareTitle
=
shareTitle
this
.
shareUrl
=
shareUrl
this
.
shareContent
=
shareContent
this
.
shareHead
=
shareHead
this
.
path
=
path
this
.
minProgramId
=
minProgramId
}
constructor
()
:
super
()
{}
init
{
dp55
=
RxImageTool
.
dip2px
(
55f
)
llmargin
=
(
ScreenUtil
.
screenWidth
-
RxImageTool
.
dip2px
(
260f
))
/
3
dp7
=
RxImageTool
.
dip2px
(
7.5f
)
}
companion
object
{
var
typeStyle
:
Int
=
0
/**
* 1.为显示1排(5个) 2.为显示2排(隐藏动态和举报)3.为显示2排(隐藏动态和删除) 4.为显示1排(4个)隐藏动态按钮 5:生成海报按钮、隐藏动态 6:保存海报按钮、隐藏动态 7.为显示1排(4个)隐藏动态按钮
*/
const
val
TYPE1
=
1
const
val
TYPE2
=
2
const
val
TYPE3
=
3
const
val
TYPE4
=
4
const
val
TYPE5
=
5
const
val
TYPE6
=
6
const
val
TYPE7
=
7
/**
* 点击事件类型 1.动态 2.删除 3.举报 4.返回首页 5:生成海报 6:保存本地 7:分享纯图片
*/
const
val
CLICK_DYNAMIC
=
1
const
val
CLICK_DELETE
=
2
const
val
CLICK_REPORT
=
3
const
val
CLICK_BACKHOME
=
4
const
val
CLICK_POSTER
=
5
const
val
CLICK_SAVE
=
6
const
val
CLICK_SHARE_IMAGE
=
7
fun
style1
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE1
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
//支持分享小程序
fun
style1
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?,
minProgramPath
:
String
?
=
""
,
minProgramId
:
String
?
=
""
):
YDLShareDialog
{
typeStyle
=
TYPE1
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
,
minProgramPath
,
minProgramId
)
}
fun
style2
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE2
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
fun
style3
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE3
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
fun
style4
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE4
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
fun
style5
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE5
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
fun
style6
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?
):
YDLShareDialog
{
typeStyle
=
TYPE6
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
)
}
//支持分享小程序
fun
style7
(
activity
:
Activity
,
shareTitle
:
String
?,
shareUrl
:
String
?,
shareContent
:
String
?,
shareHead
:
String
?,
minProgramPath
:
String
?
=
""
,
minProgramId
:
String
?
=
""
):
YDLShareDialog
{
typeStyle
=
TYPE7
return
YDLShareDialog
(
activity
,
shareTitle
,
shareUrl
,
shareContent
,
shareHead
,
minProgramPath
,
minProgramId
)
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
?,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
{
//去掉dialog的标题,需要在setContentView()之前
this
.
dialog
.
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
)
val
window
=
this
.
dialog
.
window
//去掉dialog默认的padding
window
!!
.
decorView
.
setPadding
(
0
,
0
,
0
,
0
)
val
lp
=
window
.
attributes
lp
.
width
=
WindowManager
.
LayoutParams
.
MATCH_PARENT
lp
.
height
=
WindowManager
.
LayoutParams
.
WRAP_CONTENT
//设置dialog的位置在底部
lp
.
gravity
=
Gravity
.
BOTTOM
//设置dialog的动画
lp
.
windowAnimations
=
R
.
style
.
platform_BottomDialogAnimation
window
.
attributes
=
lp
window
.
setBackgroundDrawable
(
ColorDrawable
())
return
inflater
!!
.
inflate
(
R
.
layout
.
platform_dialog_share
,
null
)
}
/**
* 设置咨询师海报的图片
* @param base64DataStr base64数据
*/
fun
setPosterPicture
(
base64DataStr
:
String
)
{
this
.
base64DataStr
=
base64DataStr
}
override
fun
onResume
()
{
super
.
onResume
()
initView
()
initParams
()
}
/**
* 初始化样式
*/
private
fun
initParams
()
{
when
(
typeStyle
)
{
TYPE1
->
{
//样式1
ll_layout2
.
visibility
=
View
.
GONE
}
TYPE2
->
{
//样式2
ll_dynamic
.
visibility
=
View
.
GONE
ll_report
.
visibility
=
View
.
GONE
setStyle
()
val
deleteParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
deleteParams
.
setMargins
(
dp7
,
0
,
llmargin
,
0
)
deleteParams
.
weight
=
0f
ll_delete
.
layoutParams
=
deleteParams
}
TYPE3
->
{
//样式3
ll_dynamic
.
visibility
=
View
.
GONE
ll_delete
.
visibility
=
View
.
GONE
setStyle
()
val
reportParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
reportParams
.
setMargins
(
dp7
,
0
,
llmargin
,
0
)
reportParams
.
weight
=
0f
ll_report
.
layoutParams
=
reportParams
}
TYPE4
->
{
//样式4
ll_dynamic
.
visibility
=
View
.
GONE
ll_layout2
.
visibility
=
View
.
GONE
setStyle
()
}
TYPE5
->
{
//样式5
ll_dynamic
.
visibility
=
View
.
GONE
ll_poster
.
visibility
=
View
.
VISIBLE
ll_layout2
.
visibility
=
View
.
GONE
}
TYPE6
->
{
//样式6
ll_dynamic
.
visibility
=
View
.
GONE
ll_save
.
visibility
=
View
.
VISIBLE
ll_layout2
.
visibility
=
View
.
GONE
}
TYPE7
->
{
//样式7
ll_layout2
.
visibility
=
View
.
GONE
ll_dynamic
.
visibility
=
View
.
GONE
}
}
showPictureView
()
}
private
fun
showPictureView
()
{
if
(
TextUtils
.
isEmpty
(
base64DataStr
))
{
return
}
cv_pic
.
visibility
=
View
.
VISIBLE
Executors
.
newCachedThreadPool
().
execute
{
var
imageByte
=
Base64
.
decode
(
base64DataStr
,
Base64
.
DEFAULT
)
mActivity
!!
.
runOnUiThread
{
GlideApp
.
with
(
this
)
.
load
(
imageByte
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
NONE
)
.
into
(
img_pic
)
}
}
tv_save_pic
.
setOnClickListener
{
ImageUtil
.
savePicture
(
mActivity
,
base64DataStr
)
}
}
private
fun
setStyle
()
{
val
weixinParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
weixinParams
.
setMargins
(
dp7
,
0
,
0
,
0
)
weixinParams
.
weight
=
0f
ll_weixin
.
layoutParams
=
weixinParams
val
friendsParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
friendsParams
.
setMargins
(
llmargin
,
0
,
0
,
0
)
friendsParams
.
weight
=
0f
ll_friends
.
layoutParams
=
friendsParams
val
qqzoneParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
qqzoneParams
.
setMargins
(
llmargin
,
0
,
0
,
0
)
qqzoneParams
.
weight
=
0f
ll_qqzone
.
layoutParams
=
qqzoneParams
val
qqParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
qqParams
.
setMargins
(
llmargin
,
0
,
dp7
,
0
)
qqParams
.
weight
=
0f
ll_qq
.
layoutParams
=
qqParams
ll_layout
.
invalidate
()
val
backhomeParams
=
LinearLayout
.
LayoutParams
(
dp55
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
)
backhomeParams
.
setMargins
(
0
,
0
,
0
,
0
)
backhomeParams
.
weight
=
0f
ll_backhome
.
layoutParams
=
backhomeParams
}
fun
setCallBack
(
callback
:
ICallBack
)
{
this
.
mCallback
=
callback
}
fun
setShareCallBack
(
callBack
:
IShareCallBack
)
{
this
.
mShareCallBack
=
callBack
}
private
fun
initView
()
{
ll_poster
.
setOnClickListener
{
//生成海报
mCallback
?.
callBack
(
CLICK_POSTER
)
dismiss
()
}
ll_save
.
setOnClickListener
{
//保存本地
mCallback
?.
callBack
(
CLICK_SAVE
)
dismiss
()
}
ll_dynamic
.
setOnClickListener
{
//动态
mCallback
?.
callBack
(
CLICK_DYNAMIC
)
dismiss
()
}
ll_weixin
.
setOnClickListener
{
//分享海报到微信:直接分享图片到微信
if
(
typeStyle
==
TYPE6
)
{
ShareUtils
.
platform
=
SHARE_MEDIA
.
WEIXIN
mCallback
?.
callBack
(
CLICK_SHARE_IMAGE
)
}
else
{
//微信
if
(
TextUtils
.
isEmpty
(
minProgramId
))
{
share
(
SHARE_MEDIA
.
WEIXIN
)
}
else
{
shareMinWeixin
()
}
}
}
ll_friends
.
setOnClickListener
{
//分享海报到微信朋友圈:直接分享图片到微信朋友圈
if
(
typeStyle
==
TYPE6
)
{
ShareUtils
.
platform
=
SHARE_MEDIA
.
WEIXIN_CIRCLE
mCallback
?.
callBack
(
CLICK_SHARE_IMAGE
)
}
else
{
//微信朋友圈
share
(
SHARE_MEDIA
.
WEIXIN_CIRCLE
)
}
}
ll_qqzone
.
setOnClickListener
{
//分享海报到qq空间:直接分享图片到qq空间
if
(
typeStyle
==
TYPE6
)
{
ShareUtils
.
platform
=
SHARE_MEDIA
.
QZONE
mCallback
?.
callBack
(
CLICK_SHARE_IMAGE
)
}
else
{
//qq空间
share
(
SHARE_MEDIA
.
QZONE
)
}
}
ll_qq
.
setOnClickListener
{
//分享海报到qq:直接分享图片到qq
if
(
typeStyle
==
TYPE6
)
{
ShareUtils
.
platform
=
SHARE_MEDIA
.
QQ
mCallback
?.
callBack
(
CLICK_SHARE_IMAGE
)
}
else
{
//qq
share
(
SHARE_MEDIA
.
QQ
)
}
}
if
(
TYPE2
==
typeStyle
||
TYPE3
==
typeStyle
)
{
ll_delete
.
setOnClickListener
{
//删除
mCallback
?.
callBack
(
CLICK_DELETE
)
dismiss
()
}
ll_report
.
setOnClickListener
{
//举报
mCallback
?.
callBack
(
CLICK_REPORT
)
dismiss
()
}
ll_backhome
.
setOnClickListener
{
//返回首页
mCallback
?.
callBack
(
CLICK_BACKHOME
)
dismiss
()
}
}
tv_cancel
.
setOnClickListener
{
//取消
dismiss
()
}
rl_root
.
setOnClickListener
{
//取消
dismiss
()
}
}
private
fun
share
(
platform
:
SHARE_MEDIA
)
{
ShareUtils
.
shareTo
(
platform
,
mActivity
!!
,
shareTitle
!!
,
shareUrl
!!
,
shareContent
,
shareHead
)
ShareUtils
.
callBack
=
object
:
ShareActionCallBack
{
override
fun
onShareSuccessed
(
share_media
:
SHARE_MEDIA
)
{
mShareCallBack
?.
onShareSuccessed
(
share_media
)
}
override
fun
onShareFailed
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
{
mShareCallBack
?.
onShareFailed
(
share_media
,
throwable
)
}
}
dismiss
()
}
/**
* 分享小程序
*/
private
fun
shareMinWeixin
()
{
//分享小程序到微信
ShareUtils
.
shareSmailWeixin
(
mActivity
!!
,
shareTitle
!!
,
shareUrl
!!
,
shareContent
,
shareHead
,
path
,
minProgramId
,
null
)
dismiss
()
}
interface
ICallBack
{
fun
callBack
(
type
:
Int
)
}
interface
IShareCallBack
{
fun
onShareSuccessed
(
share_media
:
SHARE_MEDIA
)
fun
onShareFailed
(
share_media
:
SHARE_MEDIA
,
throwable
:
Throwable
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment