-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/issue550 add equalable content provider #766
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.droidkaigi.confsched2019.session.ui.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 | ||
return other.providerEqualableContents().contentDeepEquals(this.providerEqualableContents()) | ||
} | ||
|
||
fun contentsHash(): Int { | ||
return Arrays.deepHashCode(arrayOf(this::class, this.providerEqualableContents())) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ class SpeakerItem @AssistedInject constructor( | |
@Assisted val clickNavDirection: NavDirections, | ||
@Assisted val query: String?, | ||
val navController: NavController | ||
) : BindableItem<ItemSpeakerBinding>(speaker.id.hashCode().toLong()) { | ||
) : BindableItem<ItemSpeakerBinding>(speaker.id.hashCode().toLong()), | ||
EqualableContentsProvider { | ||
@AssistedInject.Factory | ||
interface Factory { | ||
fun create( | ||
|
@@ -64,19 +65,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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ちょっと日本語で失礼します。 🙇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. すみません、最初にissueでコメントして頂いた意図を汲みきれていなかったみたいですね。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ありがとうございます! 🙇 |
||
speaker.name.toLowerCase().contains(it.toLowerCase().toRegex()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this |
||
} ?: false | ||
|
||
return true | ||
override fun equals(other: Any?): Boolean { | ||
return isSameContents(other) | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return speaker.hashCode() + query.hashCode() | ||
return contentsHash() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this interface to androidcomponent module? for sharing 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, item folder would be good?