common) and Android-specific (commonAndroid) modules.
Module Overview
Common
Platform-agnostic utilities and extensions
Common Android
Android-specific UI components and utilities
Common Module
Module:common
Package: es.mobiledev.common
Provides platform-agnostic utilities, extensions, and common constants.
String Extensions
File:common/src/main/java/es/mobiledev/common/extensions/StringExtensions.kt
Extension functions for safe string parsing.
toSafeInt()
Safely converts a string to an integer, returning null on failureReturns:
Int? - Parsed integer or null if parsing failstoSafeLong()
Safely converts a string to a long, returning null on failureReturns:
Long? - Parsed long or null if parsing failstoLocalDate()
Parses a string to LocalDate using the app’s date pattern formatReturns:
LocalDate? - Parsed date or null if parsing failsThese extensions use try-catch blocks internally, making null checks cleaner than explicit exception handling.
Date Extensions
Package:es.mobiledev.common.extensions
Extension functions for date manipulation.
AppDispatchers
File:common/src/main/java/es/mobiledev/common/util/AppDispatchers.kt:5
Wrapper class for coroutine dispatchers, enabling testability.
Dispatcher for UI operations (Main thread)
Dispatcher for CPU-intensive work
Dispatcher for IO operations (network, database)
Using
AppDispatchers instead of Dispatchers directly allows injecting test dispatchers in unit tests.CommonConstants
CommonAndroid Module
Module:commonAndroid
Package: es.mobiledev.commonandroid
Provides Android-specific base classes, UI components, and utilities.
Base Classes
BaseViewModel
File:commonAndroid/src/main/java/es/mobiledev/commonandroid/ui/base/BaseViewModel.kt:17
Base ViewModel class with built-in state management.
Type parameter for the UI state data
Returns the UI state as a read-only StateFlowReturns:
StateFlow<UiState<T>>Updates the data within the current UI state
Lambda that transforms current state to new state
Sets the UI state to loading
Sets the UI state to success and updates the data
Lambda that transforms current state to new state
UiState
Wrapper class for UI state with loading indicator.The actual UI data
Loading indicator flag
BaseScreen
File:commonAndroid/src/main/java/es/mobiledev/commonandroid/ui/base/BaseScreen.kt:39
Base composable for screens with built-in loading state.
Modifier to be applied to the screen
Whether to show loading indicator
Top app bar content
Bottom bar content
Screen content receiving padding values
- Automatic loading indicator display
- Scaffold-based layout
- Padding management for top/bottom bars
UI Components
ArticleItem
Composable for displaying article list items.CPTButton
Custom styled button component.Utilities
ComposableUtils
IntentUtils
Helper functions for Android intents.TimeUtils
Time formatting and manipulation utilities.Architecture Benefits
- Common Module
- CommonAndroid Module
Platform Agnostic
- No Android dependencies
- Pure Kotlin code
- Reusable across platforms
- Easy to unit test
Dependency Graph
The separation between
common and commonAndroid follows the principle of least dependency. Pure business logic depends only on common, while UI code uses commonAndroid.