Skip to content

Instantly share code, notes, and snippets.

View savvisingh's full-sized avatar
🏠
Working from home

Sarabjeet Singh savvisingh

🏠
Working from home
View GitHub Profile
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
@savvisingh
savvisingh / YourFragment.kt
Created February 27, 2019 05:35 — forked from rylexr/YourFragment.kt
Android navigation bar style with animation
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) {
@savvisingh
savvisingh / introrx.md
Created May 15, 2017 04:04 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing