onirutlA
03/03/2022, 12:15 PMoverride fun findUserByUsername(username: String): Flow<Resource<List<UserEntity>>> =
localDataSource.findUserByUsername(username).map { fromDb ->
when (fromDb) {
is FromDb.Empty -> {
when (val fromNetwork = remoteDataSource.findUsersByUsername(username)) {
is FromNetwork.Error -> Resource.Error(fromNetwork.message)
is FromNetwork.Success -> {
val userCache = fromNetwork.data.map { it.toEntity() }
localDataSource.insertUsers(userCache)
var userFromDb: Resource<List<UserEntity>> = Resource.Loading()
localDataSource.findUserByUsername(username).collect {
userFromDb = when (it) {
is FromDb.Empty -> Resource.Error(it.message)
is FromDb.Success -> Resource.Success(it.data)
}
}
userFromDb
}
}
}
is FromDb.Success -> Resource.Success(fromDb.data)
}
}.onStart {
Resource.Loading<List<UserEntity>>()
}.flowOn(dispatcher)
Wishnuprathikantam
03/04/2022, 1:43 PMFATAL EXCEPTION: DefaultDispatcher-worker-3
Process: com.myapp, PID: 18030
com.squareup.moshi.JsonDataException: Required value 'fakeParam' missing at $
at com.squareup.moshi.internal.Util.missingProperty(Util.java:660)
at com.myapp.data.models.DeviceInformationJsonAdapter.fromJson(DeviceInformationJsonAdapter.kt:109)
at com.myapp.DeviceInformationJsonAdapter.fromJson(DeviceInformationJsonAdapter.kt:22)
at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:41)
at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:205)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:45)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
Aaron Waller
03/04/2022, 3:40 PMSergio C.
03/04/2022, 4:57 PMclass TimeIterator(
startTime: LocalTime,
private val endTimeInclusive: LocalTime,
private val stepMinutes: Long,
) : Iterator<LocalTime> {
private var currentTime = startTime
override fun hasNext(): Boolean {
return currentTime <= endTimeInclusive
}
override fun next(): LocalTime {
val next = currentTime
currentTime = currentTime.plusMinutes(stepMinutes)
return next
}
}
Vivek Modi
03/04/2022, 9:32 PMopen class Shape {
var data : List<Shape> = emptyList()
}
Three child class which are inherited through Shape class called Circle, Rectangle, Triangle.
I create a variable called
val shape = Shape()
Mahmoud
03/06/2022, 5:15 AMLucca Beurmann
03/07/2022, 1:51 PMVivek Modi
03/07/2022, 5:14 PMTravis Griggs
03/08/2022, 9:06 PMfun drop() {
Plan.modifyRegistry { registry ->
registry.filterKeys { oid -> oid != this.oid }
}
MCCommand.planDrop.oid(oid).sendToMC()
}
Plan objects have an oid
instance variable, and store themselves in a mini companion singleton. I'm sure there are all kinds of counter suggestions for this architecture. I'm hoping we can leave those aside.
Recently, I decided to when-in-rome... and try to embrace implicit this. I let someone go through and "clean up" all of the redundant this's. And so this code got changed:
fun drop() {
Plan.modifyRegistry { registry ->
registry.filterKeys { oid -> oid != oid }
}
MCCommand.planDrop.oid(oid).sendToMC()
}
And suddenly the drop
method went from removing itself, to cleaning the whole registry. I'm not sure what the point is, but I guess I'm surprised that the way that Kotlin plays fast and furious with variable name bindings doesn't cause others more issues like this. It certainly makes it harder for me to want to let go of explicit this.Android75
03/10/2022, 5:34 AMNikolay Vlaskin
03/10/2022, 12:37 PMVivek Modi
03/10/2022, 9:07 PMdata class Price(
var value: String? = null
)
main.kt
val defaultValue : Double = 4.23
val list = listOf(Price("2.33"), Price("fr23"), Price(""), Price(null), Price("4.23"), Price("12.23"))
list.forEach{
if(it == defaultValue){
println("Found It")
}
}
Breaker ACT
03/11/2022, 3:45 PMfun hello(block: (String) -> Unit) {
//1. block()
//2 block.invoke()
}
Breaker ACT
03/11/2022, 3:59 PMKotlin syntaxI am reading sample Clean Architecture code of Fernando Cejas. He implement as the images, how you think about this approach ? The pros: We can invoke the interface/abstract class which has been injected like a function call Ref
Enrico Saggiorato
03/12/2022, 10:08 AMfailed to connect to localhost/127.0.0.1:8080
when usins "http://localhost:8080" as the base URL. How do I setup the thing?Chih Wei Lin
03/12/2022, 4:53 PMKiprop Victor
03/13/2022, 7:13 AMExecution failed for task ':buildSrc:compileKotlin'.
with the following stack trace. I have matched the Kotlin version in the IDE with the project, what can cause this?Mehdi Haghgoo
03/13/2022, 3:12 PMStefMa
03/14/2022, 1:55 PMsrc/kotlin
instead of src/java
?
Or doesn’t it matter? Just a matter of style…?!Andra Antariksa
03/14/2022, 3:59 PMVivek Modi
03/14/2022, 4:34 PMval string = "2.2"
I want to show in textview like 2.2
. But if my string is 2.00
it will show 2
in my textview. How can I do this in kotlin efficient way?Vladimir Tagakov
03/16/2022, 1:12 AMfun fact(): Observable<Any> = Observable.just(false)
.distinctUntilChanged() // fails compilation
vs
fun fact(): Observable<Any> = Observable.just(false)
//.distinctUntilChanged() // compiles just fine
andodeki
03/16/2022, 8:36 AMandodeki
03/16/2022, 12:23 PMChris Johnson
03/16/2022, 8:48 PMAli
03/16/2022, 9:46 PMDecimalFormat.getIntegerInstance(new Locale("ar")).format(number);
But this is not working
DecimalFormat.getIntegerInstance(new Locale("bn")).format(number);
I can see arabic
number properly but for bangla
its not workingTash
03/16/2022, 10:56 PMwebView.goBackward()/webView.goForward()
, how do you encode them as state? They’re very event-like and need to happen just once given certain conditions, and could get complicated when state objects are `data class`es and you use .copy
to update parts of state. More in 🧵rkeazor
03/18/2022, 3:28 AMAbhilash
03/18/2022, 9:29 AMhaoxiqiang
03/18/2022, 10:48 AM@Parcelize
data class Post(
@SerializedName("topic_list")
val topics: MutableList<Topic> = mutableListOf(),
@SerializedName("tag_list")
val tagList: MutableList<PostTag> = mutableListOf()
)
I build a android project with the kotlin-parcelize, if json with out topic_list/tag_list, I think it will be the default value which two empty list.
but in last week. it’s generate by kapt without default value.
after decompile:
@SerializedName("media_list")
@NotNull
private List<Media> mediaList;
Why….😅haoxiqiang
03/18/2022, 10:48 AM@Parcelize
data class Post(
@SerializedName("topic_list")
val topics: MutableList<Topic> = mutableListOf(),
@SerializedName("tag_list")
val tagList: MutableList<PostTag> = mutableListOf()
)
I build a android project with the kotlin-parcelize, if json with out topic_list/tag_list, I think it will be the default value which two empty list.
but in last week. it’s generate by kapt without default value.
after decompile:
@SerializedName("media_list")
@NotNull
private List<Media> mediaList;
Why….😅Tim Oltjenbruns
03/18/2022, 12:25 PMhaoxiqiang
03/18/2022, 12:30 PMTim Oltjenbruns
03/18/2022, 12:44 PMhaoxiqiang
03/21/2022, 9:54 AM// is OK
data class A (
@SerializedName(“a”)
val a:String=“”,
@SerializedName(“b”)
val b:Int=0
)
// is Failed
data class A (
@SerializedName(“a”)
val a:String,
@SerializedName(“b”)
val b:Int=0
)