76 lines
2.2 KiB
Kotlin
76 lines
2.2 KiB
Kotlin
package com.wallpaper.wallpapermagic
|
|
|
|
import android.app.Application
|
|
import android.content.Context
|
|
import android.content.SharedPreferences
|
|
import android.util.Log
|
|
import androidx.core.content.edit
|
|
import com.anythink.core.api.ATSDK
|
|
import com.anythink.core.api.NetTrafficeCallback
|
|
import com.wallpaper.wallpapermagic.room.AppDatabase
|
|
import com.wallpaper.wallpapermagic.topon.AdManager
|
|
import com.wallpaper.wallpapermagic.utils.JsonUtils
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.launch
|
|
|
|
class App : Application() {
|
|
companion object {
|
|
@Volatile
|
|
private lateinit var instance: App
|
|
|
|
const val DB_VERSION = 1
|
|
const val DB_NAME = "magic_database"
|
|
private const val PREF_NAME = "magic_preferences"
|
|
private const val INIT_DATABASE = "InitDatabase"
|
|
const val TAG = "----------Test----"
|
|
|
|
@JvmStatic
|
|
fun getContext(): Context {
|
|
return instance.applicationContext
|
|
}
|
|
}
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
instance = this
|
|
initTopOn()
|
|
val preferences: SharedPreferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE)
|
|
val init = preferences.getBoolean(INIT_DATABASE, false)
|
|
|
|
if (!init) {
|
|
initDatabase()
|
|
preferences.edit() { putBoolean(INIT_DATABASE, true) }
|
|
}
|
|
}
|
|
|
|
private fun initDatabase() {
|
|
val magicDao = AppDatabase.getDatabase(this).magicDao()
|
|
|
|
val magicEntities = JsonUtils.parseJson("wallpaper.json")
|
|
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
magicDao.insertAll(magicEntities)
|
|
}
|
|
}
|
|
|
|
private fun initTopOn(){
|
|
Log.d(TAG,"--------initTopOn")
|
|
ATSDK.checkIsEuTraffic(this, object : NetTrafficeCallback {
|
|
override fun onResultCallback(isEU: Boolean) {
|
|
if (isEU && ATSDK.getGDPRDataLevel(this@App) == ATSDK.UNKNOWN) {
|
|
ATSDK.showGdprAuth(this@App)
|
|
}
|
|
}
|
|
|
|
override fun onErrorCallback(errorMsg: String) {
|
|
|
|
}
|
|
})
|
|
ATSDK.init( this, "h67d933408d3fc", "a3d2ffafdcdfe47b9a129164309345cce")
|
|
AdManager.loadAllAd()
|
|
}
|
|
|
|
}
|
|
|