|
@@ -10,7 +10,19 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
-import com.blankj.utilcode.util.GsonUtils
|
|
|
|
|
|
|
+import com.anythink.banner.api.ATBannerListener
|
|
|
|
|
+import com.anythink.banner.api.ATBannerView
|
|
|
|
|
+import com.anythink.core.api.ATAdConst
|
|
|
|
|
+import com.anythink.core.api.ATAdInfo
|
|
|
|
|
+import com.anythink.core.api.ATShowConfig
|
|
|
|
|
+import com.anythink.core.api.AdError
|
|
|
|
|
+import com.anythink.interstitial.api.ATInterstitial
|
|
|
|
|
+import com.anythink.interstitial.api.ATInterstitialListener
|
|
|
|
|
+import com.anythink.nativead.api.ATNative
|
|
|
|
|
+import com.anythink.nativead.api.ATNativeNetworkListener
|
|
|
|
|
+import com.anythink.nativead.api.NativeAd
|
|
|
|
|
+import com.anythink.rewardvideo.api.ATRewardVideoAd
|
|
|
|
|
+import com.anythink.rewardvideo.api.ATRewardVideoListener
|
|
|
import com.blankj.utilcode.util.LogUtils
|
|
import com.blankj.utilcode.util.LogUtils
|
|
|
import com.blankj.utilcode.util.ToastUtils
|
|
import com.blankj.utilcode.util.ToastUtils
|
|
|
import com.blankj.utilcode.util.ToastUtils.MODE
|
|
import com.blankj.utilcode.util.ToastUtils.MODE
|
|
@@ -20,10 +32,14 @@ import com.ytpm.hydtw.adapter.MineAdapter
|
|
|
import com.ytpm.hydtw.dao.Question
|
|
import com.ytpm.hydtw.dao.Question
|
|
|
import com.ytpm.hydtw.dao.Record
|
|
import com.ytpm.hydtw.dao.Record
|
|
|
import com.ytpm.hydtw.databinding.FragmentDatiBinding
|
|
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.BaseRetrofit
|
|
|
import com.ytpm.hydtw.network.Callback2
|
|
import com.ytpm.hydtw.network.Callback2
|
|
|
import com.ytpm.hydtw.utils.DateTimeConverter
|
|
import com.ytpm.hydtw.utils.DateTimeConverter
|
|
|
|
|
+import com.ytpm.hydtw.utils.DateTimeUtils
|
|
|
import com.ytpm.hydtw.utils.GlideUtils
|
|
import com.ytpm.hydtw.utils.GlideUtils
|
|
|
|
|
+import com.ytpm.hydtw.utils.MediationNativeAdUtil
|
|
|
import com.ytpm.hydtw.utils.UserInfoSpUtils
|
|
import com.ytpm.hydtw.utils.UserInfoSpUtils
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
@@ -34,13 +50,28 @@ import kotlinx.coroutines.cancel
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.isActive
|
|
import kotlinx.coroutines.isActive
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
-
|
|
|
|
|
-class DatiFragment : Fragment() {
|
|
|
|
|
-
|
|
|
|
|
- private var job:Job? = null
|
|
|
|
|
- private var scope:CoroutineScope? = null
|
|
|
|
|
|
|
+import java.time.Instant
|
|
|
|
|
+import java.time.LocalDateTime
|
|
|
|
|
+import java.time.ZoneId
|
|
|
|
|
+import java.time.format.DateTimeFormatter
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class DatiFragment() : Fragment(), ATRewardVideoListener,
|
|
|
|
|
+ ATBannerListener {
|
|
|
|
|
+
|
|
|
|
|
+ private var atNative: ATNative? = null
|
|
|
|
|
+ private var interstitialAd: ATInterstitial? = null
|
|
|
|
|
+ private var startAdTime: String? = null
|
|
|
|
|
+ private var endAdTime: String? = null
|
|
|
|
|
+ private var mRewardVideoAd: ATRewardVideoAd? = null
|
|
|
|
|
+ private var job: Job? = null
|
|
|
|
|
+ private var scope: CoroutineScope? = null
|
|
|
|
|
+ private var job1: Job? = null
|
|
|
|
|
+ private var scope1: CoroutineScope? = null
|
|
|
|
|
+ private var inAdTime: Int = 0
|
|
|
private var getTlCountDownTimer: CountDownTimer? = null
|
|
private var getTlCountDownTimer: CountDownTimer? = null
|
|
|
private var getTlShowBtnCountDownTimer: CountDownTimer? = null
|
|
private var getTlShowBtnCountDownTimer: CountDownTimer? = null
|
|
|
|
|
+ private var startReloadRewardVideoAd: CountDownTimer? = null
|
|
|
private var useTimer: Int = 0
|
|
private var useTimer: Int = 0
|
|
|
private var questions: ArrayList<Question>? = arrayListOf()
|
|
private var questions: ArrayList<Question>? = arrayListOf()
|
|
|
private lateinit var binding: FragmentDatiBinding
|
|
private lateinit var binding: FragmentDatiBinding
|
|
@@ -50,13 +81,17 @@ class DatiFragment : Fragment() {
|
|
|
private var jrdd = 0
|
|
private var jrdd = 0
|
|
|
private var lsdd = 0
|
|
private var lsdd = 0
|
|
|
|
|
|
|
|
- private var getTlTime = 30
|
|
|
|
|
- private var getTlShowBtnTime = 10
|
|
|
|
|
|
|
+ private var getTlTime = 20
|
|
|
|
|
+ private var getTlShowBtnTime = 8
|
|
|
|
|
|
|
|
private var isGrDialogShow = false
|
|
private var isGrDialogShow = false
|
|
|
private var isGetTlDialogShow = false
|
|
private var isGetTlDialogShow = false
|
|
|
|
|
|
|
|
private var isGetResult = false
|
|
private var isGetResult = false
|
|
|
|
|
+ private var isInAdPaunse = false
|
|
|
|
|
+
|
|
|
|
|
+ private var loadDialog: LoadingDialog? = null
|
|
|
|
|
+ private var loadingTime = 10
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
inflater: LayoutInflater,
|
|
@@ -69,25 +104,28 @@ class DatiFragment : Fragment() {
|
|
|
.statusBarDarkFont(true)
|
|
.statusBarDarkFont(true)
|
|
|
.titleBar(null)
|
|
.titleBar(null)
|
|
|
.init()
|
|
.init()
|
|
|
-
|
|
|
|
|
|
|
+ loadAd()
|
|
|
initData()
|
|
initData()
|
|
|
initUserTime()
|
|
initUserTime()
|
|
|
- return binding.root
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- override fun onResume() {
|
|
|
|
|
- super.onResume()
|
|
|
|
|
|
|
+ initInAdTime()
|
|
|
|
|
+ loadBannerAd()
|
|
|
|
|
+ loadNativeAd()
|
|
|
|
|
+ loadInterstitial()
|
|
|
initView()
|
|
initView()
|
|
|
useTimer = 0
|
|
useTimer = 0
|
|
|
|
|
+ return binding.root
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun initView() {
|
|
private fun initView() {
|
|
|
|
|
|
|
|
val headImg = UserInfoSpUtils().getHeadImg()
|
|
val headImg = UserInfoSpUtils().getHeadImg()
|
|
|
- context?.let {
|
|
|
|
|
- GlideUtils().circelImages(it, headImg, binding.dialogGettlHead)
|
|
|
|
|
- GlideUtils().circelImages(it, headImg, binding.fragmentDatiHead)
|
|
|
|
|
- GlideUtils().circelImages(it, headImg, binding.dialogSetHead)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (headImg.isNotEmpty()) {
|
|
|
|
|
+ context?.let {
|
|
|
|
|
+ GlideUtils().circelImages(it, headImg, binding.dialogGettlHead)
|
|
|
|
|
+ GlideUtils().circelImages(it, headImg, binding.fragmentDatiHead)
|
|
|
|
|
+ GlideUtils().circelImages(it, headImg, binding.dialogSetHead)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
val registerTime = UserInfoSpUtils().getRegistryTime()
|
|
val registerTime = UserInfoSpUtils().getRegistryTime()
|
|
@@ -100,7 +138,7 @@ class DatiFragment : Fragment() {
|
|
|
binding.dialogGettlLoginTime.text = "登录时间:${ccc}"
|
|
binding.dialogGettlLoginTime.text = "登录时间:${ccc}"
|
|
|
|
|
|
|
|
val uid = UserInfoSpUtils().getUserId()
|
|
val uid = UserInfoSpUtils().getUserId()
|
|
|
- binding.fragmentDatiUid.text = "UID:${uid}"
|
|
|
|
|
|
|
+ binding.fragmentDatiUid.text = uid
|
|
|
binding.dialogGettlUserid.text = uid
|
|
binding.dialogGettlUserid.text = uid
|
|
|
binding.dialogSetUserid.text = uid
|
|
binding.dialogSetUserid.text = uid
|
|
|
|
|
|
|
@@ -121,6 +159,7 @@ class DatiFragment : Fragment() {
|
|
|
binding.switch2.isChecked = true
|
|
binding.switch2.isChecked = true
|
|
|
|
|
|
|
|
startGetTlTime()
|
|
startGetTlTime()
|
|
|
|
|
+
|
|
|
startGetTlShowBtnTime()
|
|
startGetTlShowBtnTime()
|
|
|
|
|
|
|
|
initGetTlTime()
|
|
initGetTlTime()
|
|
@@ -143,7 +182,7 @@ class DatiFragment : Fragment() {
|
|
|
binding.dialogGr.visibility = View.GONE
|
|
binding.dialogGr.visibility = View.GONE
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- binding.getTl.setOnClickListener {
|
|
|
|
|
|
|
+ binding.getTlCl.setOnClickListener {
|
|
|
|
|
|
|
|
if (getTlTime > 0) {
|
|
if (getTlTime > 0) {
|
|
|
ToastUtils.showShort("等待倒计时结束!")
|
|
ToastUtils.showShort("等待倒计时结束!")
|
|
@@ -164,7 +203,12 @@ class DatiFragment : Fragment() {
|
|
|
binding.dialgoGettlLl.setOnClickListener { }
|
|
binding.dialgoGettlLl.setOnClickListener { }
|
|
|
|
|
|
|
|
binding.dialotGettlBtnTx.setOnClickListener {
|
|
binding.dialotGettlBtnTx.setOnClickListener {
|
|
|
- addPower()
|
|
|
|
|
|
|
+ showAd()
|
|
|
|
|
+ }
|
|
|
|
|
+ binding.getTlDialogClose.setOnClickListener {
|
|
|
|
|
+ this.isGetTlDialogShow = false
|
|
|
|
|
+ binding.dialgoGettlLl.visibility = View.GONE
|
|
|
|
|
+ initGetTlBtnTime()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
binding.a1.setOnClickListener {
|
|
binding.a1.setOnClickListener {
|
|
@@ -185,23 +229,60 @@ class DatiFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun initUserTime() {
|
|
private fun initUserTime() {
|
|
|
- if (job == null){
|
|
|
|
|
|
|
+ if (job == null) {
|
|
|
job = Job()
|
|
job = Job()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (scope == null){
|
|
|
|
|
|
|
+ if (scope == null) {
|
|
|
scope = CoroutineScope(Dispatchers.Main + job!!)
|
|
scope = CoroutineScope(Dispatchers.Main + job!!)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
scope!!.launch {
|
|
scope!!.launch {
|
|
|
while (isActive) {
|
|
while (isActive) {
|
|
|
useTimer++
|
|
useTimer++
|
|
|
- LogUtils.e(useTimer)
|
|
|
|
|
delay(1000)
|
|
delay(1000)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun initInAdTime() {
|
|
|
|
|
+ if (job1 == null) {
|
|
|
|
|
+ job1 = Job()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (scope1 == null) {
|
|
|
|
|
+ scope1 = CoroutineScope(Dispatchers.Main + job1!!)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ scope1!!.launch {
|
|
|
|
|
+ while (isActive) {
|
|
|
|
|
+ if (!isInAdPaunse) {
|
|
|
|
|
+ inAdTime++
|
|
|
|
|
+ if (inAdTime == 60) {
|
|
|
|
|
+
|
|
|
|
|
+ interstitialAd?.show(activity, getATShowConfig1())
|
|
|
|
|
+ job1?.cancel()
|
|
|
|
|
+ scope1?.cancel()
|
|
|
|
|
+ job1 = null
|
|
|
|
|
+ scope1 = null
|
|
|
|
|
+ inAdTime = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ delay(1000)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onPause() {
|
|
|
|
|
+ super.onPause()
|
|
|
|
|
+ this.isInAdPaunse = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onResume() {
|
|
|
|
|
+ super.onResume()
|
|
|
|
|
+ this.isInAdPaunse = false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private fun initDialogGetTl() {
|
|
private fun initDialogGetTl() {
|
|
|
|
|
|
|
|
val adapter = MineAdapter(initDataAdapter())
|
|
val adapter = MineAdapter(initDataAdapter())
|
|
@@ -230,6 +311,23 @@ class DatiFragment : Fragment() {
|
|
|
.enqueue(object : Callback2<Any>() {
|
|
.enqueue(object : Callback2<Any>() {
|
|
|
override fun success(body: Any?) {
|
|
override fun success(body: Any?) {
|
|
|
val userinfo = UserInfoSpUtils().getUserInfo()
|
|
val userinfo = UserInfoSpUtils().getUserInfo()
|
|
|
|
|
+
|
|
|
|
|
+ var answerTime = ""
|
|
|
|
|
+
|
|
|
|
|
+ // 格式化为ISO字符串
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
+ val instant = Instant.now()
|
|
|
|
|
+ val formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME
|
|
|
|
|
+ answerTime = instant.atZone(ZoneId.of("UTC")).format(formatter)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ answerTime = DateTimeUtils.getCurrentDateTimeIso().toString()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val record = Record(answerTime)
|
|
|
|
|
+ val ddd = UserInfoSpUtils().getUserInfo().answerRecordList as MutableList
|
|
|
|
|
+ ddd.add(0, record)
|
|
|
|
|
+
|
|
|
|
|
+ userinfo.answerRecordList = ddd
|
|
|
userinfo.lastQuestionId = questionId
|
|
userinfo.lastQuestionId = questionId
|
|
|
UserInfoSpUtils().changeValue(userinfo)
|
|
UserInfoSpUtils().changeValue(userinfo)
|
|
|
initDialogGetTl()
|
|
initDialogGetTl()
|
|
@@ -282,7 +380,7 @@ class DatiFragment : Fragment() {
|
|
|
@SuppressLint("SetTextI18n")
|
|
@SuppressLint("SetTextI18n")
|
|
|
private fun initGetTlTime() {
|
|
private fun initGetTlTime() {
|
|
|
binding.zz.visibility = View.VISIBLE
|
|
binding.zz.visibility = View.VISIBLE
|
|
|
- getTlTime = 30
|
|
|
|
|
|
|
+ getTlTime = 20
|
|
|
binding.zz.text = "${getTlTime}s"
|
|
binding.zz.text = "${getTlTime}s"
|
|
|
getTlCountDownTimer?.start()
|
|
getTlCountDownTimer?.start()
|
|
|
}
|
|
}
|
|
@@ -290,8 +388,9 @@ class DatiFragment : Fragment() {
|
|
|
@SuppressLint("SetTextI18n")
|
|
@SuppressLint("SetTextI18n")
|
|
|
private fun initGetTlBtnTime() {
|
|
private fun initGetTlBtnTime() {
|
|
|
binding.dialotGettlBtnTx.visibility = View.GONE
|
|
binding.dialotGettlBtnTx.visibility = View.GONE
|
|
|
|
|
+ binding.getTlDialogClose.visibility = View.GONE
|
|
|
binding.dialgoGettlTime.visibility = View.VISIBLE
|
|
binding.dialgoGettlTime.visibility = View.VISIBLE
|
|
|
- getTlShowBtnTime = 10
|
|
|
|
|
|
|
+ getTlShowBtnTime = 8
|
|
|
binding.dialgoGettlTime.text = "${getTlShowBtnTime}s"
|
|
binding.dialgoGettlTime.text = "${getTlShowBtnTime}s"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -300,7 +399,7 @@ class DatiFragment : Fragment() {
|
|
|
if (getTlShowBtnCountDownTimer != null) {
|
|
if (getTlShowBtnCountDownTimer != null) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- this.getTlShowBtnTime = 10
|
|
|
|
|
|
|
+ this.getTlShowBtnTime = 8
|
|
|
getTlShowBtnCountDownTimer =
|
|
getTlShowBtnCountDownTimer =
|
|
|
object : CountDownTimer((getTlShowBtnTime * 1000).toLong(), 1000) {
|
|
object : CountDownTimer((getTlShowBtnTime * 1000).toLong(), 1000) {
|
|
|
@SuppressLint("SetTextI18n")
|
|
@SuppressLint("SetTextI18n")
|
|
@@ -313,6 +412,7 @@ class DatiFragment : Fragment() {
|
|
|
override fun onFinish() {
|
|
override fun onFinish() {
|
|
|
binding.dialgoGettlTime.visibility = View.GONE
|
|
binding.dialgoGettlTime.visibility = View.GONE
|
|
|
binding.dialotGettlBtnTx.visibility = View.VISIBLE
|
|
binding.dialotGettlBtnTx.visibility = View.VISIBLE
|
|
|
|
|
+ binding.getTlDialogClose.visibility = View.VISIBLE
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -323,7 +423,7 @@ class DatiFragment : Fragment() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.getTlTime = 30
|
|
|
|
|
|
|
+ this.getTlTime = 20
|
|
|
getTlCountDownTimer = object : CountDownTimer((getTlTime * 1000).toLong(), 1000) {
|
|
getTlCountDownTimer = object : CountDownTimer((getTlTime * 1000).toLong(), 1000) {
|
|
|
@SuppressLint("SetTextI18n")
|
|
@SuppressLint("SetTextI18n")
|
|
|
override fun onTick(millisUntilFinished: Long) {
|
|
override fun onTick(millisUntilFinished: Long) {
|
|
@@ -338,6 +438,25 @@ class DatiFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun startReloadRewardVideoAd() {
|
|
|
|
|
+
|
|
|
|
|
+ if (startReloadRewardVideoAd != null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ startReloadRewardVideoAd = object : CountDownTimer((loadingTime * 1000).toLong(), 1000) {
|
|
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
|
|
+ override fun onTick(millisUntilFinished: Long) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onFinish() {
|
|
|
|
|
+ ToastUtils.showShort("非法操作,请30秒后重新获取!")
|
|
|
|
|
+ if (loadDialog?.isShowing == true) loadDialog?.dismiss()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private fun initLever() {
|
|
private fun initLever() {
|
|
|
val lastQuestionId = UserInfoSpUtils().getLastQuestionId()
|
|
val lastQuestionId = UserInfoSpUtils().getLastQuestionId()
|
|
|
questions?.forEachIndexed { index, question ->
|
|
questions?.forEachIndexed { index, question ->
|
|
@@ -447,6 +566,8 @@ class DatiFragment : Fragment() {
|
|
|
val questionId = item?.questionId
|
|
val questionId = item?.questionId
|
|
|
val itemId = item?.itemList?.get(btnIndex)?.itemId
|
|
val itemId = item?.itemList?.get(btnIndex)?.itemId
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if (questionId != null && itemId != null) {
|
|
if (questionId != null && itemId != null) {
|
|
|
answer(questionId, itemId)
|
|
answer(questionId, itemId)
|
|
|
} else {
|
|
} else {
|
|
@@ -509,8 +630,8 @@ class DatiFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- override fun onPause() {
|
|
|
|
|
- super.onPause()
|
|
|
|
|
|
|
+ override fun onDestroy() {
|
|
|
|
|
+ super.onDestroy()
|
|
|
getTlCountDownTimer?.cancel()
|
|
getTlCountDownTimer?.cancel()
|
|
|
getTlShowBtnCountDownTimer?.cancel()
|
|
getTlShowBtnCountDownTimer?.cancel()
|
|
|
getTlCountDownTimer = null
|
|
getTlCountDownTimer = null
|
|
@@ -521,8 +642,261 @@ class DatiFragment : Fragment() {
|
|
|
scope = null
|
|
scope = null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- override fun onDestroy() {
|
|
|
|
|
- super.onDestroy()
|
|
|
|
|
- job?.cancel()
|
|
|
|
|
|
|
+ private fun loadAd() {
|
|
|
|
|
+ if (mRewardVideoAd == null) {
|
|
|
|
|
+ mRewardVideoAd = ATRewardVideoAd(context, "b68400aae18fc0")
|
|
|
|
|
+ }
|
|
|
|
|
+ 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
|
|
|
|
|
+ mRewardVideoAd?.setLocalExtra(localMap)
|
|
|
|
|
+ mRewardVideoAd?.setAdListener(this)
|
|
|
|
|
+ mRewardVideoAd?.load()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private var isReload = false
|
|
|
|
|
+
|
|
|
|
|
+ private fun showAd() {
|
|
|
|
|
+ if (mRewardVideoAd?.isAdReady == true) {
|
|
|
|
|
+ mRewardVideoAd?.show(activity)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 在 Fragment 中使用
|
|
|
|
|
+ if (isAdded && activity != null && !requireActivity().isFinishing) {
|
|
|
|
|
+ loadDialog = LoadingDialog(activity)
|
|
|
|
|
+ loadDialog?.show()
|
|
|
|
|
+ startReloadRewardVideoAd()
|
|
|
|
|
+ startReloadRewardVideoAd?.start()
|
|
|
|
|
+ }
|
|
|
|
|
+ isReload = true
|
|
|
|
|
+ if (mRewardVideoAd?.checkAdStatus()?.isLoading != true) mRewardVideoAd?.load()
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private var isRewardedVideoFinish = false
|
|
|
|
|
+
|
|
|
|
|
+ override fun onRewardedVideoAdLoaded() {
|
|
|
|
|
+ LogUtils.e("DFDFDF=onRewardedVideoAdLoaded")
|
|
|
|
|
+ startReloadRewardVideoAd?.cancel()
|
|
|
|
|
+ startReloadRewardVideoAd = null
|
|
|
|
|
+ if (loadDialog?.isShowing == true) loadDialog?.dismiss()
|
|
|
|
|
+ if (isReload) showAd()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onRewardedVideoAdFailed(p0: AdError?) {
|
|
|
|
|
+ LogUtils.e("DFDFDF=onRewardedVideoAdFailed${p0?.code}")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onRewardedVideoAdPlayStart(p0: ATAdInfo?) {
|
|
|
|
|
+ isReload = false
|
|
|
|
|
+ isRewardedVideoFinish = false
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
+ val current = LocalDateTime.now()
|
|
|
|
|
+ val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
|
|
+ startAdTime = current.format(formatter)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ startAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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()}")
|
|
|
|
|
+ if (!isRewardedVideoFinish) {
|
|
|
|
|
+ ToastUtils.showShort("请观看完广告再关闭!")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onRewardedVideoAdPlayClicked(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("DFDFDF=onRewardedVideoAdPlayClicked${p0.toString()}")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onReward(p0: ATAdInfo?) {
|
|
|
|
|
+
|
|
|
|
|
+ LogUtils.e("DFDFDF=onReward${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")
|
|
|
|
|
+ endAdTime = current.format(formatter)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ endAdTime = DateTimeUtils.getCurrentDateTime()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saveRecord(p0)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun saveRecord(p0: ATAdInfo?) {
|
|
|
|
|
+
|
|
|
|
|
+ if (p0 == null) return
|
|
|
|
|
+ val map = HashMap<String, Any>()
|
|
|
|
|
+ map["adSourceId"] = p0.adsourceId.toInt()
|
|
|
|
|
+ map["beginTime"] = startAdTime.toString()
|
|
|
|
|
+ map["finishTime"] = endAdTime.toString()
|
|
|
|
|
+ map["networkFormId"] = p0.networkFirmId
|
|
|
|
|
+ map["networkName"] = p0.networkName
|
|
|
|
|
+ map["networkPlacementId"] = p0.networkPlacementId
|
|
|
|
|
+ map["nickName"] = UserInfoSpUtils().getNickName()
|
|
|
|
|
+ map["placementId"] = p0.placementId
|
|
|
|
|
+ map["recordId"] = p0.requestId
|
|
|
|
|
+ map["revenue"] = p0.publisherRevenue.toDouble()
|
|
|
|
|
+ map["userId"] = UserInfoSpUtils().getUserId()
|
|
|
|
|
+ map["ecpm"] = p0.ecpm.toString()
|
|
|
|
|
+ map["adSourceIndex"] = p0.adsourceIndex
|
|
|
|
|
+ map["adSourceType"] = p0.adSourceAdType
|
|
|
|
|
+ map["resultJson"] = p0.toString()
|
|
|
|
|
+
|
|
|
|
|
+ val body = BaseRetrofit.getRequestBodyByMapToJson(map)
|
|
|
|
|
+
|
|
|
|
|
+ BaseRetrofit.getInstance().apiService.saveRecord(body).enqueue(object : Callback2<Any>() {
|
|
|
|
|
+ override fun success(body: Any?) {
|
|
|
|
|
+ addPower()
|
|
|
|
|
+ LogUtils.e("dfdfdfdf广告同步成功!")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun fail(msg: String?) {
|
|
|
|
|
+ ToastUtils.showShort(msg)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun loadNativeAd() {
|
|
|
|
|
+ if (atNative == null) {
|
|
|
|
|
+ atNative = ATNative(context, "b68400acd7390c", object : ATNativeNetworkListener {
|
|
|
|
|
+ override fun onNativeAdLoaded() {
|
|
|
|
|
+ val nativeAd: NativeAd? = atNative?.getNativeAd(getATShowConfig())
|
|
|
|
|
+ try {
|
|
|
|
|
+ nativeAd?.renderAdContainer(binding.fragmentDatiContentAd, null)
|
|
|
|
|
+ } catch (e: Exception) {
|
|
|
|
|
+ e.printStackTrace()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onNativeAdLoadFail(adError: AdError) {
|
|
|
|
|
+ LogUtils.e("onNativeAdLoadFail:" + adError.fullErrorInfo)
|
|
|
|
|
+ atNative = null
|
|
|
|
|
+ loadNativeAd()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ binding.fragmentDatiContentAd.removeAllViews()
|
|
|
|
|
+ atNative?.makeAdRequest()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun loadInterstitial() {
|
|
|
|
|
+
|
|
|
|
|
+ interstitialAd = ATInterstitial(context, "b68400ac31936e")
|
|
|
|
|
+ interstitialAd?.setNativeAdCustomRender { mixNativeAd, atAdInfo ->
|
|
|
|
|
+ MediationNativeAdUtil.getViewFromNativeAd(
|
|
|
|
|
+ context,
|
|
|
|
|
+ mixNativeAd,
|
|
|
|
|
+ atAdInfo,
|
|
|
|
|
+ true
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ interstitialAd?.setAdListener(object : ATInterstitialListener {
|
|
|
|
|
+ override fun onInterstitialAdLoaded() {
|
|
|
|
|
+ LogUtils.e("==========onInterstitialAdLoaded")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdLoadFail(p0: AdError?) {
|
|
|
|
|
+ LogUtils.e("===========onInterstitialAdLoadFail")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdClicked(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("===========onInterstitialAdClicked")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdShow(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("=============onInterstitialAdShow")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdClose(p0: ATAdInfo?) {
|
|
|
|
|
+ initInAdTime()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdVideoStart(p0: ATAdInfo?) {
|
|
|
|
|
+ interstitialAd?.load()
|
|
|
|
|
+ LogUtils.e("===========onInterstitialAdVideoStart")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdVideoEnd(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("==============onInterstitialAdVideoEnd")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onInterstitialAdVideoError(p0: AdError?) {
|
|
|
|
|
+ LogUtils.e("==========onInterstitialAdVideoError")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+ interstitialAd?.load()
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun loadBannerAd() {
|
|
|
|
|
+ val mBannerView = ATBannerView(context)
|
|
|
|
|
+ mBannerView.setPlacementId("b68400aba2a385")
|
|
|
|
|
+ mBannerView.setShowConfig(getATShowConfig())
|
|
|
|
|
+ mBannerView.setBannerAdListener(this)
|
|
|
|
|
+ binding.fragmentDatiBanner.removeAllViews()
|
|
|
|
|
+ binding.fragmentDatiBanner.addView(mBannerView)
|
|
|
|
|
+ mBannerView.loadAd()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun getATShowConfig(): ATShowConfig {
|
|
|
|
|
+ val builder: ATShowConfig.Builder = ATShowConfig.Builder()
|
|
|
|
|
+ builder.scenarioId("banner_ad_show_1")
|
|
|
|
|
+ builder.showCustomExt("banner_ad_show_custom_ext")
|
|
|
|
|
+
|
|
|
|
|
+ return builder.build()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private fun getATShowConfig1(): ATShowConfig {
|
|
|
|
|
+ val builder = ATShowConfig.Builder()
|
|
|
|
|
+ builder.scenarioId("interstitial_ad_show_1")
|
|
|
|
|
+ builder.showCustomExt("interstitial_ad_show_custom_ext")
|
|
|
|
|
+
|
|
|
|
|
+ return builder.build()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onBannerLoaded() {
|
|
|
|
|
+ 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")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onBannerClose(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("dfdfdf onBannerClose")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onBannerAutoRefreshed(p0: ATAdInfo?) {
|
|
|
|
|
+ LogUtils.e("dfdfdf onBannerAutoRefreshed")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onBannerAutoRefreshFail(p0: AdError?) {
|
|
|
|
|
+ LogUtils.e("dfdfdf onBannerAutoRefreshFail")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|