Skip to content

Instantly share code, notes, and snippets.

@hasancse91
Last active December 23, 2023 06:45
Show Gist options
  • Save hasancse91/d7c854ef164ae8558c2750ca24ff2c21 to your computer and use it in GitHub Desktop.
Save hasancse91/d7c854ef164ae8558c2750ca24ff2c21 to your computer and use it in GitHub Desktop.
This is a sample Gist of MainActivity class for Dynamic Feature Module Delivery. Full repository: https://github.com/hasancse91/dynamic-feature-module-android
class MainActivity : ComponentActivity(), DynamicModuleListener {
private val CUSTOMER_SUPPORT_DYNAMIC_MODULE = "customer_support"
private lateinit var dynamicModuleDownloadUtil: DynamicModuleDownloadUtil
private var logState = mutableStateOf("Activity Log:\n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dynamicModuleDownloadUtil = DynamicModuleDownloadUtil(baseContext, this)
// ui codes
}
override fun onDownloading() {
logState.value += "${getCurrentTimestamp()}: Downloading...\n"
}
override fun onDownloadCompleted() {
logState.value += "${getCurrentTimestamp()}: Module download completed.\n"
}
override fun onInstallSuccess() {
logState.value += "${getCurrentTimestamp()}: Module install Success!\n"
startCustomerSupportActivity()
}
override fun onFailed() {
logState.value += "${getCurrentTimestamp()}: Module download or installation failed.\n"
}
private fun openCustomerSupportFeature() {
if (dynamicModuleDownloadUtil.isModuleDownloaded(CUSTOMER_SUPPORT_DYNAMIC_MODULE)) {
logState.value += "${getCurrentTimestamp()}: Module is already downloaded.\n"
startCustomerSupportActivity()
} else {
dialogState.value = true
}
}
private fun startCustomerSupportActivity() {
val intent = Intent()
intent.setClassName(
"com.hellohasan.hasanerrafkhata",
"com.hellohasan.customer_support.CustomerSupportActivity"
)
startActivity(intent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment