Class HeadModule
-
- All Implemented Interfaces:
public abstract class HeadModuleMain class to crate a Module for Hydra
Don't modify this code, the main app and the module need to have exactly the same library implementation in order to work, in the same way you can only implement an specific list of libraries, the main app needs to have a copy of that library in order to work.
TODO: Add compatible libraries list
The modules are limited in the permission they can declare, if the main app detects any other permission besides those, the module will be ignored, the admitted permissions are:
android.permission.INTERNET
android.permission.ACCESS_WIFI_STATE
To create a module you need to create a new Application project, once created you need to create a class named Module that extends HeadModule, because the core is based in abstract implementation the minimum required functions needs to be overridden, the other overridable functions are optional (i.e., the main app will try to use the functions, but if the module doesn't implement them or any of them fail/crash it will adapt the UI to hide the related elements).
The name of the application doesn't need any requirements, but it can be a little descriptive for the users (e.g., Hydra Module: My module name) in case of a manual uninstall, the app won't use this name internally, instead it will use the name provided in the moduleName implementation.
<b>Sample usage</b>
class Module: HeadModule() { override val moduleVersionCode: Int = BuildConfig.VERSION_CODE override val moduleVersionName: String = BuildConfig.VERSION_NAME override val baseUrl: String = "https://empty.com" override val moduleName: String = "Test Module" override val dataRepository: HeadRepository = Repository() override val config: HeadConfig = TestConfig() }
-
-
Field Summary
Fields Modifier and Type Field Description private final IntegermoduleVersionCodeprivate final StringmoduleVersionNameprivate final StringbaseUrlprivate final StringmoduleNameprivate final HeadRepositorydataRepositoryprivate final HeadConfigconfig
-
Constructor Summary
Constructors Constructor Description HeadModule()
-
Method Summary
Modifier and Type Method Description abstract IntegergetModuleVersionCode()abstract StringgetModuleVersionName()abstract StringgetBaseUrl()abstract StringgetModuleName()abstract HeadRepositorygetDataRepository()abstract HeadConfiggetConfig()UnitonModuleInitialize()This method is called the first time the module is initialized, here you can get/create internal databases using createRoomDatabase. final <T extends RoomDatabase> RoomDatabase.Builder<T>createRoomDatabase(String name, KClass<T> clazz)Create or get a RoomDatabase, it will be created in the Main app storage and will persist if the module is uninstalled, we suggest to put the database reference inside an object for easier access through the module, this method can only be used inside of onModuleInitialize. -
-
Method Detail
-
getModuleVersionCode
abstract Integer getModuleVersionCode()
-
getModuleVersionName
abstract String getModuleVersionName()
-
getBaseUrl
abstract String getBaseUrl()
-
getModuleName
abstract String getModuleName()
-
getDataRepository
abstract HeadRepository getDataRepository()
-
getConfig
abstract HeadConfig getConfig()
-
onModuleInitialize
Unit onModuleInitialize()
This method is called the first time the module is initialized, here you can get/create internal databases using createRoomDatabase.
-
createRoomDatabase
final <T extends RoomDatabase> RoomDatabase.Builder<T> createRoomDatabase(String name, KClass<T> clazz)
Create or get a RoomDatabase, it will be created in the Main app storage and will persist if the module is uninstalled, we suggest to put the database reference inside an object for easier access through the module, this method can only be used inside of onModuleInitialize.
- Parameters:
name- The name of the database, the package name of the Module is used to create an unique nameclazz- The class of the Database- Returns:
The reference of the created/gotten Database
-
-
-
-