Last active
May 2, 2019 02:50
-
-
Save cdmunoz/8db036128c85d49ba79572126a8fe959 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AuctionsCreationViewModel : ViewModel(), CoroutineScope { | |
private var auction: MutableLiveData<Auction> = MutableLiveData() | |
private var auctionCreationRepository = AuctionCreationRepository() | |
private var onClickSaveTrigger = SingleLiveEvent<Unit>() | |
private val job = Job() | |
override val coroutineContext: CoroutineContext | |
get() = job + Dispatchers.Main | |
fun getAuction() = auction | |
fun queryAuctionById(auctionId: Long) { | |
val auctionQueried = auctionCreationRepository.getAuctionById(auctionId) | |
//other logic regarding auction object | |
auction.value = auctionQueried | |
} | |
fun saveAuction(auction: Auction) { | |
launch(Dispatchers.Main) { | |
withContext(Dispatchers.IO) { auctionCreationRepository.save(mutableListOf(auction)) } | |
} | |
} | |
override fun onCleared() { | |
job.cancel() | |
} | |
fun getOnClickSaveTrigger(): SingleLiveEvent<Unit> { | |
return onClickSaveTrigger | |
} | |
fun onClickSaveEvent() { | |
onClickSaveTrigger.call() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment