Florian
10/27/2020, 9:33 AMtry/catch
🤔?Hamza GATTAL
10/27/2020, 3:40 PMcoroutinedispatcher
10/27/2020, 3:50 PMSharedFlow
in Android:
https://coroutinedispatcher.com/posts/shared-flow/R Brian Amesbury
10/27/2020, 4:56 PMallan.conda
10/27/2020, 11:06 PM/**
* Convenience property delegate for accessing and setting the live data value
*/
class LiveDataDelegate<T> : MutableLiveData<T> {
constructor(value: T) : super(value)
constructor() : super()
operator fun getValue(thisRef: Any?, property: KProperty<*>): T? = value
operator fun setValue(thisObj: Any?, property: KProperty<*>, value: T?) {
this.value = value
}
}
So then I could do:
// In Some ViewModel
private val stateDelegate = LiveDateDelegate(SomeState())
private var _state by stateDelegate
private val state: LiveData<SomeState>
get() = _state
fun onSomeUserEvent() {
// no need to call state.value
_state = _state.copy(
// update the state
)
}
Opinions are welcomeNathan Retta
10/28/2020, 4:21 AMSomeViewModel: ViewModel(), LifecycleObserver {
init {
viewModelScope.launch { databaseStuff() }
}
suspend fun databaseStuff() =
liveData {
emit(ViewState.Loading)
emit(retrieveDataUseCase.getDatabaseStuff().fold({
ViewState.Error
}, {
if (it.retrievedFromDatabase) {
ViewState.ReadFromDatabase(it)
} else {
ViewState.SuccessfulFetch(it)
}
}))
}
}
}
SomeFragment: Fragment() {
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
viewModel.databaseStuff().observe(viewLifecycleOwner, {
renderState(it)
})
}
}
Correct behavior:
SomeOtherViewModel: ViewModel(), LifecycleObserver {
init {
viewModelScope.launch { databaseStuff() }
}
val myLiveData: LiveData<Item>
get() = _myLiveData
private val _myLiveData = MutableLiveData<Item>()
@ExperimentalCoroutinesApi
suspend fun databaseStuff() =
retrieveDataUseCase.itemFlow().collect {
_myLiveData.value = it
}
}
}
SomeOtherFragment: Fragment() {
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
viewModel.myLiveData.observe(viewLifecycleOwner, {
renderState(ViewState.SuccessfulFetch(it))
})
}
}
Anybody know why the first case queries the database upon screen rotation, while the second does not? Thanks!Jan
10/28/2020, 7:40 AMRemy Benza
10/28/2020, 8:36 AMMarko Gajić
10/28/2020, 2:17 PMJay Ademola
10/28/2020, 2:31 PMRyan
10/28/2020, 5:07 PMSpencer Stock
10/28/2020, 8:44 PMSlackbot
10/29/2020, 1:25 AMvapoyan
10/29/2020, 8:46 AMPcorbella
10/29/2020, 9:33 AMShreyas Patil
10/29/2020, 12:52 PMAriel Bogdziewicz
10/29/2020, 1:10 PMLocale
in Android.Ömer Ateş
10/29/2020, 2:56 PMMikael Alfredsson
10/29/2020, 7:57 PMCorey Lanier
10/29/2020, 11:26 PMFlorian
10/31/2020, 10:46 AMRăzvan Roșu
11/02/2020, 11:16 AMinterface TasksDataSource {
fun getTasks(forceUpdate: Boolean): Single<List<Task>> {
if (forceUpdate) refreshTasks()
return getTasks()
}
fun getTasks(): Single<List<Task>>
...
}
I have this issue when I try to implement it:Doru N.
11/02/2020, 11:07 PMColton Idle
11/03/2020, 12:00 AMkvs
11/03/2020, 6:54 AMkvs
11/03/2020, 6:56 AMahmad abas
11/03/2020, 7:03 AMbobby
11/03/2020, 7:57 AMloadUrl()
instead of evaluateJavascript()
to call a javascript function from a Webview? My target device is 23+
From what I see in the documentation is that you should use evaluateJavascript()
to call javascript function if the device KitKat+, the loadUrl()
is for older device. The reason why I don't want to use evaluateJavascript()
is because it's run asynchronously, which is not what I want.
I had seek for the answers online but I still don't get it.
Thanks for helping!Muhammad Usman
11/03/2020, 10:12 AMSamuele Pontremoli
11/03/2020, 10:44 AM