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
SwipeToDeleteItem( | |
onDeleteItem = { onDeleteTask(task) }, | |
onBackground = { state -> BackgroundSwipeToDeleteItem(state) }, | |
onDismissContent = { | |
TaskItem( | |
task = task, | |
showDeleteItem = showDeleteItem, | |
onCheckChange = onCheckChange, | |
onDeleteTask = onDeleteTask | |
) |
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
/** | |
* Used as a wrapper for data that is exposed via a LiveData that represents an event. | |
*/ | |
open class Event<out T>(private val content: T) { | |
@Suppress("MemberVisibilityCanBePrivate") | |
var hasBeenHandled = false | |
private set // Allow external read but not write | |
/** |
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
import androidx.annotation.MainThread | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.Observer | |
import java.util.concurrent.atomic.AtomicBoolean | |
class SingleLiveEvent<T> : MutableLiveData<T> { | |
constructor() : super() | |
constructor(initialValue: T) : super(initialValue) |
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 LauncherActivity : AppCompactActivity() { | |
private val inAppUpdateViewModel by viewModel<InAppUpdateViewModel>() | |
private val appUpdateInfoProvider by inject<AppUpdateInfoWrapper>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
//Essa feature não funciona em DEBUG, | |
//então precisamos fazer isso para conseguir utilizar o ambiente de dev | |
if (BuildConfig.DEBUG) { |
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
val playCoreModule = module { | |
single { AppUpdateInfoWrapper(androidContext()) } | |
single<AppUpdateInfoDefinitions> { AppUpdateInfoDefinitionsImpl() } | |
factory<InAppUpdateStatusIterator> { InAppUpdateStatusIteratorImpl(get(), get()) } | |
viewModel { InAppUpdateViewModel(get()) } | |
} |
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() | |
} |
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> { | |
//... | |
} | |
@Throws(IllegalStateException::class) |
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 InAppUpdateStatusIteratorImpl( | |
appUpdateInfoWrapper: AppUpdateInfoWrapper, | |
definitions: AppUpdateInfoDefinitions | |
) : InAppUpdateStatusIterator(appUpdateInfoWrapper, definitions) { | |
override fun getSuccessInAppUpdateStatus(definitions: AppUpdateInfoDefinitions): InAppUpdateStatus { | |
return when { | |
//Utilizamos shouldNotifyUpdateVersion para saber se precisamos notificar uma atualização | |
definitions.shouldNotifyUpdateVersion() -> getAvailableVersionUpdate(definitions) | |
else -> InAppUpdateStatus.NoNeedUpdate |
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
abstract class InAppUpdateStatusIterator( | |
private val appUpdateInfoWrapper: AppUpdateInfoWrapper, | |
private val definitions: AppUpdateInfoDefinitions | |
) { | |
suspend fun getInAppUpdateStatus(): Resource<InAppUpdateStatus> { | |
val resourceDefinitions = appUpdateInfoWrapper.getAppUpdateInfo().mapNotNull { appUpdatePertinentInfo -> | |
definitions.apply { | |
setupAppUpdatePertinentInfo(appUpdatePertinentInfo) | |
} |
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 AppUpdateInfoDefinitionsImpl : AppUpdateInfoDefinitions() { | |
override fun shouldNotifyUpdateVersion() = | |
(hasUpdateAvailable() && !isNoNotifyUpdateVersion()) | |
private fun hasUpdateAvailable() = /*UpdateAvailability.UPDATE_AVAILABLE*/ | |
appUpdatePertinentInfo?.updateAvailability() == appUpdatePertinentInfo?.updateAvailableValue | |
private fun isNoNotifyUpdateVersion() = | |
appUpdatePertinentInfo?.updatePriority() == NO_NOTIFY |
NewerOlder