package com.yidianling.user.base


import android.app.Application
import android.content.Context
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.UMShareAPI
import com.ydl.ydlcommon.base.delegate.IAppLifecycles
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.yidianling.user.api.event.UserSetEvent
import com.yidianling.user.api.service.IUserService
import com.yidianling.user.modular_service.UserServiceImp
import de.greenrobot.event.EventBus

/**
 * Created by haorui on 2019-09-02.
 * Des:
 */
class UserAppLifecycles : IAppLifecycles {
    override fun attachBaseContext(base: Context) {

    }

    override fun onCreate(application: Application) {
        EventBus.getDefault().register(this)
        UMConfigure.init(application, "56970affe0f55a9cda001e24", "android_yidianling", UMConfigure.DEVICE_TYPE_PHONE, null)
        UMShareAPI.init(application, "56970affe0f55a9cda001e24")
    }

    override fun onTerminate(application: Application) {
        EventBus.getDefault().unregister(this)
    }

    open fun onEvent(event:UserSetEvent){
        if (event.userResponse!=null){
            ModularServiceManager.provide(IUserService::class.java).setUserResponse(event.userResponse)
        } else if (event.userInfo!=null){
            ModularServiceManager.provide(IUserService::class.java).updateUserInfoSp(event.userInfo)
        }else if (event.userSetting!=null){
            ModularServiceManager.provide(IUserService::class.java).updateUserSetingSp(event.userSetting)
        }
    }

}
