|
|
@@ -1,13 +1,19 @@
|
|
|
-package com.ytpm.hydtw.fragment
|
|
|
+package com.ytpm.qnjz.fragment
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.content.Context
|
|
|
+import android.graphics.Bitmap
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
import android.os.CountDownTimer
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
+import android.widget.FrameLayout
|
|
|
+import android.widget.FrameLayout.LayoutParams
|
|
|
+import android.widget.TextView
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
import androidx.fragment.app.Fragment
|
|
|
import com.anythink.banner.api.ATBannerListener
|
|
|
@@ -21,31 +27,35 @@ import com.anythink.interstitial.api.ATInterstitialListener
|
|
|
import com.anythink.nativead.api.ATNative
|
|
|
import com.anythink.nativead.api.ATNativeAdView
|
|
|
import com.anythink.nativead.api.ATNativeEventListener
|
|
|
+import com.anythink.nativead.api.ATNativeImageView
|
|
|
+import com.anythink.nativead.api.ATNativeMaterial
|
|
|
import com.anythink.nativead.api.ATNativeNetworkListener
|
|
|
+import com.anythink.nativead.api.ATNativePrepareInfo
|
|
|
import com.anythink.nativead.api.NativeAd
|
|
|
import com.anythink.rewardvideo.api.ATRewardVideoAd
|
|
|
import com.anythink.rewardvideo.api.ATRewardVideoListener
|
|
|
-import com.blankj.utilcode.util.GsonUtils
|
|
|
+import com.blankj.utilcode.util.ActivityUtils
|
|
|
import com.blankj.utilcode.util.LogUtils
|
|
|
import com.blankj.utilcode.util.ToastUtils
|
|
|
import com.blankj.utilcode.util.ToastUtils.MODE
|
|
|
import com.gyf.immersionbar.ImmersionBar
|
|
|
-import com.ytpm.hydtw.Constants
|
|
|
-import com.ytpm.hydtw.R
|
|
|
-import com.ytpm.hydtw.adapter.MineAdapter
|
|
|
-import com.ytpm.hydtw.dao.Question
|
|
|
-import com.ytpm.hydtw.dao.Record
|
|
|
-import com.ytpm.hydtw.dao.UserInfo
|
|
|
-import com.ytpm.hydtw.databinding.FragmentDatiBinding
|
|
|
-import com.ytpm.hydtw.loading.GlobalLoading
|
|
|
-import com.ytpm.hydtw.loading.LoadingDialog
|
|
|
-import com.ytpm.hydtw.network.BaseRetrofit
|
|
|
-import com.ytpm.hydtw.network.Callback2
|
|
|
-import com.ytpm.hydtw.utils.DateTimeConverter
|
|
|
-import com.ytpm.hydtw.utils.DateTimeUtils
|
|
|
-import com.ytpm.hydtw.utils.GlideUtils
|
|
|
-import com.ytpm.hydtw.utils.MediationNativeAdUtil
|
|
|
-import com.ytpm.hydtw.utils.UserInfoSpUtils
|
|
|
+import com.ytpm.qnjz.Constants
|
|
|
+import com.ytpm.qnjz.R
|
|
|
+import com.ytpm.qnjz.activity.LoginActivity
|
|
|
+import com.ytpm.qnjz.adapter.MineAdapter
|
|
|
+import com.ytpm.qnjz.dao.Question
|
|
|
+import com.ytpm.qnjz.dao.UserInfo
|
|
|
+import com.ytpm.qnjz.databinding.FragmentDatiBinding
|
|
|
+import com.ytpm.qnjz.loading.LoadingDialog
|
|
|
+import com.ytpm.qnjz.network.BaseRetrofit
|
|
|
+import com.ytpm.qnjz.network.Callback2
|
|
|
+import com.ytpm.qnjz.utils.ConfigSpUtils
|
|
|
+import com.ytpm.qnjz.utils.DateTimeConverter
|
|
|
+import com.ytpm.qnjz.utils.DateTimeUtils
|
|
|
+import com.ytpm.qnjz.utils.GlideUtils
|
|
|
+import com.ytpm.qnjz.utils.MediationNativeAdUtil
|
|
|
+import com.ytpm.qnjz.utils.MutiImageView
|
|
|
+import com.ytpm.qnjz.utils.UserInfoSpUtils
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
@@ -59,6 +69,7 @@ import java.time.Instant
|
|
|
import java.time.LocalDateTime
|
|
|
import java.time.ZoneId
|
|
|
import java.time.format.DateTimeFormatter
|
|
|
+import com.ytpm.qnjz.dao.Record
|
|
|
|
|
|
|
|
|
class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
@@ -110,14 +121,19 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
private var jrdd = 0
|
|
|
private var lsdd = 0
|
|
|
|
|
|
+
|
|
|
private var isGrDialogShow = false
|
|
|
private var isGetTlDialogShow = false
|
|
|
|
|
|
private var isGetResult = false
|
|
|
private var isInAdPaunse = false
|
|
|
+ private var isNativeAdPaunse = false
|
|
|
|
|
|
private var loadDialog: LoadingDialog? = null
|
|
|
private var loadingTime = 10
|
|
|
+ var mSelfRenderView: View? = null //开发者自定义布局的容器
|
|
|
+
|
|
|
+ private var isNativeClick = false
|
|
|
|
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
|
@@ -134,27 +150,25 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
initData()
|
|
|
initUserTime()
|
|
|
initInAdTime()
|
|
|
-// initNativeTime()
|
|
|
+ initNativeTime()
|
|
|
loadBannerAd()
|
|
|
loadNativeAd()
|
|
|
loadInterstitial()
|
|
|
initView()
|
|
|
+ mSelfRenderView = binding.selfview
|
|
|
useTimer = 0
|
|
|
return binding.root
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private fun initView() {
|
|
|
|
|
|
- val headImg = UserInfoSpUtils().getHeadImg()
|
|
|
+ val powerWaitTime = ConfigSpUtils().getConfig()?.powerWaitTime
|
|
|
+ this.getTlTime = powerWaitTime ?: 30
|
|
|
|
|
|
- if (headImg.isNotEmpty()) {
|
|
|
- context?.let {
|
|
|
- GlideUtils().circelImages(it, headImg, binding.dialogGettlHead)
|
|
|
- GlideUtils().circelImages(it, headImg, binding.fragmentDatiHead)
|
|
|
- GlideUtils().circelImages(it, headImg, binding.dialogSetHead)
|
|
|
- }
|
|
|
- }
|
|
|
+ val headImg = UserInfoSpUtils().getHeadImg()
|
|
|
+ GlideUtils().circelImages(requireContext(), headImg.toString(), binding.dialogGettlHead)
|
|
|
+ GlideUtils().circelImages(requireContext(), headImg.toString(), binding.fragmentDatiHead)
|
|
|
+ GlideUtils().circelImages(requireContext(), headImg.toString(), binding.dialogSetHead)
|
|
|
|
|
|
val registerTime = UserInfoSpUtils().getRegistryTime()
|
|
|
val ddd = DateTimeConverter.convertToBeijingTime(registerTime, "yyyy/MM/dd HH:mm:ss")
|
|
|
@@ -186,9 +200,8 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
binding.switch1.isChecked = true
|
|
|
binding.switch2.isChecked = true
|
|
|
|
|
|
- startGetTlTime()
|
|
|
- initGetTlTime()
|
|
|
-
|
|
|
+// startGetTlTime()
|
|
|
+// getTlCountDownTimer?.start()
|
|
|
binding.dialogGr.setOnClickListener {
|
|
|
|
|
|
}
|
|
|
@@ -217,6 +230,12 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
return@setOnClickListener
|
|
|
}
|
|
|
|
|
|
+ val canAccumulation = ConfigSpUtils().getConfig()?.canAccumulation
|
|
|
+ if (canAccumulation != null && canAccumulation == 1 && tl > 0) {
|
|
|
+ ToastUtils.showShort("已有体力请先答题!")
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
+
|
|
|
if (isGetTlDialogShow) {
|
|
|
this.isGetTlDialogShow = false
|
|
|
binding.dialgoGettlLl.visibility = View.GONE
|
|
|
@@ -233,6 +252,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
} else {
|
|
|
nowTime = DateTimeUtils.getCurrentDateTime()
|
|
|
}
|
|
|
+
|
|
|
binding.dialogGettlTime.text = nowTime
|
|
|
|
|
|
startGetTlShowBtnTime()
|
|
|
@@ -241,6 +261,10 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
binding.dialgoGettlLl.setOnClickListener { }
|
|
|
|
|
|
binding.dialotGettlBtnTx.setOnClickListener {
|
|
|
+ if (UserInfoSpUtils().ifPowerLimit()) {
|
|
|
+// ToastUtils.showLong(ConfigSpUtils().getConfig()?.lowValueTip)
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
showAd()
|
|
|
}
|
|
|
binding.getTlDialogClose.setOnClickListener {
|
|
|
@@ -277,7 +301,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
scope = CoroutineScope(Dispatchers.Main + job!!)
|
|
|
}
|
|
|
|
|
|
- scope!!.launch {
|
|
|
+ scope?.launch {
|
|
|
while (isActive) {
|
|
|
useTimer++
|
|
|
delay(1000)
|
|
|
@@ -294,11 +318,15 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
scope1 = CoroutineScope(Dispatchers.Main + job1!!)
|
|
|
}
|
|
|
|
|
|
- scope1!!.launch {
|
|
|
+ scope1?.launch {
|
|
|
while (isActive) {
|
|
|
if (!isInAdPaunse) {
|
|
|
inAdTime++
|
|
|
- if (inAdTime == 30) {
|
|
|
+ val interstitialIntervalTime =
|
|
|
+ ConfigSpUtils().getConfig()?.interstitialIntervalTime
|
|
|
+ val maxTime = interstitialIntervalTime ?: 30
|
|
|
+// LogUtils.e("DFDFDFDFDFDFDF===$inAdTime")
|
|
|
+ if (inAdTime == maxTime) {
|
|
|
interstitialAd?.load()
|
|
|
job1?.cancel()
|
|
|
scope1?.cancel()
|
|
|
@@ -313,6 +341,12 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
private fun initNativeTime() {
|
|
|
+
|
|
|
+ val canAllowAutoRefresh =
|
|
|
+ ConfigSpUtils().getConfig()?.canAllowAutoRefresh
|
|
|
+
|
|
|
+ if (canAllowAutoRefresh == 0) return
|
|
|
+
|
|
|
if (job2 == null) {
|
|
|
job2 = Job()
|
|
|
}
|
|
|
@@ -321,18 +355,17 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
scope2 = CoroutineScope(Dispatchers.Main + job2!!)
|
|
|
}
|
|
|
|
|
|
- scope2!!.launch {
|
|
|
+ scope2?.launch {
|
|
|
while (isActive) {
|
|
|
nativeAdTime++
|
|
|
- if (nativeAdTime == 40) {
|
|
|
-
|
|
|
+ val flowIntervalTime =
|
|
|
+ ConfigSpUtils().getConfig()?.flowIntervalTime
|
|
|
+ val maxTime = flowIntervalTime ?: 30
|
|
|
+ if (nativeAdTime >= maxTime) {
|
|
|
if (atNative?.checkAdStatus()?.isLoading == false) {
|
|
|
- atNative?.makeAdRequest()
|
|
|
+ atNative = null
|
|
|
+ loadNativeAd()
|
|
|
}
|
|
|
- job2?.cancel()
|
|
|
- scope2?.cancel()
|
|
|
- job2 = null
|
|
|
- scope2 = null
|
|
|
nativeAdTime = 0
|
|
|
}
|
|
|
delay(1000)
|
|
|
@@ -340,10 +373,33 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 暂停计时任务
|
|
|
+ */
|
|
|
+ private fun pauseNativeTime() {
|
|
|
+ job2?.cancel()
|
|
|
+ job2 = null
|
|
|
+ scope2 = null
|
|
|
+ isNativeAdPaunse = true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动控制开始/继续计时任务
|
|
|
+ * 调用此方法会继续之前的计时进度
|
|
|
+ */
|
|
|
+ private fun startOrResumeNativeTime() {
|
|
|
+ if (isNativeAdPaunse) {
|
|
|
+ initNativeTime()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun onPause() {
|
|
|
super.onPause()
|
|
|
this.isInAdPaunse = true
|
|
|
this.pauseGetTlShowBtnTime = true
|
|
|
+ pauseNativeTime()
|
|
|
+ this.getTlCountDownTimer?.cancel()
|
|
|
+ this.getTlCountDownTimer = null
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
@@ -351,6 +407,12 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
this.isInAdPaunse = false
|
|
|
this.pauseGetTlShowBtnTime = false
|
|
|
getUserInfo()
|
|
|
+ startOrResumeNativeTime()
|
|
|
+ startGetTlTime()
|
|
|
+ getTlCountDownTimer?.start()
|
|
|
+ if (this.isNativeClick){
|
|
|
+ loadNativeAd()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private fun initDialogGetTl() {
|
|
|
@@ -369,7 +431,11 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
private fun answer(questionId: String, itemId: String) {
|
|
|
-
|
|
|
+ var url = if (Constants.isDebug) {
|
|
|
+ Constants.ANSWER_QUESTION
|
|
|
+ } else {
|
|
|
+ Constants.FULL_URL_V2 + Constants.ANSWER_QUESTION
|
|
|
+ }
|
|
|
val map = HashMap<String, Any>()
|
|
|
map["duration"] = useTimer
|
|
|
map["itemId"] = itemId
|
|
|
@@ -377,13 +443,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
map["userId"] = UserInfoSpUtils().getUserId()
|
|
|
|
|
|
val requestBody = BaseRetrofit.getRequestBodyByMapToJson(map)
|
|
|
-
|
|
|
- var url = if (Constants.isDebug) {
|
|
|
- Constants.ANSWER_QUESTION
|
|
|
- } else {
|
|
|
- Constants.FULL_URL_V2 + Constants.ANSWER_QUESTION
|
|
|
- }
|
|
|
-
|
|
|
BaseRetrofit.getInstance().apiService.answerQuestion(url, requestBody)
|
|
|
.enqueue(object : Callback2<Any>() {
|
|
|
override fun success(body: Any?) {
|
|
|
@@ -412,7 +471,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
useTimer = 0
|
|
|
}
|
|
|
|
|
|
- override fun fail(msg: String?) {
|
|
|
+ override fun fail(code: Int, msg: String?) {
|
|
|
ToastUtils
|
|
|
.make()
|
|
|
.setMode(MODE.DARK)
|
|
|
@@ -431,7 +490,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
} else {
|
|
|
Constants.FULL_URL_V2 + Constants.ADD_POWER
|
|
|
}
|
|
|
-
|
|
|
val userId = UserInfoSpUtils().getUserId()
|
|
|
BaseRetrofit.getInstance().apiService.addPower(url, userId)
|
|
|
.enqueue(object : Callback2<Any>() {
|
|
|
@@ -449,7 +507,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
initGetTlTime()
|
|
|
}
|
|
|
|
|
|
- override fun fail(msg: String?) {
|
|
|
+ override fun fail(code: Int, msg: String?) {
|
|
|
ToastUtils
|
|
|
.make()
|
|
|
.setMode(MODE.DARK)
|
|
|
@@ -464,7 +522,10 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
private fun initGetTlTime() {
|
|
|
binding.zz.visibility = View.VISIBLE
|
|
|
- getTlTime = 30
|
|
|
+
|
|
|
+ val powerWaitTime = ConfigSpUtils().getConfig()?.powerWaitTime
|
|
|
+ val maxTime = powerWaitTime ?: 30
|
|
|
+ getTlTime = maxTime
|
|
|
binding.zz.text = "${getTlTime}s"
|
|
|
getTlCountDownTimer?.start()
|
|
|
}
|
|
|
@@ -538,7 +599,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- this.getTlTime = 30
|
|
|
getTlCountDownTimer = object : CountDownTimer((getTlTime * 1000).toLong(), 1000) {
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
override fun onTick(millisUntilFinished: Long) {
|
|
|
@@ -567,7 +627,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
override fun onFinish() {
|
|
|
- ToastUtils.showShort("非法操作,请30秒后重新获取!")
|
|
|
+ ToastUtils.showShort("未响应,请15分钟以后再试如果还不行,请联系任务客服。")
|
|
|
if (loadDialog?.isShowing == true) loadDialog?.dismiss()
|
|
|
}
|
|
|
}
|
|
|
@@ -616,7 +676,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
changeLever()
|
|
|
}
|
|
|
|
|
|
- override fun fail(msg: String?) {
|
|
|
+ override fun fail(code: Int, msg: String?) {
|
|
|
ToastUtils
|
|
|
.make()
|
|
|
.setMode(MODE.DARK)
|
|
|
@@ -679,15 +739,13 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
user.todayAnswerCount = jrdd
|
|
|
user.historyAnswerCount = lsdd
|
|
|
UserInfoSpUtils().changeValue(user)
|
|
|
-
|
|
|
- binding.jrddTv.text = "今日答题: ${jrdd}题"
|
|
|
+ val _jrddTv = resources.getString(R.string.today_answer_count)
|
|
|
+ binding.jrddTv.text = String.format(_jrddTv, jrdd.toString())
|
|
|
binding.lsddTv.text = "历史答题: ${lsdd}题"
|
|
|
|
|
|
val questionId = item?.questionId
|
|
|
val itemId = item?.itemList?.get(btnIndex)?.itemId
|
|
|
|
|
|
-
|
|
|
-
|
|
|
if (questionId != null && itemId != null) {
|
|
|
answer(questionId, itemId)
|
|
|
} else {
|
|
|
@@ -764,9 +822,10 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
|
|
|
private fun loadAd() {
|
|
|
if (mRewardVideoAd == null) {
|
|
|
- mRewardVideoAd = ATRewardVideoAd(context, Constants.TAKU_REWARD_PID)
|
|
|
+ val takuRewardPid =
|
|
|
+ ConfigSpUtils().getConfig()?.takuRewardPid ?: Constants.TAKU_REWARD_PID
|
|
|
+ mRewardVideoAd = ATRewardVideoAd(context, takuRewardPid)
|
|
|
}
|
|
|
-
|
|
|
val userid = UserInfoSpUtils().getUserInfo().userId
|
|
|
val userdata = UserInfoSpUtils().getUserInfo().nickName
|
|
|
val localMap: MutableMap<String, Any> = HashMap()
|
|
|
@@ -780,6 +839,9 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
private var isReload = false
|
|
|
|
|
|
private fun showAd() {
|
|
|
+// if (interstitialAd?.isAdReady == true) {
|
|
|
+// interstitialAd?.show(activity, getATShowConfig1())
|
|
|
+// }
|
|
|
if (mRewardVideoAd?.isAdReady == true) {
|
|
|
mRewardVideoAd?.show(activity)
|
|
|
return
|
|
|
@@ -788,6 +850,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
// 在 Fragment 中使用
|
|
|
if (isAdded && activity != null && !requireActivity().isFinishing) {
|
|
|
loadDialog = LoadingDialog(activity)
|
|
|
+
|
|
|
loadDialog?.show()
|
|
|
startReloadRewardVideoAd()
|
|
|
startReloadRewardVideoAd?.start()
|
|
|
@@ -800,7 +863,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
private var isRewardedVideoFinish = false
|
|
|
|
|
|
override fun onRewardedVideoAdLoaded() {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdLoaded")
|
|
|
startReloadRewardVideoAd?.cancel()
|
|
|
startReloadRewardVideoAd = null
|
|
|
if (loadDialog?.isShowing == true) loadDialog?.dismiss()
|
|
|
@@ -808,7 +870,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdFailed(p0: AdError?) {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdFailed${p0?.code}")
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdPlayStart(p0: ATAdInfo?) {
|
|
|
@@ -823,20 +884,16 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
mRewardVideoAd?.load()
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdPlayStart${p0.toString()}")
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdPlayEnd(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdPlayEnd${p0.toString()}")
|
|
|
isRewardedVideoFinish = true
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdPlayFailed(p0: AdError?, p1: ATAdInfo?) {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdPlayFailed${p0?.code}===${p1.toString()}")
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdClosed(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdClosed${p0.toString()}")
|
|
|
loadBannerAd()
|
|
|
loadNativeAd()
|
|
|
if (!isRewardedVideoFinish) {
|
|
|
@@ -845,7 +902,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
override fun onRewardedVideoAdPlayClicked(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("DFDFDF=onRewardedVideoAdPlayClicked${p0.toString()}")
|
|
|
}
|
|
|
|
|
|
override fun onReward(p0: ATAdInfo?) {
|
|
|
@@ -881,117 +937,138 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
map["adSourceIndex"] = p0.adsourceIndex
|
|
|
map["adSourceType"] = p0.adSourceAdType
|
|
|
map["resultJson"] = p0.toString()
|
|
|
+ map["appId"] = UserInfoSpUtils().getAppid()
|
|
|
|
|
|
val body = BaseRetrofit.getRequestBodyByMapToJson(map)
|
|
|
+
|
|
|
var url = if (Constants.isDebug) {
|
|
|
Constants.SAVE_RECORD
|
|
|
} else {
|
|
|
Constants.FULL_URL_V2 + Constants.SAVE_RECORD
|
|
|
}
|
|
|
+
|
|
|
BaseRetrofit.getInstance().apiService.saveRecord(url, body)
|
|
|
.enqueue(object : Callback2<Any>() {
|
|
|
override fun success(body: Any?) {
|
|
|
+// LogUtils.e("====dfdfdfdfdf${p0.adSourceAdType}")
|
|
|
if (p0.adSourceAdType == 1) addPower()
|
|
|
- LogUtils.e("dfdfdfdf广告同步成功!")
|
|
|
}
|
|
|
|
|
|
- override fun fail(msg: String?) {
|
|
|
+ override fun fail(code: Int, msg: String?) {
|
|
|
+ //766达到上限
|
|
|
+ LogUtils.e("dfdfdfdfdfdf${code}===${msg}")
|
|
|
+ if (code == 766 || code == 767) {
|
|
|
+ ToastUtils.showShort(msg)
|
|
|
+ getUserInfo()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
ToastUtils.showShort(msg)
|
|
|
+
|
|
|
+ if (code == 301) {
|
|
|
+ ActivityUtils.startActivity(LoginActivity::class.java)
|
|
|
+ ActivityUtils.finishAllActivities()
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
private fun loadNativeAd() {
|
|
|
if (atNative == null) {
|
|
|
- atNative =
|
|
|
- ATNative(context, Constants.TAKU_NATIVE_PID, object : ATNativeNetworkListener {
|
|
|
- override fun onNativeAdLoaded() {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- val current = LocalDateTime.now()
|
|
|
- val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
- startNativeAdTime = current.format(formatter)
|
|
|
- } else {
|
|
|
- startNativeAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
- }
|
|
|
- val nativeAd: NativeAd? = atNative?.getNativeAd(getATShowConfig())
|
|
|
- nativeAd?.setNativeEventListener(object : ATNativeEventListener {
|
|
|
- override fun onAdImpressed(
|
|
|
- p0: ATNativeAdView?,
|
|
|
- p1: ATAdInfo?
|
|
|
- ) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- val current = LocalDateTime.now()
|
|
|
- val formatter =
|
|
|
- DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
- endNativeAdTime = current.format(formatter)
|
|
|
- } else {
|
|
|
- endNativeAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
- }
|
|
|
- saveRecord(
|
|
|
- p1,
|
|
|
- startNativeAdTime.toString(),
|
|
|
- endNativeAdTime.toString()
|
|
|
- )
|
|
|
-// reloadNativeAd()
|
|
|
- LogUtils.e("dfdfdfdfonAdImpressed${p1.toString()}")
|
|
|
+ val takuNativePid =
|
|
|
+ ConfigSpUtils().getConfig()?.takuNativePid ?: Constants.TAKU_NATIVE_PID
|
|
|
+ atNative = ATNative(context, takuNativePid, object : ATNativeNetworkListener {
|
|
|
+ override fun onNativeAdLoaded() {
|
|
|
+ isNativeClick = false
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ val current = LocalDateTime.now()
|
|
|
+ val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
+ startNativeAdTime = current.format(formatter)
|
|
|
+ } else {
|
|
|
+ startNativeAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
+ }
|
|
|
+ val nativeAd: NativeAd? = atNative?.getNativeAd(getATShowConfig())
|
|
|
+ nativeAd?.setNativeEventListener(object : ATNativeEventListener {
|
|
|
+ override fun onAdImpressed(
|
|
|
+ p0: ATNativeAdView?,
|
|
|
+ p1: ATAdInfo?
|
|
|
+ ) {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ val current = LocalDateTime.now()
|
|
|
+ val formatter =
|
|
|
+ DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
+ endNativeAdTime = current.format(formatter)
|
|
|
+ } else {
|
|
|
+ endNativeAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
}
|
|
|
+ saveRecord(
|
|
|
+ p1,
|
|
|
+ startNativeAdTime.toString(),
|
|
|
+ endNativeAdTime.toString()
|
|
|
+ )
|
|
|
+// reloadNativeAd()
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdClicked(
|
|
|
- p0: ATNativeAdView?,
|
|
|
- p1: ATAdInfo?
|
|
|
- ) {
|
|
|
- LogUtils.e("dfdfdfdfonAdImpressed${p1.toString()}")
|
|
|
- }
|
|
|
+ override fun onAdClicked(
|
|
|
+ p0: ATNativeAdView?,
|
|
|
+ p1: ATAdInfo?
|
|
|
+ ) {
|
|
|
+ isNativeClick = true
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdVideoStart(p0: ATNativeAdView?) {
|
|
|
+ override fun onAdVideoStart(p0: ATNativeAdView?) {
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdVideoEnd(p0: ATNativeAdView?) {
|
|
|
- }
|
|
|
+ override fun onAdVideoEnd(p0: ATNativeAdView?) {
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdVideoProgress(
|
|
|
- p0: ATNativeAdView?,
|
|
|
- p1: Int
|
|
|
- ) {
|
|
|
- LogUtils.e("dfdfdfdfonAdVideoProgress}")
|
|
|
+ override fun onAdVideoProgress(
|
|
|
+ p0: ATNativeAdView?,
|
|
|
+ p1: Int
|
|
|
+ ) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ if (nativeAd?.isNativeExpress != true) {
|
|
|
+ var nativePrepareInfo = ATNativePrepareInfo()
|
|
|
+ nativeAd?.adMaterial?.let {
|
|
|
+ mSelfRenderView?.let { selfRenderView ->
|
|
|
+ bindSelfRenderView(
|
|
|
+ requireActivity(), it, selfRenderView,
|
|
|
+ nativePrepareInfo
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- })
|
|
|
- try {
|
|
|
- nativeAd?.renderAdContainer(binding.fragmentDatiContentAd, null)
|
|
|
- } catch (e: Exception) {
|
|
|
- e.printStackTrace()
|
|
|
+ nativeAd?.renderAdContainer(
|
|
|
+ binding.fragmentDatiContentAd,
|
|
|
+ mSelfRenderView
|
|
|
+ )
|
|
|
+ binding.selfview.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ nativeAd.renderAdContainer(binding.fragmentDatiContentAd, null)
|
|
|
+ binding.fragmentDatiContentAd.visibility = View.VISIBLE
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- override fun onNativeAdLoadFail(adError: AdError) {
|
|
|
- LogUtils.e("onNativeAdLoadFail:" + adError.fullErrorInfo)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
atNative = null
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onNativeAdLoadFail(adError: AdError) {
|
|
|
+ atNative = null
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
binding.fragmentDatiContentAd.removeAllViews()
|
|
|
- val userid = UserInfoSpUtils().getUserInfo().userId
|
|
|
- val userdata = UserInfoSpUtils().getUserInfo().nickName
|
|
|
- val localMap: MutableMap<String, Any> = HashMap()
|
|
|
- localMap[ATAdConst.KEY.USER_ID] = userid
|
|
|
- localMap[ATAdConst.KEY.USER_CUSTOM_DATA] = userdata
|
|
|
- atNative?.setLocalExtra(localMap)
|
|
|
if (atNative?.checkAdStatus()?.isLoading == false) atNative?.makeAdRequest()
|
|
|
}
|
|
|
|
|
|
private fun loadInterstitial() {
|
|
|
-
|
|
|
- interstitialAd = ATInterstitial(context, Constants.TAKU_INTERSTITIAL_PID)
|
|
|
-
|
|
|
- val userid = UserInfoSpUtils().getUserInfo().userId
|
|
|
- val userdata = UserInfoSpUtils().getUserInfo().nickName
|
|
|
- val localMap: MutableMap<String, Any> = HashMap()
|
|
|
- localMap[ATAdConst.KEY.USER_ID] = userid
|
|
|
- localMap[ATAdConst.KEY.USER_CUSTOM_DATA] = userdata
|
|
|
- interstitialAd?.setLocalExtra(localMap)
|
|
|
+ val takuInterstitialPid =
|
|
|
+ ConfigSpUtils().getConfig()?.takuInterstitialPid ?: Constants.TAKU_INTERSTITIAL_PID
|
|
|
+ interstitialAd = ATInterstitial(context, takuInterstitialPid)
|
|
|
interstitialAd?.setNativeAdCustomRender { mixNativeAd, atAdInfo ->
|
|
|
MediationNativeAdUtil.getViewFromNativeAd(
|
|
|
context,
|
|
|
@@ -1002,7 +1079,7 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
interstitialAd?.setAdListener(object : ATInterstitialListener {
|
|
|
override fun onInterstitialAdLoaded() {
|
|
|
- LogUtils.e("==========onInterstitialAdLoaded")
|
|
|
+
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
val current = LocalDateTime.now()
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
@@ -1010,17 +1087,15 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
} else {
|
|
|
startInAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
}
|
|
|
- interstitialAd?.show(activity, getATShowConfig1())
|
|
|
|
|
|
+ interstitialAd?.show(activity, getATShowConfig1())
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdLoadFail(p0: AdError?) {
|
|
|
- LogUtils.e("===========onInterstitialAdLoadFail")
|
|
|
- initInAdTime()
|
|
|
+// initInAdTime()
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdClicked(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("===========onInterstitialAdClicked")
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdShow(p0: ATAdInfo?) {
|
|
|
@@ -1033,7 +1108,6 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
saveRecord(p0, startInAdTime.toString(), endInAdTime.toString())
|
|
|
- LogUtils.e("=============onInterstitialAdShow${p0.toString()}")
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdClose(p0: ATAdInfo?) {
|
|
|
@@ -1041,15 +1115,12 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdVideoStart(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("===========onInterstitialAdVideoStart")
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdVideoEnd(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("==============onInterstitialAdVideoEnd")
|
|
|
}
|
|
|
|
|
|
override fun onInterstitialAdVideoError(p0: AdError?) {
|
|
|
- LogUtils.e("==========onInterstitialAdVideoError")
|
|
|
}
|
|
|
|
|
|
})
|
|
|
@@ -1059,19 +1130,14 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
|
|
|
private fun loadBannerAd() {
|
|
|
|
|
|
+ val takuBannerPid = ConfigSpUtils().getConfig()?.takuBannerPid ?: Constants.TAKU_BANNER_PID
|
|
|
mBannerView = ATBannerView(context)
|
|
|
- mBannerView?.setPlacementId(Constants.TAKU_BANNER_PID)
|
|
|
+ mBannerView?.setPlacementId(takuBannerPid)
|
|
|
mBannerView?.setShowConfig(getATShowConfig())
|
|
|
mBannerView?.setBannerAdListener(this)
|
|
|
binding.fragmentDatiBanner.removeAllViews()
|
|
|
binding.fragmentDatiBanner.addView(mBannerView)
|
|
|
|
|
|
- val userid = UserInfoSpUtils().getUserInfo().userId
|
|
|
- val userdata = UserInfoSpUtils().getUserInfo().nickName
|
|
|
- val localMap: MutableMap<String, Any> = HashMap()
|
|
|
- localMap[ATAdConst.KEY.USER_ID] = userid
|
|
|
- localMap[ATAdConst.KEY.USER_CUSTOM_DATA] = userdata
|
|
|
- mBannerView?.setLocalExtra(localMap)
|
|
|
if (mBannerView?.checkAdStatus()?.isLoading == false) mBannerView?.loadAd()
|
|
|
}
|
|
|
|
|
|
@@ -1100,19 +1166,15 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
startBannerAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
}
|
|
|
|
|
|
- LogUtils.e("dfdfdf onBannerLoaded")
|
|
|
}
|
|
|
|
|
|
override fun onBannerFailed(p0: AdError?) {
|
|
|
- LogUtils.e("dfdfdf onBannerFailed")
|
|
|
}
|
|
|
|
|
|
override fun onBannerClicked(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("dfdfdf onBannerClicked")
|
|
|
}
|
|
|
|
|
|
override fun onBannerShow(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("dfdfdf onBannerShow${p0.toString()}")
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
val current = LocalDateTime.now()
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
@@ -1121,19 +1183,30 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
endBannerAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
}
|
|
|
saveRecord(p0, startBannerAdTime.toString(), endBannerAdTime.toString())
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun onBannerClose(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("dfdfdf onBannerClose")
|
|
|
}
|
|
|
|
|
|
override fun onBannerAutoRefreshed(p0: ATAdInfo?) {
|
|
|
- LogUtils.e("dfdfdf onBannerAutoRefreshed")
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ val current = LocalDateTime.now()
|
|
|
+ val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
+ startBannerAdTime = current.format(formatter)
|
|
|
+ } else {
|
|
|
+ startBannerAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ val current = LocalDateTime.now()
|
|
|
+ val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
+ endBannerAdTime = current.format(formatter)
|
|
|
+ } else {
|
|
|
+ endBannerAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
+ }
|
|
|
+ saveRecord(p0, startBannerAdTime.toString(), endBannerAdTime.toString())
|
|
|
}
|
|
|
|
|
|
override fun onBannerAutoRefreshFail(p0: AdError?) {
|
|
|
- LogUtils.e("dfdfdf onBannerAutoRefreshFail")
|
|
|
}
|
|
|
|
|
|
private fun getUserInfo() {
|
|
|
@@ -1151,12 +1224,240 @@ class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
|
|
|
binding.jrddTv.text = "今日答题: ${jrdd}题"
|
|
|
binding.lsddTv.text = "历史答题: ${lsdd}题"
|
|
|
+
|
|
|
initDialogGetTl()
|
|
|
+
|
|
|
+ binding.dialotGettlBtnTx.text =
|
|
|
+ if (UserInfoSpUtils().ifPowerLimit()) "今日已达上限" else "获取体力"
|
|
|
}
|
|
|
|
|
|
- override fun fail(msg: String?) {
|
|
|
+ override fun fail(code: Int, msg: String?) {
|
|
|
ToastUtils.showShort(msg)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ @SuppressLint("RtlHardcoded")
|
|
|
+ private fun bindSelfRenderView(
|
|
|
+ context: Context, adMaterial: ATNativeMaterial,
|
|
|
+ selfRenderView: View,
|
|
|
+ nativePrepareInfo: ATNativePrepareInfo
|
|
|
+ ) {
|
|
|
+
|
|
|
+ val padding: Int = dip2px(context, 5.toFloat())
|
|
|
+ selfRenderView.setPadding(padding, padding, padding, padding)
|
|
|
+ val titleView: TextView = selfRenderView.findViewById(R.id.native_ad_title)
|
|
|
+ val descView: TextView = selfRenderView.findViewById(R.id.native_ad_desc)
|
|
|
+ val ctaView: TextView = selfRenderView.findViewById(R.id.native_ad_install_btn)
|
|
|
+ val adFromView: TextView = selfRenderView.findViewById(R.id.native_ad_from)
|
|
|
+ val iconArea: FrameLayout = selfRenderView.findViewById(R.id.native_ad_image)
|
|
|
+ val contentArea: FrameLayout =
|
|
|
+ selfRenderView.findViewById(R.id.native_ad_content_image_area)
|
|
|
+ val logoView: ATNativeImageView =
|
|
|
+ selfRenderView.findViewById(R.id.native_ad_logo)
|
|
|
+ val closeView: View? = selfRenderView.findViewById(R.id.native_ad_close)
|
|
|
+ val shakeViewContainer: FrameLayout? =
|
|
|
+ selfRenderView.findViewById(R.id.native_ad_shake_view_container)
|
|
|
+ val slideViewContainer: FrameLayout? =
|
|
|
+ selfRenderView.findViewById(R.id.native_ad_slide_view_container)
|
|
|
+ val adLogoContainer: FrameLayout =
|
|
|
+ selfRenderView.findViewById(R.id.native_ad_logo_container)
|
|
|
+
|
|
|
+ //click views
|
|
|
+ val clickViewList = arrayListOf<View>()
|
|
|
+ val title = adMaterial.title
|
|
|
+
|
|
|
+ // title
|
|
|
+ if (!TextUtils.isEmpty(title)) {
|
|
|
+ titleView.text = title
|
|
|
+ nativePrepareInfo.setTitleView(titleView) //bind title
|
|
|
+ clickViewList.add(titleView)
|
|
|
+ titleView.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ titleView.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ // desc
|
|
|
+ val descriptionText = adMaterial.descriptionText
|
|
|
+ if (!TextUtils.isEmpty(descriptionText)) {
|
|
|
+ descView.text = descriptionText
|
|
|
+ nativePrepareInfo.setDescView(descView) //bind desc
|
|
|
+ clickViewList.add(descView)
|
|
|
+ descView.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ descView.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ // icon
|
|
|
+ val adIconView = adMaterial.adIconView
|
|
|
+ val iconImageUrl = adMaterial.iconImageUrl
|
|
|
+ iconArea.removeAllViews()
|
|
|
+ val iconView: ATNativeImageView = ATNativeImageView(context)
|
|
|
+ if (adIconView != null) {
|
|
|
+ iconArea.addView(adIconView)
|
|
|
+ nativePrepareInfo.setIconView(adIconView) //bind icon
|
|
|
+ clickViewList.add(adIconView)
|
|
|
+ iconArea.visibility = View.VISIBLE
|
|
|
+ } else if (!TextUtils.isEmpty(iconImageUrl)) {
|
|
|
+ iconArea.addView(iconView)
|
|
|
+ iconView.setImage(iconImageUrl)
|
|
|
+ nativePrepareInfo.setIconView(iconView) //bind icon
|
|
|
+ clickViewList.add(iconView)
|
|
|
+ iconArea.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ iconArea.visibility = View.INVISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ // cta button
|
|
|
+ val callToActionText = adMaterial.callToActionText
|
|
|
+ if (!TextUtils.isEmpty(callToActionText)) {
|
|
|
+ ctaView.text = callToActionText
|
|
|
+ nativePrepareInfo.setCtaView(ctaView) //bind cta button
|
|
|
+ clickViewList.add(ctaView)
|
|
|
+ ctaView.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ ctaView.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ // media view
|
|
|
+ val mediaView = adMaterial.getAdMediaView(contentArea)
|
|
|
+ val imageList = adMaterial.imageUrlList
|
|
|
+
|
|
|
+
|
|
|
+ //some network support return main image width、height,if not support return -1
|
|
|
+ val mainImageHeight = adMaterial.mainImageHeight
|
|
|
+ val mainImageWidth = adMaterial.mainImageWidth
|
|
|
+ val realMainImageWidth: Int =
|
|
|
+ context.resources.displayMetrics.widthPixels - dip2px(
|
|
|
+ context, 10.toFloat()
|
|
|
+ )
|
|
|
+ var realMainHeight = 0
|
|
|
+
|
|
|
+ //media view or mainImage layout params
|
|
|
+ val mainImageParam: FrameLayout.LayoutParams = LayoutParams(
|
|
|
+ FrameLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ FrameLayout.LayoutParams.WRAP_CONTENT
|
|
|
+ )
|
|
|
+ if (mainImageWidth > 0 && mainImageHeight > 0 && mainImageWidth > mainImageHeight) {
|
|
|
+ realMainHeight = realMainImageWidth * mainImageHeight / mainImageWidth
|
|
|
+ mainImageParam.width = realMainImageWidth
|
|
|
+ mainImageParam.height = realMainHeight
|
|
|
+ } else {
|
|
|
+ mainImageParam.width = FrameLayout.LayoutParams.MATCH_PARENT
|
|
|
+ //contentArea radio
|
|
|
+ mainImageParam.height = realMainImageWidth * 600 / 1024
|
|
|
+ }
|
|
|
+ contentArea.removeAllViews()
|
|
|
+ if (mediaView != null) {
|
|
|
+ if (mediaView.parent != null) {
|
|
|
+ (mediaView.parent as ViewGroup).removeView(mediaView)
|
|
|
+ }
|
|
|
+ mainImageParam.gravity = Gravity.CENTER
|
|
|
+ mediaView.setLayoutParams(mainImageParam)
|
|
|
+ contentArea.addView(mediaView, mainImageParam)
|
|
|
+ contentArea.setVisibility(View.VISIBLE)
|
|
|
+ } else if (imageList != null && imageList.size > 1) {
|
|
|
+ val mutiImageView: MutiImageView = MutiImageView(context)
|
|
|
+ mutiImageView.setImageList(imageList, mainImageWidth, mainImageHeight)
|
|
|
+ nativePrepareInfo.setMainImageView(mutiImageView) //bind main image
|
|
|
+ contentArea.addView(
|
|
|
+ mutiImageView,
|
|
|
+ LayoutParams(
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+ ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
+ )
|
|
|
+ )
|
|
|
+ clickViewList.add(mutiImageView)
|
|
|
+ contentArea.visibility = View.VISIBLE
|
|
|
+ } else if (!TextUtils.isEmpty(adMaterial.mainImageUrl)) {
|
|
|
+ val imageView: ATNativeImageView = ATNativeImageView(context)
|
|
|
+ imageView.setImage(adMaterial.mainImageUrl)
|
|
|
+ imageView.setLayoutParams(mainImageParam)
|
|
|
+ contentArea.addView(imageView, mainImageParam)
|
|
|
+ nativePrepareInfo.setMainImageView(imageView) //bind main image
|
|
|
+ clickViewList.add(imageView)
|
|
|
+ contentArea.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ contentArea.removeAllViews()
|
|
|
+ contentArea.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ //Ad Logo
|
|
|
+ val adLogoView = adMaterial.adLogoView
|
|
|
+ if (adLogoView != null) {
|
|
|
+ adLogoContainer.visibility = View.VISIBLE
|
|
|
+ adLogoContainer.removeAllViews()
|
|
|
+ adLogoContainer.addView(adLogoView)
|
|
|
+ } else {
|
|
|
+ adLogoContainer.visibility = View.GONE
|
|
|
+ val adChoiceIconUrl = adMaterial.adChoiceIconUrl
|
|
|
+ val adLogoBitmap: Bitmap? = adMaterial.adLogo
|
|
|
+ if (!TextUtils.isEmpty(adChoiceIconUrl)) {
|
|
|
+ logoView.setImage(adChoiceIconUrl)
|
|
|
+ logoView.setVisibility(View.VISIBLE)
|
|
|
+ nativePrepareInfo.setAdLogoView(logoView) //bind ad choice
|
|
|
+ } else if (adLogoBitmap != null) {
|
|
|
+ logoView.setImageBitmap(adLogoBitmap)
|
|
|
+ logoView.setVisibility(View.VISIBLE)
|
|
|
+ nativePrepareInfo.setAdLogoView(logoView) //bind ad choice
|
|
|
+ } else {
|
|
|
+ logoView.setImageBitmap(null)
|
|
|
+ logoView.setVisibility(View.GONE)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //bind layout params for ad choice
|
|
|
+ val layoutParams: FrameLayout.LayoutParams = LayoutParams(
|
|
|
+ dip2px(context, 40.toFloat()),
|
|
|
+ dip2px(context, 10.toFloat())
|
|
|
+ ) //ad choice
|
|
|
+ layoutParams.gravity = Gravity.BOTTOM or Gravity.RIGHT
|
|
|
+ nativePrepareInfo.setChoiceViewLayoutParams(layoutParams)
|
|
|
+
|
|
|
+ // ad from
|
|
|
+ val adFrom = adMaterial.adFrom
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(adFrom)) {
|
|
|
+ adFromView.text = adFrom
|
|
|
+ adFromView.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ adFromView.visibility = View.GONE
|
|
|
+ }
|
|
|
+ nativePrepareInfo.setAdFromView(adFromView) //bind ad from
|
|
|
+ nativePrepareInfo.setCloseView(closeView) //bind close button
|
|
|
+
|
|
|
+ val domainView: TextView = selfRenderView.findViewById(R.id.native_ad_domain)
|
|
|
+ val warningView: TextView = selfRenderView.findViewById(R.id.native_ad_warning)
|
|
|
+
|
|
|
+ //Yandex require render domain
|
|
|
+ val domain = adMaterial.domain
|
|
|
+ if (!TextUtils.isEmpty(domain)) {
|
|
|
+ domainView.visibility = View.VISIBLE
|
|
|
+ domainView.text = domain
|
|
|
+ clickViewList.add(domainView)
|
|
|
+ nativePrepareInfo.domainView = domainView
|
|
|
+ } else {
|
|
|
+ domainView.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ //Yandex require render warning
|
|
|
+ val warning = adMaterial.warning
|
|
|
+ if (!TextUtils.isEmpty(warning)) {
|
|
|
+ warningView.visibility = View.VISIBLE
|
|
|
+ warningView.text = warning
|
|
|
+ clickViewList.add(warningView)
|
|
|
+ nativePrepareInfo.warningView = warningView
|
|
|
+ } else {
|
|
|
+ warningView.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ nativePrepareInfo.clickViewList = clickViewList //bind click view list
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ fun dip2px(context: Context, dipValue: Float): Int {
|
|
|
+ val scale = context.resources.displayMetrics.density
|
|
|
+ return (dipValue * scale + 0.5f).toInt()
|
|
|
+ }
|
|
|
}
|