# anzuode **Repository Path**: ma-zhida/anzuode ## Basic Information - **Project Name**: anzuode - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-04 - **Last Updated**: 2025-11-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AnZuo Android 项目框架 一个现代化的 Android 项目框架,采用 MVVM 架构模式,使用 Kotlin 语言开发。 ## 📋 项目结构 ``` app/ ├── src/ │ ├── main/ │ │ ├── java/com/anzuo/app/ │ │ │ ├── AnZuoApplication.kt # Application类 │ │ │ ├── data/ # 数据层 │ │ │ │ ├── local/ # 本地数据(Room数据库) │ │ │ │ │ ├── AppDatabase.kt # 数据库实例 │ │ │ │ │ ├── dao/ # 数据访问对象 │ │ │ │ │ │ └── ItemDao.kt │ │ │ │ │ └── entity/ # 数据库实体 │ │ │ │ │ └── ItemEntity.kt │ │ │ │ ├── model/ # 数据模型 │ │ │ │ │ └── Item.kt │ │ │ │ ├── remote/ # 远程数据(网络请求) │ │ │ │ │ └── ApiService.kt │ │ │ │ └── repository/ # 数据仓库 │ │ │ │ └── HomeRepository.kt │ │ │ ├── ui/ # UI层 │ │ │ │ ├── main/ # 主页面 │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ ├── HomeFragment.kt │ │ │ │ │ ├── HomeViewModel.kt │ │ │ │ │ └── HomeAdapter.kt │ │ │ │ ├── dashboard/ # 仪表盘页面 │ │ │ │ │ └── DashboardFragment.kt │ │ │ │ └── notifications/ # 通知页面 │ │ │ │ └── NotificationsFragment.kt │ │ │ └── util/ # 工具类 │ │ │ ├── Extensions.kt # 扩展函数 │ │ │ └── Resource.kt # 资源封装类 │ │ ├── res/ # 资源文件 │ │ │ ├── layout/ # 布局文件 │ │ │ ├── values/ # 值资源 │ │ │ ├── menu/ # 菜单资源 │ │ │ └── navigation/ # 导航资源 │ │ └── AndroidManifest.xml │ └── test/ # 测试代码 ├── build.gradle # 模块构建配置 └── proguard-rules.pro # 代码混淆规则 ``` ## 🏗️ 架构说明 ### MVVM 架构模式 本项目采用 **MVVM(Model-View-ViewModel)** 架构模式: - **Model(模型层)**:`data` 包下的数据模型、数据访问对象(DAO)、网络服务(API Service) - **View(视图层)**:`ui` 包下的 Activity、Fragment、Adapter - **ViewModel(视图模型层)**:`ui` 包下的 ViewModel 类,负责处理业务逻辑 ### 数据层架构 - **Repository(仓库)**:统一管理数据源,协调网络数据和本地数据 - **Remote Data Source(远程数据源)**:使用 Retrofit 进行网络请求 - **Local Data Source(本地数据源)**:使用 Room 数据库进行本地存储 ## 🛠️ 技术栈 - **语言**:Kotlin - **架构组件**: - ViewModel & LiveData - Navigation Component - Room Database - **网络请求**:Retrofit + OkHttp - **异步处理**:Kotlin Coroutines - **图片加载**:Glide - **UI组件**:Material Design Components - **构建工具**:Gradle ## 📦 主要依赖 ### AndroidX 组件 - `androidx.core:core-ktx` - Kotlin 扩展 - `androidx.appcompat:appcompat` - AppCompat 支持 - `androidx.lifecycle:lifecycle-viewmodel-ktx` - ViewModel - `androidx.lifecycle:lifecycle-livedata-ktx` - LiveData - `androidx.navigation:navigation-fragment-ktx` - Navigation Component ### 网络请求 - `com.squareup.retrofit2:retrofit` - Retrofit - `com.squareup.retrofit2:converter-gson` - Gson 转换器 - `com.squareup.okhttp3:okhttp` - OkHttp - `com.squareup.okhttp3:logging-interceptor` - 日志拦截器 ### 数据库 - `androidx.room:room-runtime` - Room 数据库 - `androidx.room:room-ktx` - Room Kotlin 扩展 ### 其他 - `org.jetbrains.kotlinx:kotlinx-coroutines-android` - 协程 - `com.github.bumptech.glide:glide` - 图片加载 ## 🚀 快速开始 ### 1. 环境要求 - Android Studio Hedgehog | 2023.1.1 或更高版本 - JDK 17 或更高版本 - Android SDK API 24(Android 7.0)或更高版本 ### 2. 克隆项目 ```bash git clone cd anzuo ``` ### 3. 配置项目 1. 打开 `app/build.gradle`,修改 `applicationId` 和 `API_BASE_URL` 2. 在 `AndroidManifest.xml` 中根据需要添加权限 ### 4. 运行项目 1. 使用 Android Studio 打开项目 2. 点击 Run 按钮或使用快捷键运行项目 ## 📝 代码规范 ### 命名规范 - **类名**:使用 PascalCase,如 `HomeFragment` - **方法名/变量名**:使用 camelCase,如 `loadData()` - **常量**:使用 UPPER_SNAKE_CASE,如 `API_BASE_URL` - **布局文件**:使用 snake_case,如 `activity_main.xml` ### 文件组织 - 每个功能模块放在独立的包下 - ViewModel 和对应的 Fragment/Activity 放在同一包下 - 工具类放在 `util` 包下 ## 🔧 常用功能示例 ### 使用 ViewModel ```kotlin class MyFragment : Fragment() { private val viewModel: MyViewModel by viewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) // 观察 LiveData viewModel.data.observe(viewLifecycleOwner) { data -> // 更新 UI } } } ``` ### 使用 Repository ```kotlin class MyRepository( private val apiService: ApiService, private val dao: MyDao ) { suspend fun getData(): List { // 从网络获取数据 val remoteData = apiService.getData() // 保存到本地数据库 dao.insertData(remoteData) return remoteData } } ``` ### 使用 Room 数据库 ```kotlin @Dao interface MyDao { @Query("SELECT * FROM my_table") suspend fun getAll(): List @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(entity: MyEntity) } ``` ## 📚 扩展指南 ### 添加新页面 1. 创建 Fragment 和对应的布局文件 2. 创建 ViewModel(如果需要) 3. 在 `mobile_navigation.xml` 中添加导航配置 4. 在 `bottom_nav_menu.xml` 中添加菜单项(如果是底部导航) ### 添加新的 API 接口 1. 在 `ApiService` 中添加接口方法 2. 创建对应的数据模型类 3. 在 Repository 中调用 API 方法 ### 添加新的数据库表 1. 创建 Entity 类 2. 创建 Dao 接口 3. 在 `AppDatabase` 中添加 Entity 和 Dao ## 🐛 常见问题 ### Q: 如何修改 API 基础地址? A: 在 `app/build.gradle` 中修改 `API_BASE_URL` 的值。 ### Q: 如何添加新的依赖? A: 在 `app/build.gradle` 的 `dependencies` 块中添加依赖,然后同步项目。 ### Q: ViewBinding 没有生成? A: 确保 `buildFeatures.viewBinding = true` 已启用,然后重新构建项目。 ## 📄 许可证 本项目采用 MIT 许可证。 ## 👥 贡献 欢迎提交 Issue 和 Pull Request! ## 📞 联系方式 如有问题,请通过 Issue 联系。 --- **Happy Coding! 🎉**