CLAUDE.md 3.4 KB

Base 模块

模块概述

Base 模块是整个 Android 框架的核心基础模块,提供了应用的基础配置管理、日志接口定义、统计接口以及基础框架抽象类。所有其他 frame 模块都依赖于此模块。

主要功能

1. 应用基础配置管理

  • AppBase: 应用全局配置单例管理器
  • IAppBase: 应用基础配置接口定义
  • 管理调试标志、环境配置、平台信息、深链接配置等

2. 基础框架抽象

  • BaseFrame: 提供监听器管理和协程支持的基础框架类
  • IBaseFrame: 基础框架接口定义
  • IListener: 监听器标记接口

3. 日志系统接口

  • ILog: 统一的日志接口定义
  • 支持 Debug、Info、Error 等多种日志级别

4. 统计接口

  • IStat: 统计事件接口定义
  • 支持事件数据的统计上报

5. 工具类和扩展

  • ConcurrentList: 线程安全的列表实现
  • KotlinExt: Kotlin 扩展函数
  • Callback: 回调接口定义

核心类和接口

IAppBase

interface IAppBase {
    val debugLog: Boolean
    val isRelease: Boolean
    val platform: String
    val deeplinkScheme: String
    val deeplinkHost: String
    val isProdEnv: Boolean
    val appName: String
    val log: ILog
}

BaseFrame
open class BaseFrame<L : IListener> : IBaseFrame<L>, CoroutineScope {
    fun dispatch(c: (l: L) -> Unit)
    fun addListener(l: L)
    fun removeListener(l: L)
    fun clearListeners()
    fun runOnSerialHandler(runnable: Runnable, delay: Long = 0L)
}

ILog

interface ILog {
    fun d(tag: String, msg: String)
    fun i(tag: String, msg: String)
    fun e(tag: String, msg: String, e: Exception? = null)
}

使用方式

1. 初始化应用基础配置

// 在 Application 中初始化
AppBase.init(object : IAppBase {
    override val debugLog: Boolean = BuildConfig.DEBUG
    override val isRelease: Boolean = !BuildConfig.DEBUG
    override val platform: String = "android"
    // ... 其他配置
})

2. 使用 BaseFrame

class MyManager : BaseFrame<MyListener>() {
    
    fun notifyListeners() {
        dispatch { listener ->
            listener.onEvent()
        }
    }
    
    fun doSomethingAsync() {
        runOnSerialHandler({
            // 异步操作
        })
    }
}

3. 使用日志系统

val log = AppBase.log
log.d("TAG", "Debug message")
log.i("TAG", "Info message")
log.e("TAG", "Error message", exception)

依赖关系

编译时依赖

  • frame:zero - 零依赖模块
  • frame:coroutine - 协程工具模块
  • androidx.annotation - Android 注解支持
  • kotlin-stdlib - Kotlin 标准库

被依赖关系

Base 模块是所有其他 frame 模块的基础依赖,提供了:

  • 统一的配置管理接口
  • 基础的框架抽象
  • 日志和统计接口定义
  • 线程安全的数据结构

构建配置

implementation "com.wenext.android:frame-base:6.0.2"

注意事项

  1. 全局单例: AppBase 是全局单例,需要在应用启动时进行初始化
  2. 监听器管理: BaseFrame 提供的监听器管理是线程安全的
  3. 协程支持: BaseFrame 实现了 CoroutineScope,支持协程操作
  4. 序列化执行: 通过 serialHandler 确保某些操作的序列化执行
  5. 内存管理: clearListeners() 方法谨慎使用,特别是对于单例管理器