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
package library; | |
/** | |
* Created by Prokash Sarkar on March, 2021 | |
* Copyright https://prokashsarkar.com | |
*/ | |
public class CommandLibrary { | |
public static final String KEY_FUNNY = "funny"; | |
public static final String KEY_JOKE = "joke"; |
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
@VisibleForTesting(otherwise = VisibleForTesting.NONE) | |
fun <T> LiveData<T>.getOrAwaitValue( | |
time: Long = 2, | |
timeUnit: TimeUnit = TimeUnit.SECONDS, | |
afterObserve: () -> Unit = {} | |
): T { | |
var data: T? = null | |
val latch = CountDownLatch(1) | |
val observer = object : Observer<T> { | |
override fun onChanged(o: T?) { |
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 MainViewModel( | |
private val dispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
private var _userData: MutableLiveData<Any> = MutableLiveData<Any>() | |
val userData: LiveData<Any> = _userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch(dispatcher) { | |
_userData.value = "some_user_data" |
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 MainViewModel( | |
private val dispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
private var _userData: MutableLiveData<Any> = MutableLiveData<Any>() | |
val userData: LiveData<Any> = _userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch(dispatcher) { | |
_userData.value = "some_user_data" |
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 MainViewModel ( | |
private val dispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
private var userData: Any? = null | |
fun getUserData(): Any? = userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch(dispatcher) { | |
userData = "some_user_data" |
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 MainViewModel : ViewModel() { | |
private var userData: Any? = null | |
fun getUserData(): Any? = userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch(Dispatchers.IO) { | |
userData = "some_user_data" | |
} | |
} |
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 MainViewModel : ViewModel() { | |
private var userData: Any? = null | |
fun getUserData(): Any? = userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch(Dispatchers.IO) { | |
userData = "some_user_data" | |
} | |
} |
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
@ExperimentalCoroutinesApi | |
class MainCoroutineRule : TestWatcher(), TestCoroutineScope by TestCoroutineScope() { | |
override fun starting(description: Description) { | |
super.starting(description) | |
Dispatchers.setMain(this.coroutineContext[ContinuationInterceptor] as CoroutineDispatcher) | |
} | |
override fun finished(description: Description) { | |
super.finished(description) |
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 MainViewModel : ViewModel() { | |
private var userData: Any? = null | |
fun getUserData(): Any? = userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch { | |
userData = "some_user_data" | |
} | |
} |
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 MainViewModel : ViewModel() { | |
private var userData: Any? = null | |
fun getUserData(): Any? = userData | |
suspend fun saveSessionData() { | |
viewModelScope.launch { | |
userData = "some_user_data" | |
} | |
} |
NewerOlder