diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/ServiceSessionItem.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/ServiceSessionItem.kt index 2b41fae0f..bcee9b8be 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/ServiceSessionItem.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/ServiceSessionItem.kt @@ -5,6 +5,7 @@ import androidx.navigation.NavDirections import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.xwray.groupie.databinding.BindableItem +import io.github.droidkaigi.confsched2019.item.EqualableContentsProvider import io.github.droidkaigi.confsched2019.model.ServiceSession import io.github.droidkaigi.confsched2019.model.defaultLang import io.github.droidkaigi.confsched2019.session.R @@ -19,7 +20,7 @@ class ServiceSessionItem @AssistedInject constructor( val sessionContentsActionCreator: SessionContentsActionCreator ) : BindableItem( session.id.hashCode().toLong() -), SessionItem { +), SessionItem, EqualableContentsProvider { val serviceSession get() = session @AssistedInject.Factory @@ -63,18 +64,13 @@ class ServiceSessionItem @AssistedInject constructor( override fun getLayout(): Int = R.layout.item_service_session - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as ServiceSessionItem + override fun providerEqualableContents(): Array<*> = arrayOf(session) - if (session != other.session) return false - - return true + override fun equals(other: Any?): Boolean { + return isSameContents(other) } override fun hashCode(): Int { - return session.hashCode() + return contentsHash() } } diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeakerItem.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeakerItem.kt index 0e64c402f..7f59272f6 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeakerItem.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeakerItem.kt @@ -8,6 +8,7 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.picasso.Picasso import com.xwray.groupie.databinding.BindableItem +import io.github.droidkaigi.confsched2019.item.EqualableContentsProvider import io.github.droidkaigi.confsched2019.model.Speaker import io.github.droidkaigi.confsched2019.session.R import io.github.droidkaigi.confsched2019.session.databinding.ItemSpeakerBinding @@ -18,7 +19,8 @@ class SpeakerItem @AssistedInject constructor( @Assisted val clickNavDirection: NavDirections, @Assisted val query: String?, val navController: NavController -) : BindableItem(speaker.id.hashCode().toLong()) { +) : BindableItem(speaker.id.hashCode().toLong()), + EqualableContentsProvider { @AssistedInject.Factory interface Factory { fun create( @@ -64,19 +66,17 @@ class SpeakerItem @AssistedInject constructor( } } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as SpeakerItem + override fun providerEqualableContents(): Array<*> = arrayOf(speaker) - if (speaker != other.speaker) return false - if (query != other.query) return false + override fun isTextHighlightNeedUpdate() = query?.let { + speaker.name.toLowerCase().contains(it.toLowerCase()) + } ?: false - return true + override fun equals(other: Any?): Boolean { + return isSameContents(other) } override fun hashCode(): Int { - return speaker.hashCode() + query.hashCode() + return contentsHash() } } diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeechSessionItem.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeechSessionItem.kt index e99fbd912..9c06e84fb 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeechSessionItem.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/SpeechSessionItem.kt @@ -18,6 +18,7 @@ import com.squareup.inject.assisted.AssistedInject import com.squareup.picasso.Picasso import com.squareup.picasso.Target import com.xwray.groupie.databinding.BindableItem +import io.github.droidkaigi.confsched2019.item.EqualableContentsProvider import io.github.droidkaigi.confsched2019.model.Speaker import io.github.droidkaigi.confsched2019.model.SpeechSession import io.github.droidkaigi.confsched2019.model.defaultLang @@ -40,7 +41,7 @@ class SpeechSessionItem @AssistedInject constructor( val sessionContentsActionCreator: SessionContentsActionCreator ) : BindableItem( session.id.hashCode().toLong() -), SessionItem { +), SessionItem, EqualableContentsProvider { val speechSession get() = session @AssistedInject.Factory @@ -199,19 +200,24 @@ class SpeechSessionItem @AssistedInject constructor( override fun getLayout(): Int = R.layout.item_session - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as SpeechSessionItem + override fun providerEqualableContents(): Array<*> = arrayOf(session) - if (session != other.session) return false - if (query == null || other.query == null || query != other.query) return false + override fun isTextHighlightNeedUpdate() = query?.let { + when { + session.title.getByLang(defaultLang()).toLowerCase() + .contains(query.toLowerCase()) -> true + session.speakers.find { + it.name.toLowerCase().contains(query.toLowerCase()) + } != null -> true + else -> false + } + } ?: false - return true + override fun equals(other: Any?): Boolean { + return isSameContents(other) } override fun hashCode(): Int { - return session.hashCode() + query.hashCode() + return contentsHash() } } diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularServiceSessionItem.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularServiceSessionItem.kt index 392c0778f..908c63c58 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularServiceSessionItem.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularServiceSessionItem.kt @@ -6,6 +6,7 @@ import androidx.navigation.NavDirections import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.xwray.groupie.databinding.BindableItem +import io.github.droidkaigi.confsched2019.item.EqualableContentsProvider import io.github.droidkaigi.confsched2019.model.ServiceSession import io.github.droidkaigi.confsched2019.model.defaultLang import io.github.droidkaigi.confsched2019.session.R @@ -17,7 +18,7 @@ class TabularServiceSessionItem @AssistedInject constructor( private val navController: NavController ) : BindableItem( session.id.hashCode().toLong() -), SessionItem { +), SessionItem, EqualableContentsProvider { @AssistedInject.Factory interface Factory { @@ -46,18 +47,13 @@ class TabularServiceSessionItem @AssistedInject constructor( override fun getLayout() = R.layout.item_tabular_service_session - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as TabularServiceSessionItem + override fun providerEqualableContents(): Array<*> = arrayOf(session) - if (session != other.session) return false - - return true + override fun equals(other: Any?): Boolean { + return isSameContents(other) } override fun hashCode(): Int { - return session.hashCode() + return contentsHash() } } diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularSpeechSessionItem.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularSpeechSessionItem.kt index ef5c2f19a..b4fc9d207 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularSpeechSessionItem.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/item/TabularSpeechSessionItem.kt @@ -12,6 +12,7 @@ import com.squareup.picasso.Picasso import com.xwray.groupie.GroupAdapter import com.xwray.groupie.databinding.BindableItem import com.xwray.groupie.databinding.ViewHolder +import io.github.droidkaigi.confsched2019.item.EqualableContentsProvider import io.github.droidkaigi.confsched2019.model.Speaker import io.github.droidkaigi.confsched2019.model.SpeechSession import io.github.droidkaigi.confsched2019.model.defaultLang @@ -26,7 +27,7 @@ class TabularSpeechSessionItem @AssistedInject constructor( private val navController: NavController ) : BindableItem( session.id.hashCode().toLong() -), SessionItem { +), SessionItem, EqualableContentsProvider { @AssistedInject.Factory interface Factory { @@ -82,19 +83,14 @@ class TabularSpeechSessionItem @AssistedInject constructor( override fun getLayout() = R.layout.item_tabular_speech_session - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as TabularSpeechSessionItem + override fun providerEqualableContents(): Array<*> = arrayOf(session) - if (session != other.session) return false - - return true + override fun equals(other: Any?): Boolean { + return isSameContents(other) } override fun hashCode(): Int { - return session.hashCode() + return contentsHash() } private class SpeakerIconItem( diff --git a/frontendcomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/item/EqualableContentsProvider.kt b/frontendcomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/item/EqualableContentsProvider.kt new file mode 100644 index 000000000..9bea27a52 --- /dev/null +++ b/frontendcomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/item/EqualableContentsProvider.kt @@ -0,0 +1,28 @@ +package io.github.droidkaigi.confsched2019.item + +import java.util.Arrays + +interface EqualableContentsProvider { + fun providerEqualableContents(): Array<*> + + override fun equals(other: Any?): Boolean + + override fun hashCode(): Int + + fun isTextHighlightNeedUpdate(): Boolean { + return false + } + + fun isSameContents(other: Any?): Boolean { + other ?: return false + if (other !is EqualableContentsProvider) return false + if (other::class != this::class) return false + if (isTextHighlightNeedUpdate()) return false + if (other.isTextHighlightNeedUpdate()) return false + return other.providerEqualableContents().contentDeepEquals(this.providerEqualableContents()) + } + + fun contentsHash(): Int { + return Arrays.deepHashCode(arrayOf(this::class, this.providerEqualableContents())) + } +}