Napa Ram
10/19/2021, 12:15 PM慧斌
10/20/2021, 6:40 AMtypealias HttpCall<T> = suspend () -> Response<HttpResult<T>>
suspend fun <T> HttpCall<T>.doTransform(): Try<T> {
return try {
invoke().run {
if (isSuccessful && body()?.statusCode == 200) {
Right(body()!!.result)
} else {
Left(Exception(body()?.message))
}
}
} catch (e: Exception) {
Left(e)
}
}
//getToken is a REST API by retrofit
val httpCall: HttpCall<AuthenticationToken> = { service.getToken(params) }
httpCall.doTransform() // OK
{ service.getToken(params) }.doTransform() // failure
Sergio C.
10/20/2021, 11:06 AMSergio C.
10/20/2021, 5:07 PMSergio C.
10/20/2021, 5:51 PMCharles Jo
10/20/2021, 8:58 PMxxfast
10/21/2021, 12:12 AMWorkManager
’s `CoroutineWorker`s, is there a way to run clean up work during onStopped()
? looks like this is marked as final
in the implementation for some reasonFernando de Paula
10/21/2021, 2:18 AMInk
10/21/2021, 10:18 AMenum class ScreenState(val error: ErrorAlertType? = null) {
LOADING, ERROR, OK
}
enum class ErrorAlertType {
CONNECTION, UNKNOWN
}
and then
val state = ScreenState.ERROR(ErrorAlertType.UNKNOWN)
How I can define my ScreenState
to get optional parameter for ERROR
state?Sergio C.
10/21/2021, 4:54 PMSusheel
10/21/2021, 10:46 PMval category = mock(Category::class.java)
where Category is the enum. And when I run the test I'm seeing a NoClassDefFoundError
I already added the mock-maker-inline file but any thoughts on what I'm doing wrong here?Kwangjo Lee
10/22/2021, 11:20 AMraghunandan
10/22/2021, 5:13 PMMarko Novakovic
10/23/2021, 2:14 PMViewModel
that exposes state with StateFlow
. I want to test that it emits Loading
state and than starting data fetching process from init
block. when I provide fake API I can’t catch Loading
state because data is fetched immediately and Success
state is emitted. how to test that Loading
comes first followed by Success
?Josefsidhd
10/24/2021, 9:26 AMSergio C.
10/24/2021, 3:29 PMFrancisco
10/25/2021, 4:09 AMdata class Item(val a: String, val b: String)
My problems comes trying to create a DiffCallback:
If I use oldItem == newItem on itemsAreTheSame
, this is going to return true on items that are not the same, for instance, the first two on the following list:
Item("a", "a")
Item("a", "a")
Item("b", "b")
As long as an operation doesn't involve items with the same content, everything works fine: animations, add, edit, move, delete. But this gets buggy when items are equal. If I delete the second item, the first one will also be deleted. If I add or move something, the animation is wrong, kind of reversed.
What I wanted to know is if there's any other way to handle something like this, without adding an identifier, nor using a custom differ without ListAdapter.kierans777
10/25/2021, 4:32 AMmaxmello
10/25/2021, 7:28 AMviewModelScope
and lifecycleScope
both run on the Main Dispatcher. All the official and unofficial examples of these scopes together with a StateFlow
or SharedFlow
show this:
.stateIn(viewModelScope, ...) or .sharedIn(viewModelScope, ...)
. But this means that all the calculations (for example when using combine
) then run on the main thread. Wouldn’t the better default be to always run SharedFlow
and StateFlow
in viewModelScope + Dispatchers.Default
? When collecting the flow, it will run in another coroutine anyway, and UI operations can be done on the Main dispatcher.Shreyas Patil
10/25/2021, 3:15 PMAshu
10/26/2021, 7:58 AM{SomeObject} is {SomeClass}
as a parameter? I am trying to perform type checking inside a function where the type to check for meeds to be passed as an argument. Any way to achieve this?Farid Mrz
10/26/2021, 2:21 PMNoel Stieglitz
10/26/2021, 2:54 PMzain
10/27/2021, 2:24 PMplayers.filter {
it.pStatus != "E" && it.pStatus != "I" && it.pStatus != "S" && it.pStatus != "D" && it.pStatus != "R" && it.pStatus != "NIS"
}
William Reed
10/27/2021, 5:05 PMvalue class
, can I send it through a bundle as the type of it’s backing field? or do i need the class to be Parcelable
?tateisu
10/27/2021, 10:23 PMMd. Nazmun Sadat Khan
10/28/2021, 5:01 AMzain
10/28/2021, 5:41 AMplayers.groupBy {
it.skill
}
Graeme Laws
10/28/2021, 10:04 AMundermark5
10/28/2021, 8:41 PMfun onFinishedProcessingEvent(event: FinishedProcessing) {
when (event) {
is FinishedProcessingSuccessfully -> {
onAuthenticationSuccess()
}
is FinishedProcessingUnsuccessfully -> {
onAuthenticationFailure(event)
}
}
}
where FinishedProcessing
is defined as follows
sealed class FinishedProcessing(val status: String)
class FinishedProcessingSuccessfully(status: String = "success"): FinishedProcessing(status)
class FinishedProcessingUnsuccessfully(error: String) : FinishedProcessing(error)
Intellisense in Android Studio (Android Studio Arctic Fox | 2020.3.1 Patch 3) is suggesting that I make the when exhaustive by adding an else
branch because I’m using a sealed class. However, as far as I can tell, this should be exhaustive without the else, or is there something I’m missing?