Skip to content

Commit

Permalink
Refactor EqualableContentsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Feb 3, 2019
1 parent e665418 commit a701c2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ class SpeakerItem @AssistedInject constructor(
}
}

override fun providerEqualableContents(): Array<*> = arrayOf(speaker)
override fun providerEqualableContents(): Array<*> = arrayOf(
speaker,
if (isContainsQuery()) query else null
)

override fun isTextHighlightNeedUpdate() = query?.let {
private fun isContainsQuery() = query?.let {
speaker.name.toLowerCase().contains(it.toLowerCase())
} ?: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import io.github.droidkaigi.confsched2019.session.ui.actioncreator.SessionConten
import io.github.droidkaigi.confsched2019.session.ui.bindingadapter.setHighlightText
import io.github.droidkaigi.confsched2019.util.lazyWithParam
import jp.wasabeef.picasso.transformations.CropCircleTransformation
import java.lang.IllegalArgumentException
import kotlin.math.max

class SpeechSessionItem @AssistedInject constructor(
Expand Down Expand Up @@ -200,9 +199,12 @@ class SpeechSessionItem @AssistedInject constructor(

override fun getLayout(): Int = R.layout.item_session

override fun providerEqualableContents(): Array<*> = arrayOf(session)
override fun providerEqualableContents(): Array<*> = arrayOf(
session,
if (isContainsQuery()) query else null
)

override fun isTextHighlightNeedUpdate() = query?.let {
private fun isContainsQuery() = query?.let {
when {
session.title.getByLang(defaultLang()).toLowerCase()
.contains(query.toLowerCase()) -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ interface EqualableContentsProvider {

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())
}

Expand Down

0 comments on commit a701c2c

Please sign in to comment.