update
This commit is contained in:
parent
459b6716b4
commit
b040a1d9c1
@ -32,7 +32,7 @@
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
||||
android:value="ca-app-pub-3940256099942544~3347511713" />
|
||||
android:value="ca-app-pub-1371732277241593~7848475249" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.LaunchActivity"
|
||||
|
||||
@ -2,49 +2,90 @@ package melody.offline.music.activity
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.CountDownTimer
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import com.gyf.immersionbar.ktx.immersionBar
|
||||
import com.lol.apex.ok.google.adlibrary.LoLAds
|
||||
import com.lol.apex.ok.google.adlibrary.base.listener.LolLoadError
|
||||
import com.lol.apex.ok.google.adlibrary.base.listener.LolShowError
|
||||
import melody.offline.music.ads.AdPlacement
|
||||
import melody.offline.music.ads.AnalysisAdState
|
||||
import melody.offline.music.ads.LolAdWrapper
|
||||
import melody.offline.music.databinding.ActivityLaunchBinding
|
||||
import melody.offline.music.util.AnalysisUtil
|
||||
import melody.offline.music.util.LogTag
|
||||
|
||||
class LaunchActivity : MoBaseActivity() {
|
||||
companion object {
|
||||
private const val MSG_PROGRESS = 0
|
||||
private const val MSG_LOAD_AD_LOADED = 1
|
||||
private const val MSG_LOAD_AD_FAIL = 2
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityLaunchBinding
|
||||
private val totalTime = 8000L // 5秒
|
||||
private var interval = 50L // 更新间隔,毫秒
|
||||
private val steps = totalTime / interval
|
||||
private val progressPerStep = 100f / steps.toFloat()
|
||||
private val mMaxLoading = 10000L//最大超时
|
||||
private var progress = 0f
|
||||
private val delayMillis = mMaxLoading / 100
|
||||
|
||||
private val handler = object : Handler(Looper.getMainLooper()) {
|
||||
override fun handleMessage(msg: Message) {
|
||||
val progressBar = binding.customProgressBar
|
||||
if (!isFinishing && !isDestroyed) {
|
||||
when (msg.what) {
|
||||
MSG_PROGRESS -> {
|
||||
if (progress >= 100f) {//超时
|
||||
//超时就是没有广告,就是广告show失败了
|
||||
val map =
|
||||
mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, "No cache for ads"))
|
||||
AnalysisUtil.placeToLogEvent(
|
||||
AdPlacement.INST_SPLASH, AnalysisAdState.AD_SHOW_FAILED, map
|
||||
)
|
||||
toMainActivity()
|
||||
return
|
||||
}
|
||||
if (adCanShow()) {
|
||||
sendEmptyMessageDelayed(MSG_LOAD_AD_LOADED, delayMillis)
|
||||
removeMessages(MSG_PROGRESS)
|
||||
return
|
||||
}
|
||||
progress += 1
|
||||
progressBar.setProgress(progress)
|
||||
sendEmptyMessageDelayed(MSG_PROGRESS, delayMillis)
|
||||
}
|
||||
|
||||
MSG_LOAD_AD_LOADED -> {
|
||||
if (progress >= 100f) {
|
||||
showAd()
|
||||
removeMessages(MSG_LOAD_AD_LOADED)
|
||||
return
|
||||
}
|
||||
progress += 2
|
||||
progressBar.setProgress(progress)
|
||||
sendEmptyMessageDelayed(MSG_LOAD_AD_LOADED, delayMillis)
|
||||
}
|
||||
|
||||
MSG_LOAD_AD_FAIL -> {
|
||||
sendEmptyMessageDelayed(MSG_LOAD_AD_LOADED, delayMillis)
|
||||
removeMessages(MSG_LOAD_AD_FAIL)
|
||||
removeMessages(MSG_PROGRESS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun main() {
|
||||
binding = ActivityLaunchBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
initTimer()
|
||||
loadAd()
|
||||
handler.sendEmptyMessageDelayed(MSG_PROGRESS, delayMillis)
|
||||
immersionBar {
|
||||
fullScreen(true)
|
||||
statusBarDarkFont(false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initTimer() {
|
||||
val progressBar = binding.customProgressBar
|
||||
val timer = object : CountDownTimer(totalTime, interval) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
progressBar.setProgress(progressBar.getProgress() + progressPerStep)
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
progressBar.setProgress(100f)
|
||||
showAd()
|
||||
}
|
||||
}
|
||||
|
||||
timer.start()
|
||||
}
|
||||
|
||||
private fun toMainActivity() {
|
||||
if (!withPermission()) {
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
@ -56,19 +97,21 @@ class LaunchActivity : MoBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadAd() {
|
||||
LolAdWrapper.shared.loadAd(
|
||||
this,
|
||||
LolAdWrapper.shared.loadAd(this,
|
||||
AdPlacement.INST_SPLASH,
|
||||
object : LolAdWrapper.LoLLoadListener {
|
||||
override fun loadFailed(error: LolLoadError?) {
|
||||
|
||||
handler.sendEmptyMessage(MSG_LOAD_AD_FAIL)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun adCanShow(): Boolean {
|
||||
return LolAdWrapper.shared.hasCache(AdPlacement.INST_SPLASH)
|
||||
}
|
||||
|
||||
private fun showAd() {
|
||||
LolAdWrapper.shared.showAdIfCached(
|
||||
this,
|
||||
LolAdWrapper.shared.showAdIfCached(this,
|
||||
AdPlacement.INST_SPLASH,
|
||||
object : LolAdWrapper.LolShowListener {
|
||||
override fun closed() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user