(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
var mySessionId = 0; | |
// Creates a listener for request status updates. | |
var listener = SplitInstallStateUpdatedListener{ | |
if(it.sessionId() == sessionId){ | |
when(it.status()){ | |
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> { | |
splitInstallManager.startConfirmationDialogForResult(it, activity, HomeActivity.REQUEST_USER_CONFIRMATIOON) | |
} |
// Creates an instance of SplitInstallManager. | |
val splitInstallManager = SplitInstallManagerFactory.create(context) | |
// Creates a request to install a module. | |
val request = | |
SplitInstallRequest | |
.newBuilder() | |
.addModule("helpmodule") | |
.build() |
appUpdateManager | |
.appUpdateInfo | |
.addOnSuccessListener { appUpdateInfo -> | |
... | |
// If the update is downloaded but not installed, | |
// notify the user to complete the update. | |
if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) { | |
popupSnackbarForCompleteUpdate() | |
} |
// Create a listener to track downloading state updates. | |
val listener = InstallStateUpdatedListener { state -> | |
// Update progress indicator, request user to approve app reload | |
if (state.installStatus() == InstallStatus.DOWNLOADING) { | |
// show the progress to the User | |
updateStatetoDownloading() | |
}else if (state.installStatus() == InstallStatus.DOWNLOADED) { | |
// After the update is downloaded, show a notification |
appUpdateManager.startUpdateFlowForResult( | |
// Pass the intent that is returned by getAppUpdateInfo() | |
appUpdateInfo, | |
AppUpdateType.FLEXIBLE, activity, | |
// Include a request code to later monitor this update request. | |
MY_REQUEST_CODE | |
) |
fun onActivityResult(requestCode:Int, resultCode:Int, data:Intent) { | |
if (myRequestCode === MY_REQUEST_CODE){ | |
if (myRequestCode !== RESULT_OK){ | |
log("Update flow failed! Result code: " + resultCode) | |
// If the update is cancelled or fails, | |
// you can request to start the update again. | |
} | |
} | |
} |
appUpdateManager.startUpdateFlowForResult( | |
// Pass the intent that is returned by 'getAppUpdateInfo()'. | |
appUpdateInfo, | |
// Or 'AppUpdateType.FLEXIBLE' for flexible updates. | |
AppUpdateType.IMMEDIATE, | |
// The current activity making the update request. | |
this, |
// Creates instance of the manager. | |
val appUpdateManager = AppUpdateManagerFactory.create(context) | |
// Returns an intent object that you use to check for an update. | |
val appUpdateInfoTask = appUpdateManager.appUpdateInfo | |
// Checks that the platform will allow the specified type of update. | |
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | |
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | |
binding = DataBindingUtil.inflate(inflater, R.layout.your_fragment, container, false) | |
binding.homeAction.setOnClickListener { select(R.id.home_action) } | |
binding.likesAction.setOnClickListener { select(R.id.likes_action) } | |
binding.searchAction.setOnClickListener { select(R.id.search_action) } | |
binding.profileAction.setOnClickListener { select(R.id.profile_action) } | |
return binding.root | |
} | |
fun select(id: Int) { |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.