| 类别 | 工具/扩展 | 说明 |
|---|---|---|
| 🛠️ 工具类 | NetworkUtil | 网络状态监听、类型判断 |
| 🛠️ 工具类 | DateUtil | 时间格式化、相对时间 |
| 🛠️ 工具类 | FileUtil | 缓存目录、文件读写 |
| 🛠️ 工具类 | ScreenUtil | dp / px 转换、屏幕信息 |
| ⚡ 扩展函数 | Context.toast() | 简化 Toast 显示 |
| ⚡ 扩展函数 | String.isValidEmail() | 邮箱格式校验 |
| ⚡ 扩展函数 | Int.dp | Int 转 Dp (Compose) |
| ⚡ 扩展函数 | List | 防御性拷贝 |
| 🎨 Compose扩展 | Modifier.paddingHorizontal() | 快速水平内边距 |
| 🎨 Compose扩展 | Color.complementary() | 获取互补色 |
// ===== 扩展函数示例 (Context + Compose) =====
fun Context.showShortToast(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}
// Modifier 扩展 —— 通用边距
fun Modifier.commonPadding(): Modifier =
this.padding(horizontal = 16.dp, vertical = 12.dp)
// 字符串扩展 —— 邮箱校验
fun String.isValidEmail(): Boolean {
return !isNullOrBlank() &&
android.util.Patterns.EMAIL_ADDRESS.matcher(this).matches()
}
// ===== CommonTopBar 示例 =====
@Composable
fun CommonTopBar(
title: String,
onBack: (() -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {}
) {
TopAppBar(
title = { Text(title, fontWeight = FontWeight.SemiBold) },
navigationIcon = {
if (onBack != null) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, "返回")
}
}
},
actions = actions,
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
titleContentColor = MaterialTheme.colorScheme.onSurface
)
)
}
⬆ 多模块依赖关系:所有业务模块仅依赖 :common