68 lines
2.1 KiB
Kotlin
68 lines
2.1 KiB
Kotlin
package com.gh.common.util
|
|
|
|
import android.annotation.SuppressLint
|
|
import androidx.lifecycle.MutableLiveData
|
|
import com.gh.common.constant.Config
|
|
import com.gh.gamecenter.common.utils.NetworkUtils
|
|
import com.gh.gamecenter.entity.SettingsEntity
|
|
import com.gh.gamecenter.entity.StartupAdEntity
|
|
import com.gh.gamecenter.common.retrofit.BiResponse
|
|
import com.gh.gamecenter.retrofit.RetrofitManager
|
|
import com.halo.assistant.HaloApp
|
|
import io.reactivex.schedulers.Schedulers
|
|
|
|
object AdHelper {
|
|
|
|
// 搜索为空/求版本/意见反馈-功能收录/发现/模拟器游戏
|
|
const val LOCATION_SEARCH_EMPTY = "search_empty"
|
|
const val LOCATION_GAME_REQUEST_VERSION = "game_request_version"
|
|
const val LOCATION_SUGGESTION_FUNCTION = "suggestion_function"
|
|
const val LOCATION_SIMULATOR_GAME = "simulator_game"
|
|
|
|
@JvmField
|
|
var startupAd = MutableLiveData<StartupAdEntity>()
|
|
|
|
@JvmStatic
|
|
@SuppressLint("CheckResult")
|
|
fun getStartUpAd() {
|
|
if (!NetworkUtils.isNetworkConnected(HaloApp.getInstance())) {
|
|
startupAd.postValue(null)
|
|
return
|
|
}
|
|
|
|
RetrofitManager.getInstance()
|
|
.api
|
|
.getSplashAd(HaloApp.getInstance().channel)
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribe(object : BiResponse<StartupAdEntity>() {
|
|
override fun onSuccess(data: StartupAdEntity) {
|
|
startupAd.postValue(data)
|
|
}
|
|
})
|
|
}
|
|
|
|
fun getAd(location: String): SettingsEntity.AD? {
|
|
val adList = Config.getSettings()?.adList ?: return null
|
|
|
|
for (ad in adList) {
|
|
if (ad.location == location) return ad
|
|
}
|
|
return null
|
|
}
|
|
|
|
fun getAdForLocation(location: String): SettingsEntity.AD? {
|
|
val adList = Config.getSettings()?.adList ?: return null
|
|
|
|
var result: SettingsEntity.AD? = null
|
|
run outside@ {
|
|
for (ad in adList) {
|
|
if (ad.location == location) {
|
|
result = ad
|
|
return@outside
|
|
}
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
} |