package com.yidian.shenghuoquan.bgeneralbusiness.app

import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.constant.SpinnerStyle
import com.yidian.bcommon.app.YdBaseApplication
import com.yidian.bcommon.services.ZapServiceNameConstants
import com.yidian.news.util.ProcessUtil
import com.yidian.shenghuoquan.bgeneralbusiness.service.EncryptService
import com.yidian.shenghuoquan.bgeneralbusiness.service.GeneralAbilityService
import com.yidian.shenghuoquan.bgeneralbusiness.service.net.BNAHttpReqService
import com.yidian.yac.core.core.YacModuleSpec
import com.yidian.yac.core.zap.Zap

@YacModuleSpec
class BGeneralBusinessApplication : YdBaseApplication() {

  override fun onCreate() {
    super.onCreate()
    if (ProcessUtil.isMainProcess(this)) {
      initService()
      initSmartRefreshLayout()
    }
  }

  private fun initService() {
    Zap.addService(ZapServiceNameConstants.BNAHttpReq, BNAHttpReqService())
    Zap.addService(ZapServiceNameConstants.GeneralAbilityService, GeneralAbilityService())
    Zap.addService(ZapServiceNameConstants.EncryptService, EncryptService())
  }

  /**
   * 设置刷新 默认的header和footer
   */
  private fun initSmartRefreshLayout() {
    //设置全局的Header构建器
    SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
      layout.setPrimaryColorsId(android.R.color.transparent)//全局设置主题颜色
      ClassicsHeader(context) //指定为经典Header，默认是 贝塞尔雷达Header
    }
    //设置全局的Footer构建器
    SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
      layout.setEnableLoadMoreWhenContentNotFull(true) //内容不满一页时候启用加载更多
      val footer = ClassicsFooter(context)
      footer.setBackgroundResource(android.R.color.transparent)
      footer.setDrawableSize(20f)
      footer.spinnerStyle = SpinnerStyle.FixedBehind //设置为固定在背后模式
      footer //指定为经典Footer，默认是 BallPulseFooter
    }
  }

}
