Last active
May 11, 2021 11:20
-
-
Save Wottrich/ad958a9cc56a7d70ee4073be843c0056 to your computer and use it in GitHub Desktop.
InAppUpdates AppUpdateInfoWrapper pt1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppUpdateInfoWrapper(context: Context) { | |
private val appUpdateManager: AppUpdateManager = AppUpdateManagerFactory.create(context) | |
private var appUpdateInfo: AppUpdateInfo? = null | |
suspend fun getAppUpdateInfo(): Resource<AppUpdatePertinentInfo> { | |
return suspendCancellableCoroutine { continuation -> | |
//Pegando o AppUpdateInfoTask | |
val appUpdateInfoTask = appUpdateManager.appUpdateInfo | |
//Esperando o retorno no listener de sucesso | |
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | |
this@AppUpdateInfoWrapper.appUpdateInfo = appUpdateInfo | |
//AppUpdatePertinentInfo usado para pegarmos apenas o que precisamos | |
continuation.resume(Resource.success(AppUpdatePertinentInfo(appUpdateInfo))) | |
} | |
//Esperando o retorno no listener de erro | |
appUpdateInfoTask.addOnFailureListener { | |
continuation.resume(Resource.error(it)) | |
} | |
}//suspendCancellableCoroutine | |
}//getAppUpdateInfo | |
}//AppUpdateInfoWrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment