From 6a29e7d381803abe9772c983231fe255bc987f76 Mon Sep 17 00:00:00 2001 From: Chesire Date: Sat, 29 May 2021 20:35:39 +0100 Subject: [PATCH] fix: use a LiveEvent instead of Livedata for api result (#151) Use LiveEvent so it only occurs once, this stops the livedata firing a second time if navigating between the settings and pusher view. --- feature/pusher/build.gradle.kts | 1 + .../main/java/com/chesire/pushie/pusher/PusherViewModel.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/feature/pusher/build.gradle.kts b/feature/pusher/build.gradle.kts index a24eac96..51e088ba 100644 --- a/feature/pusher/build.gradle.kts +++ b/feature/pusher/build.gradle.kts @@ -37,6 +37,7 @@ dependencies { implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1") implementation("com.chesire.lintrules:lint-gradle:1.2.6") implementation("com.chesire.lintrules:lint-xml:1.2.6") + implementation("com.github.hadilq:live-event:1.2.3") implementation("com.google.android.material:material:1.3.0") implementation("com.squareup.okhttp3:okhttp:4.9.1") diff --git a/feature/pusher/src/main/java/com/chesire/pushie/pusher/PusherViewModel.kt b/feature/pusher/src/main/java/com/chesire/pushie/pusher/PusherViewModel.kt index e3a419ff..dd5fd8c0 100644 --- a/feature/pusher/src/main/java/com/chesire/pushie/pusher/PusherViewModel.kt +++ b/feature/pusher/src/main/java/com/chesire/pushie/pusher/PusherViewModel.kt @@ -1,9 +1,9 @@ package com.chesire.pushie.pusher import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.hadilq.liveevent.LiveEvent import kotlinx.coroutines.launch /** @@ -14,7 +14,7 @@ class PusherViewModel( private val clipboardInteractor: ClipboardInteractor ) : ViewModel() { - private val _apiState = MutableLiveData() + private val _apiState = LiveEvent() /** * The current state of the api request.