Commit e2effc51 authored by wanglei's avatar wanglei

[同步]广告问题

parent e4fcd61a
......@@ -138,7 +138,7 @@ object AdsMgr {
isMaxInit = true
// maxOpenMgr.loadAd(context)
if (!adsConfigBean.adSwitch) {
maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName))
// maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName))
context.toast("max init")
maxInitCallBack?.invoke()
maxInitCallBack = null
......
package com.dumpster.cleaner.business.ads.applovin
import android.app.Activity
import android.content.Context
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError
......@@ -13,7 +12,6 @@ import com.dumpster.cleaner.business.ads.AdState
import com.dumpster.cleaner.business.ads.AdsShowCallBack
import com.dumpster.cleaner.business.ads.AdsType
import com.dumpster.cleaner.business.ads.LimitUtils
import java.lang.ref.WeakReference
/**
*插屏广告加载显示管理类
......@@ -36,7 +34,6 @@ class MaxInsertMgr {
}
if (showCallBack != null) {
adState.activityRef = WeakReference(activity)
this.showCallBack = showCallBack
if (adState.adDialog == null) {
adState.adDialog = activity.showAdCountDownDialog()
......@@ -100,7 +97,7 @@ class MaxInsertMgr {
adState.onAdHidden()
showCallBack?.close()
loadAd(activity.applicationContext, AdMaxEvent("interAd", "preload"))
loadAd(activity, AdMaxEvent("interAd", "preload"))
}
override fun onAdClicked(ad: MaxAd) {
......@@ -119,7 +116,7 @@ class MaxInsertMgr {
fun loadAd(
context: Context,
ac: Activity,
adEvent: AdEvent,
isUnLimit: Boolean = false,
) {
......@@ -136,7 +133,7 @@ class MaxInsertMgr {
adEvent.adPulStart()
adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, context)
adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, ac)
adState.currentAd?.setListener(object : MaxAdListener {
override fun onAdDisplayed(p0: MaxAd) = Unit
......@@ -145,11 +142,9 @@ class MaxInsertMgr {
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) = Unit
override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null)
val ac = adState.activityRef?.get()
if (ac != null) {
show(ac, isUnLimit, adEvent, null)
}
adState.onAdLoaded(null, adEvent)
show(ac, isUnLimit, adEvent, null)
(adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum()
......
......@@ -12,7 +12,6 @@ import com.dumpster.cleaner.business.ads.AdState
import com.dumpster.cleaner.business.ads.AdsShowCallBack
import com.dumpster.cleaner.business.ads.AdsType
import com.dumpster.cleaner.business.ads.LimitUtils
import java.lang.ref.WeakReference
/**
* 开屏广告加载显示管理类
......@@ -29,7 +28,6 @@ class MaxOpenMgr {
if (showCallBack != null) {
this.showCallBack = showCallBack
adState.activityRef = WeakReference(activity)
adEvent.adPrepareShow()
}
......@@ -126,11 +124,11 @@ class MaxOpenMgr {
adState.currentAd = MaxAppOpenAd(GlobalConfig.ID_MAX_OPEN, context)
adState.currentAd?.setListener(object : MaxAdListener {
override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null)
val ac = adState.activityRef?.get()
if (ac != null) {
show(ac, isUnLimit, adEvent, null)
}
// adState.onAdLoaded(null)
// val ac = adState.activityRef?.get()
// if (ac != null) {
// show(ac, isUnLimit, adEvent, null)
// }
(adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum()
}
......
......@@ -4,66 +4,32 @@ import android.os.Build
import com.dumpster.cleaner.BuildConfig
import com.dumpster.cleaner.SpConstObject.ifAgreePrivacy
import com.dumpster.cleaner.GlobalConfig
import com.dumpster.cleaner.business.helper.ReportUtils.doPost
import com.dumpster.cleaner.bean.config.ConfigBean
import com.dumpster.cleaner.utils.AppPreferences
import com.dumpster.cleaner.utils.LogEx
import org.json.JSONException
import okhttp3.Call
import okhttp3.Callback
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import java.io.IOException
import java.util.TimeZone
object EventUtils {
private val TAG = "EventUtils"
fun event(
key: String,
value: String? = null,
ext: JSONObject? = null,
) {
if (!ifAgreePrivacy) {
return
private val client = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
}
}.build()
Thread {
var paramJson: String? = ""
try {
val pkg = GlobalConfig.PACKAGE_NAME
val s = JSONObject()
.put("action", key)
.put("value", value)
.put("ext", ext)
val s2 = JSONObject()
.put("${pkg}_3", AppPreferences.getInstance().getString("Equipment", ""))
.put("${pkg}_4", AppPreferences.getInstance().getString("Manufacturer", ""))
.put("${pkg}_5", Build.VERSION.SDK_INT)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("gid", ""))
.put("${pkg}_13", "android")
.put("${pkg}_15", "google")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
.put("${pkg}_34", TimeZone.getDefault().getID())
val data = JSONObject()
.put("data", s)
.put("bp", s2)
.toString()
LogEx.logDebug(TAG, "uuid=${AppPreferences.getInstance().getString("uuid", "")}")
LogEx.logDebug(TAG, "gid=${AppPreferences.getInstance().getString("gid", "")}")
paramJson = AESHelper.encrypt(data)
} catch (e: JSONException) {
paramJson = ""
}
LogEx.logDebug(TAG, "url=$url")
doPost(
url,
HashMap(),
paramJson
)
}.start()
}
private val url by lazy {
val pkg = GlobalConfig.PACKAGE_NAME
......@@ -76,4 +42,64 @@ object EventUtils {
url.toString()
}
// 获取配置参数
fun getConfigParams(): JSONObject {
val packageName = GlobalConfig.PACKAGE_NAME
val jsonObject = JSONObject()
jsonObject.put("${packageName}_4", Build.MANUFACTURER) // 手机厂商
jsonObject.put("${packageName}_5", Build.VERSION.SDK_INT) // android系统版本号
jsonObject.put("${packageName}_8", BuildConfig.VERSION_NAME) // APP版本号,如:1.1.2
jsonObject.put("${packageName}_9", AppPreferences.getInstance().getString("uuid", "")) // Android id
jsonObject.put("${packageName}_10", AppPreferences.getInstance().getString("gid", "")) // Google advertiser id
jsonObject.put("${packageName}_13", "android") // platform 默认android
jsonObject.put("${packageName}_14", BuildConfig.VERSION_CODE)// android版本,如:13
jsonObject.put("${packageName}_15", "google") // 渠道标识
jsonObject.put("${packageName}_24", BuildConfig.BUILD_TYPE) // 环境
val timeZone: TimeZone = TimeZone.getDefault()
jsonObject.put("${packageName}_34", timeZone.id) // 手机本地时区,值如下格式:America/New_York
return jsonObject
}
fun event(
key: String,
value: String? = null,
ext: JSONObject? = null,
) {
if (BuildConfig.DEBUG || !ifAgreePrivacy || ConfigBean.configBean.noEventKey.contains(key)) {
return
}
val s = JSONObject()
.put("action", key)
.put("value", value)
.put("ext", ext)
val data = JSONObject()
.put("data", s)
.put("bp", getConfigParams())
.toString()
val body = AESHelper.encrypt(data)
.toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
val request = Request.Builder()
.url(url)
.post(body)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
LogEx.logDebug(TAG, "onFailure")
}
override fun onResponse(call: Call, response: Response) {
if (response.code == 200 && response.isSuccessful) {
LogEx.logDebug(TAG, "onResponse 200")
}
}
})
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment