Last active
May 11, 2021 11:29
-
-
Save Wottrich/6ea42930968d2782322e038f5df8e4a8 to your computer and use it in GitHub Desktop.
InAppUpdates InAppUpdateViewModel 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 InAppUpdateViewModel( | |
private val inAppUpdateStatusIterator: InAppUpdateStatusIterator | |
) : ViewModel() { | |
private val _inAppUpdateAction = MediatorLiveData<Resource<InAppUpdateStatus>>() | |
fun getAppUpdateActionLiveData(): LiveData<Resource<InAppUpdateStatus>> { | |
if (_inAppUpdateAction.value == null) { | |
checkAvailableVersion() | |
} | |
return _inAppUpdateAction | |
} | |
fun retryCheckAvailableVersion() { | |
checkAvailableVersion() | |
} | |
private fun checkAvailableVersion() { | |
/*_inAppUpdateAction.addResource { | |
inAppUpdateStatusIterator.getInAppUpdateStatus() | |
}Fazer isso é o mesmo que:*/ | |
viewModelScope.launch(/*seu coroutineContext*/) { | |
_inAppUpdateAction.postValue(inAppUpdateStatusIterator.getInAppUpdateStatus()) | |
} | |
} | |
fun isImmediateVersion(): Boolean { | |
val value = _inAppUpdateAction.value?.getOrNull() | |
return (value as? InAppUpdateStatus.AvailableVersionUpdate)?.isImmediate == true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment