# KtWanAndroid **Repository Path**: PrettyAnt/ktWanAndroid ## Basic Information - **Project Name**: KtWanAndroid - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-12-15 - **Last Updated**: 2026-02-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: Kotlin, Android ## README # KtWanAndroid - WanAndroid Client in Kotlin ## 📱 Project Overview KtWanAndroid is an Android application developed using Kotlin that implements the client functionality for the WanAndroid website. The project showcases modern Android development practices including MVVM architecture, modular design, dependency injection, and other industry best practices. ## 🏗️ Architecture ### Technology Stack - **Language**: 100% Kotlin - **Architecture Pattern**: MVVM (Model-View-ViewModel) - **Dependency Injection**: Dagger Hilt - **Network**: Retrofit2 + OkHttp3 + Kotlin Coroutines - **Routing**: ARouter - **Data Storage**: MMKV - **UI Components**: Jetpack Navigation, DataBinding, ViewBinding - **Build Tool**: Gradle (Kotlin DSL) ### Module Structure ``` app/ # Main application module ├── src/main/java/com/prettyant/ktwanandroid/ │ ├── KtApplication.kt # Application class │ ├── MainActivity.kt # Main Activity │ └── SplashActivity.kt # Splash screen │ kt_common/ # Common module (core infrastructure) ├── base/ # Base classes │ ├── BaseActivity.kt │ ├── BaseFragment.kt │ ├── BaseViewModel.kt │ ├── BaseVMActivity.kt │ └── BaseVMFragment.kt ├── network/ # Network layer │ ├── BaseRepository.kt │ ├── RetrofitManager.kt │ └── interceptor/ # Interceptors ├── util/ # Utility classes └── di/ # Dependency injection │ kt_home/ # Home module kt_project/ # Project module kt_navigation/ # Navigation module kt_login/ # Login module kt_collect/ # Collection module kt_web/ # WebView module ``` ## 🚀 Getting Started ### Prerequisites - Latest Android Studio - JDK 17+ - Gradle 8.0+ - Android SDK API 31+ ### Build Configuration The project supports three build variants: - **debug**: Development environment with test API endpoints - **uat**: User Acceptance Testing environment - **release**: Production environment ### Build Steps 1. Clone the repository ```bash git clone ``` 2. Open project in Android Studio - File → Open → Select project root directory 3. Wait for Gradle sync to complete 4. Select build variant - Build Variants panel → Choose `debug` or `uat` 5. Run the application - Connect Android device or start emulator - Run → Run 'app' ## 📖 Core Features ### 1. Base Architecture - **BaseActivity/BaseFragment**: Unified lifecycle management and logging - **BaseVMActivity/BaseVMFragment**: MVVM architecture support with built-in lazy loading - **BaseViewModel**: Standard ViewModel base class with coroutine support ### 2. Network Layer - **RetrofitManager**: Unified network request management - **BaseRepository**: Data repository base class with unified error handling - **Interceptors**: - `PrettyHttpLoggingInterceptor`: Enhanced logging interceptor with JSON formatting - `HeaderInterceptor`: Unified request header management - `ErrorInterceptor`: Unified error code handling - `RetrofitProxyInterceptor`: Dynamic proxy interceptor for request monitoring ### 3. Data Management - **CookieJar**: Automated cookie management - **RespStateData**: Response state wrapper with loading state management - **BaseStateObserver**: Unified data observer ### 4. UI Components - **CollectRvAdapter**: Collection list adapter with pagination support - **SwipeToDeleteCallback**: Swipe-to-delete callback with undo functionality ## 🛠️ Development Guide ### Creating New Modules 1. Create new module folder in project root (e.g., `kt_newfeature`) 2. Create corresponding `build.gradle` file 3. Add module reference in `settings.gradle` 4. Add dependency in main module's `build.gradle` ### Adding New Pages 1. Extend appropriate base class: ```kotlin class NewActivity : BaseVMActivity() { override fun getLayoutId(): Int = R.layout.activity_new override fun observe() { // Observe ViewModel data } override fun initView() { // Initialize UI components } } ``` 2. Register route in ARouter: ```kotlin @Route(path = Constants.PATH_NEW) @AndroidEntryPoint class NewActivity : BaseVMActivity() ``` ### Network Requests 1. Define API interface: ```kotlin interface NewApi { @GET("api/path") suspend fun getData(): BaseResp } ``` 2. Create Repository: ```kotlin @Singleton class NewRepo @Inject constructor(private val api: NewApi) : BaseRepository() { suspend fun getData(liveData: RespStateData) { dealResp(callback = { api.getData() }, liveData) } } ``` 3. Use in ViewModel: ```kotlin @HiltViewModel class NewViewModel @Inject constructor(private val repo: NewRepo) : BaseViewModel() { val data = RespStateData() fun loadData() { launch { repo.getData(data) } } } ``` ## 🔧 Configuration ### Dependency Management Project uses unified `dependencies.gradle` for dependency management: - **Core Dependencies**: Hilt, Retrofit, OkHttp, Coroutines - **UI Dependencies**: Navigation, Coil, BannerViewPager - **Utility Dependencies**: ARouter, MMKV, ByteHook ### Build Configuration ```gradle android { compileSdk 36 defaultConfig { minSdk 31 targetSdk 36 versionCode 2 versionName "1.1.0" } buildTypes { debug { buildConfigField "String", "BASE_URL", "\"https://debug-api.example.com/\"" } release { buildConfigField "String", "BASE_URL", "\"https://api.example.com/\"" } uat { buildConfigField "String", "BASE_URL", "\"https://uat-api.example.com/\"" } } } ``` ## 📱 Feature Modules ### Home Module (kt_home) - Article list display - Banner carousel - Pagination loading ### Project Module (kt_project) - Project categories - Project details ### Collection Module (kt_collect) - Collection list - Remove from collection - Swipe-to-delete ### Login Module (kt_login) - User login - Registration ### Web Module (kt_web) - Built-in browser - Article detail display ## 🐛 Troubleshooting ### Common Issues 1. **ARouter routes not working** - Ensure correct configuration in `dependencies.gradle`: `kapt "com.alibaba:arouter-compiler:1.5.2"` - Check modules have correct `@Route` annotation 2. **Hilt dependency injection failures** - Ensure Application class has `@HiltAndroidApp` annotation - Check Activity/Fragment has `@AndroidEntryPoint` annotation 3. **Network request failures** - Verify BASE_URL configuration - Confirm network permissions are added ### Debugging Tips - Use `PrettyHttpLoggingInterceptor` for detailed network logs - Enable ARouter debug mode: `ARouter.openDebug()` - Check Hilt generated code at `app/build/generated/source/kapt/` ## 📈 Performance Optimization ### Implemented Optimizations 1. **Lazy Loading**: Smart lazy loading in BaseVMFragment 2. **Memory Optimization**: Timely release of DataBinding references 3. **Network Optimization**: Connection timeout and retry mechanisms 4. **Image Loading**: Optimized image loading with Coil ### Recommended Optimizations 1. Implement image caching strategy 2. Add database caching layer 3. Implement more granular error handling ## 🤝 Contributing 1. Fork the repository 2. Create feature branch (`git checkout -b feature/AmazingFeature`) 3. Commit changes (`git commit -m 'Add some AmazingFeature'`) 4. Push to branch (`git push origin feature/AmazingFeature`) 5. Open Pull Request ## 📄 License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## 🙏 Acknowledgments - [WanAndroid API](https://www.wanandroid.com/) - For providing open API - Contributors of Jetpack, Retrofit, Dagger Hilt, and other open-source libraries ## 📞 Contact For issues or suggestions, please contact: - Email: prettyant@qq.com - GitHub: [Issues](https://github.com/your-repo/issues) --- **Note**: This project is developed for learning and communication purposes. API data comes from the WanAndroid open platform. Do not use for commercial purposes.