Appearance
Reactive Plugin - Android SampleApp
Setting up your project
In general, when creating a new project with PlatformHub following a DDD pattern (Domain Driven Design), your project should look like:
.
├── app
│ ├── src / main / assets
│ │ └── app-plugin-policy.json
│ ├── src / main / ...
│ │ ├── AppPlugin
│ │ ├── LaunchActivity
│ │ ├── MainApplication
│ │ └── PlatformHubInitializer
│ └── build.gradle
├── plugin-name-domain
│ ├── src / main / assets
│ │ └── name-domain-plugin-policy.json
│ └── src / main / com / ... / domain / ...
│ └── ...
├── plugin-name-journey
│ ├── src / main / assets
│ │ └── name-journey-plugin-policy.json
│ └── src / main / com / ... / journey / ...
│ └── ...
├── mobile-ci.json
└── build.gradleIt is recommended that you leave the /app module just as a container that initialises the project and handles all dependencies.
The mobile-ci.json file
Update the mobile-ci.json file with the latest PlatformHub version
json
{
"depends": {
"android": [
{
"name": "platformhub",
"version": "<latest-version>"
}
]
}
}Add the gradle dependency of PlatformHubimplementation "com.skyrin.mobilebanking:platformhub:<latest-version>" in your project
The PlatformHubInitializer class
In this file you will initialise all the plugins you need - or eventually create - for your project, as well as set up any optional configuration.
The fact of using Hilt or Dagger annotations in this example is not a requirement.
kotlin
import com.skyrin.mobilebanking.platformhub.PlatformHub
import com.skyrin.mobilebanking.platformhub.PlatformHubInitializer
import com.skyrin.mobilebanking.platformhub.core.Plugin
@Singleton
class PlatformHubInitializer @Inject constructor() {
@Inject
lateinit var platformHub: PlatformHub
@Inject
lateinit var domainPlugin: NameDomainPlugin
@Inject
lateinit var journeyPlugin: NameJourneyPlugin
override val plugins: List<Pair<Plugin, Map<String, InputStream>>>
get() = listOf(
Pair(domainPlugin, emptyMap()),
Pair(journeyPlugin, emptyMap()),
)
fun setup(application: Context) {
platformHub.init(context, this)
}
}Note:
PlatformHub will crash the app on start if something is not set up properly.
The MainApplication class
You will launch the PlatformHubInitializer in your main application class, to ensure it is the first module enabled, so that it can properly coordinate the messaging system.
kotlin
@HiltAndroidApp
class MainApplication : Application() {
@Inject
lateinit var platformHubInitializer: PlatformHubInitializer
override fun onCreate() {
super.onCreate()
//..
platformHubInitializer.setup(this)
}
}The AppPlugin class
This class is a helper that allows the Host App to initially communicate with other plugins.
kotlin
@Singleton
class AppPlugin @Inject constructor(
assetsLoader: AssetsLoader
) : Plugin(assetsLoader) {
private lateinit var context: Context
override val policyFilename: String = POLICY_FILE
override fun init(
context: Context,
configurationFiles: Map<String, InputStream>
) {
this.context = context
}
fun send(navigation: BaseMessage.NavigationQuery) = messageSender.send(navigation, this)
private companion object {
const val POLICY_FILE = "app-plugin-policy.json"
}
}The LaunchActivity class
Here is where you would normally start the Screen your users are going to first see when they open the app.
kotlin
import com.skyrin.mobilebanking.platformhub.microkernel.BaseMessage
import com.skyrin.mobilebanking.platformhub.microkernel.MicroKernel
import com.skyrin.mobilebanking.platformhub.microkernel.NavigationMode
@AndroidEntryPoint
class LaunchActivity : AppCompatActivity() {
@Inject
lateinit var appPlugin: AppPlugin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
val message = BaseMessage.NavigationQuery(
messageName = "NavigateToNameJourneyScreen",
pluginName = "NameJourneyPlugin",
navigationMode = NavigationMode.Activity(this)
)
appPlugin.send(message)
}
}