Skip to content

Instantly share code, notes, and snippets.

Dhruv Taneja dhruvtaneja

  • Uber
  • Bangalore, India
View GitHub Profile
@dhruvtaneja
dhruvtaneja / OnActivityResponseInAppUpdate.kt
Created Jun 5, 2019
Handling user's action in onActivityResult
View OnActivityResponseInAppUpdate.kt
companion object {
private const val REQUEST_CODE_FLEXI_UPDATE = 17362
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_FLEXI_UPDATE) {
when (resultCode) {
Activity.RESULT_OK -> { // handle user's approval }
Activity.RESULT_CANCELED -> { // handle user's rejection }
@dhruvtaneja
dhruvtaneja / build.gradle
Created Jun 5, 2019
Dependency for in-app updates
View build.gradle
dependencies {
implementation 'com.google.android.play:core:1.6.0'
}
@dhruvtaneja
dhruvtaneja / InAppUpdateWithLogs.kt
Created May 29, 2019
in app update activity snippet with lots of logs
View InAppUpdateWithLogs.kt
fun Context.showToast(text: String, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, text, duration).show()
}
override fun onStateUpdate(installState: InstallState) {
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
showToast("download complete", Toast.LENGTH_LONG)
showUpdateSnackbar()
}
}
@dhruvtaneja
dhruvtaneja / InAppUpdateObservable.kt
Created May 29, 2019
In app update check with live data
View InAppUpdateObservable.kt
private fun checkForUpdate() {
appUpdateManager.appUpdateInfo.addOnSuccessListener {
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
updateInfo.value = it
updateAvailable.value = true
} else {
updateInfo.value = null
updateAvailable.value = false
}
View FlexibleUpdate_OnResume.kt
override fun onResume() {
super.onResume()
appUpdateManager.appUpdateInfo.addOnSuccessListener {
if (it.installStatus() == InstallStatus.DOWNLOADED) {
notifyUser()
}
}
}
View MainActivity_InAppUpdates_Listener.kt
class MainActivity : AppCompatActivity(), InstallStateUpdatedListener {
override fun onStateUpdate(installState: InstallState) {
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
notifyUser()
}
}
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@dhruvtaneja
dhruvtaneja / ImmediateUpdate_OnResume.kt
Created May 27, 2019
Handling activity lifecycle during immediate in-app update
View ImmediateUpdate_OnResume.kt
override fun onResume() {
super.onResume()
appUpdateManager.appUpdateInfo.addOnSuccessListener {
if (it.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
appUpdateManager.startUpdateFlowForResult(
it,
AppUpdateType.IMMEDIATE,
this,
REQUEST_CODE_FLEXI_UPDATE
)
@dhruvtaneja
dhruvtaneja / MainActivity_RequestUpdate.kt
Last active May 27, 2019
function that fires up update request flow
View MainActivity_RequestUpdate.kt
private fun requestUpdate(appUpdateInfo: AppUpdateInfo?) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE, // HERE specify the type of update flow you want
this, // the instance of an activity
REQUEST_CODE_FLEXIBLE_UPDATE
)
}
@dhruvtaneja
dhruvtaneja / MainActivity_InAppUpdates.kt
Last active May 27, 2019
Android activity that checks for app updates
View MainActivity_InAppUpdates.kt
class MainActivity : AppCompatActivity() {
private lateinit var appUpdateManager: AppUpdateManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
appUpdateManager = AppUpdateManagerFactory.create(this)
View AppHomeViewModelTest.kt
@Test
fun testIsTodoInHome() {
whenever(firebaseRemoteConfig.getString(AbTestingUtils.FirebaseParamKeys.AB_TEST_HOME_SCREEN_VERSION_ANDROID))
.thenReturn(AbTestingUtils.FirebaseParamValues.HOME_TODO)
assertThat(viewModel.isTodoInHome()).isTrue()
whenever(firebaseRemoteConfig.getString(AbTestingUtils.FirebaseParamKeys.AB_TEST_HOME_SCREEN_VERSION_ANDROID))
.thenReturn(AbTestingUtils.FirebaseParamValues.HOME_DEFAULT)
You can’t perform that action at this time.