-
Notifications
You must be signed in to change notification settings - Fork 127
Creating Custom Use Cases
To create custom use cases in our DHIS2 Android Capture App, follow the steps below:
The best way to implement a new use case is by creating a new Android library module. This module will encapsulate the functionality and can be easily maintained and tested.
- Open your project in Android Studio.
- Go to
File->New->New Module. - Select
Android Libraryand clickNext. - Name your module according to the pattern
customcase-usecase(e.g.,stock-usecase). - Click
Finish.
In your newly created module, add the commons module as a dependency to access the design system, DHIS2 SDK, and other common tools.
-
Open
build.gradle.ktsfile of your new module. -
Add the following line to the dependencies section:
dependencies { implementation(project(":commons")) }
Depending on your Gradle version, you might need to make some configuration adjustments in the build.gradle file. Additionally, if you are using the version catalog, you will need to adjust the configuration accordingly.
This allows you to use resources and tools provided in the commons module.
Now, you can start implementing your use case within the new module. Structure your code following the best practices and utilize the resources from the commons module.
We recommend using the MVVM (Model-View-ViewModel) architecture with Kotlin language and Jetpack Compose. This approach ensures a clean separation of concerns and enhances code maintainability. For more details, refer to the official Android Architecture Guidelines.
Here is an example of the module structure:
-
src/main/java: Contains the Java/Kotlin source files. -
src/main/res: Contains the resources such as layouts, strings, etc. -
src/main/AndroidManifest.xml: The manifest file for the module.
To use your custom use case, add your new module as a dependency in the app module and call the entry point (which can be an Activity or a Composable) from where you would like to start using it.
-
Open
build.gradle.ktsfile of theappmodule. -
Add the following line to the dependencies section:
dependencies { implementation(project(":usecase-module")) } -
Call the entry point in your code:
// Example: Calling an Activity startActivity(Intent(this, YourUseCaseActivity::class.java)) // Example: Calling a Composable setContent { YourUseCaseComposable() }
This modular approach helps to avoid conflicts when updating your project with our new developments. By isolating custom use cases in separate modules, you can independently maintain and update your custom functionalities without interfering with the main project components.