package com.ccwangluo.accelerator.utils

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import com.ccwangluo.accelerator.R
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.github.shadowsocks.http.HttpConfig
import com.umeng.socialize.ShareAction
import com.umeng.socialize.bean.SHARE_MEDIA
import com.umeng.socialize.media.UMWeb
import com.xuexiang.xui.widget.dialog.bottomsheet.BottomSheet


class ShareUtils {
    var mdialog: BottomSheet? = null
    fun share(activity: Activity) {
        mdialog = BottomSheet(activity)
        val contentView: View = buildViews(activity)
        mdialog?.setContentView(contentView,
                ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
        mdialog?.show()
    }

    fun buildViews(activity: Activity): View {
        val inflate = View.inflate(activity, R.layout.bottom_sheet_share, null)
        inflate.findViewById<View>(R.id.share_wechat).setOnClickListener {
            DataRePortUtils.report("st_share_wechat_clk")
            shareWeb(activity, SHARE_MEDIA.WEIXIN)
        }
        inflate.findViewById<View>(R.id.share_pyq).setOnClickListener {
            DataRePortUtils.report("st_share_wetfriends_clk")
            shareWeb(activity, SHARE_MEDIA.WEIXIN_CIRCLE)
        }
        inflate.findViewById<View>(R.id.share_qq).setOnClickListener {
            DataRePortUtils.report("st_share_qq_clk")
            shareWeb(activity, SHARE_MEDIA.QQ)
        }
        inflate.findViewById<View>(R.id.share_qqzore).setOnClickListener {
            DataRePortUtils.report("st_share_qqspace_clk")
            shareWeb(activity, SHARE_MEDIA.QZONE)
        }
        inflate.findViewById<View>(R.id.share_close).setOnClickListener {
            mdialog?.dismiss()
        }
        return inflate
    }

    fun shareWeb(activity: Activity, type: SHARE_MEDIA) {
        mdialog?.dismiss()
        val web: UMWeb = UMWeb(HttpConfig.SHARE_URL)
        web.title = "TT手游加速器-韩服专线 畅玩你的快乐" //标题
//        web.setThumb(thumb) //缩略图
        web.description = "韩服专线一键加速，告别手机网络卡顿、延迟、加速慢等问题，韩服游戏加速就用专业的TT加速器！" //描述
        ShareAction(activity)
                .setPlatform(type)
                .withMedia(web)
                .share()
    }
}