Fixed
Status Update
Comments
fi...@gmail.com <fi...@gmail.com> #2
cy...@zen.ly <cy...@zen.ly> #3
> We accept pull requests! :)
Is there a public repo somewhere? I don't see any obvious repo for it inhttps://android.googlesource.com , and it doesn't seem to be inside https://android.googlesource.com/platform/frameworks/support .
Room supports final fields (yay!), which probably will suffice for many people with respect to this feature request.
Is there a public repo somewhere? I don't see any obvious repo for it in
Room supports final fields (yay!), which probably will suffice for many people with respect to this feature request.
fi...@gmail.com <fi...@gmail.com> #4
Room supports immutability (it can use arg constructors) but does not directly support AutoValue. It is in the schedule but not high priority :/. Idk much about its internals at this stage so I'm not sure how we would implement it but should be totally doable.
Sorry we don't have the source release yet :/.
Sorry we don't have the source release yet :/.
fi...@gmail.com <fi...@gmail.com> #5
"It is in the schedule but not high priority" -- completely understandable.
"Sorry we don't have the source release yet :/." -- ah, OK, I thought perhaps with the pull request comment, that meant that there was a repo somewhere that I had overlooked.
Thanks!
"Sorry we don't have the source release yet :/." -- ah, OK, I thought perhaps with the pull request comment, that meant that there was a repo somewhere that I had overlooked.
Thanks!
se...@gmail.com <se...@gmail.com> #6
Add autovalue support also means you can easily achieve parcelable by https://github.com/rharter/auto-value-parcel . Please consider support this.
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com> #7
AutoValue is really a handy way to ensure data integrity.
ap...@google.com <ap...@google.com> #8
Please add AutoValue support. AutoValue is a Google library with really good benefits such as toString() , hashCode() , AutoValue.Builder , checks at creation time if @NonNull values are null, etc.
fi...@gmail.com <fi...@gmail.com> #9
FWIW, issue 64206877 is not publicly accessible.
yb...@google.com <yb...@google.com> #10
@Yigit: That appears to be a private ticket. Any way we can have access to keep up with it?
ap...@google.com <ap...@google.com> #11
Have any updates?
yb...@google.com <yb...@google.com>
fi...@gmail.com <fi...@gmail.com> #12
news?
sa...@gmail.com <sa...@gmail.com> #13
Is there any update? This is huge for app that absolutely enforces immutable entities.
yb...@google.com <yb...@google.com> #14
SqlDelight has out of the box support for AutoValue. Use it with SqlBrite and you've got *pretty good* parity with Room. With the lack of movement on this ticket, I'd suggest at least taking a look at those if AutoValue is important to you.
Description
I'm testing it on String items so it shouldn't be related to my own recycler implementation.
I've created simple Instrumented Test that is failing on mentioned case:
#####################################
package com.example.diffutilbug
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import junit.framework.Assert.assertTrue
import kotlinx.coroutines.*
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.BlockJUnit4ClassRunner
@RunWith(BlockJUnit4ClassRunner::class)
internal class ExampleUnitTest {
@Test
fun testDiffUtil4() {
val handler = CoroutineExceptionHandler { _, exception ->
throw exception
}
// adapter compare items :
// areItemsTheSame -> compare length of String
// areContentsTheSame -> compare content with ==
val adapter = StringAdapterJunit(handler)
runBlocking {
adapter.submitList(
mutableListOf<String>(
"1",//1,
"22",//2,
"333",//3,
"4444",//4,
"55555",//5,
"666666",//6,
"7777777",//7,
"88888888",//8,
"999999999",//9,
"55555",//5,
"1010101010",//10,
"1010109999",//10,
"55555",//5,
"1313131313",//10,
"1414141414",//10,
"55555",//5,
"1313131313",//10,
"1414141414",//10,
"55555"//5
)
)
delay(40)
adapter.submitList(
mutableListOf<String>(
"55555",//5,
"1010101010",//10,
"1010109999",//10,
"55555",//11,
"1313131313",//10,
"1414141414",//10,
"11111111111"//11
)
)
delay(500)
}
}
}
// Stub Adapter for Strings that uses DiffUtil underneath.
// logs all callbacks to logcat
class StringAdapterJunit(val handler: CoroutineExceptionHandler) : ListAdapter<String, RecyclerView.ViewHolder>(object : DiffUtil.ItemCallback<String>() {
override fun areItemsTheSame(oldItem: String, newItem: String): Boolean {
Log.e("DiffUtilTest", "areItemsTheSame comparing $oldItem with $newItem = ${oldItem.length == newItem.length}")
return oldItem.length == newItem.length
}
override fun areContentsTheSame(oldItem: String, newItem: String): Boolean {
//should be called only if areContentsTheSame == true
Log.e(
"DiffUtilTest",
"areContentsTheSame error = ${oldItem.length != newItem.length} comparing $oldItem with $newItem"
)
runBlocking {
GlobalScope.launch(handler + Dispatchers.Main) {
assertTrue("areContentsTheSame can be called only if areItemsTheSame return true" , areItemsTheSame(oldItem, newItem))
}.join()
}
return oldItem == newItem
}
override fun getChangePayload(oldItem: String, newItem: String): Any? {
//should be called only if areItemsTheSame = true and areContentsTheSame = false
Log.e(
"DiffUtilTest",
"getChangePayload error = ${oldItem.length == newItem.length && oldItem == newItem} $oldItem with $newItem"
)
return null
}
}) {
// stub implementation on adapter - never used
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = object : RecyclerView.ViewHolder(View(null)) {}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {}
override fun getItemViewType(position: Int): Int = getItem(position).length
}
#####################################
and gradle dependencies needed for it:
dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
//coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}
#####################################
please note that you need to add
android.useAndroidX=true
android.enableJetifier=true
in your gradle.properties
coroutines and handler for exceptions added because DiffUtil computes diff on background thread and JUnit handles assertion only on main thread