Skip to content

Commit 4adcfc8

Browse files
Merge pull request #27 from Omega-R/feature/image_equals
Equals method for images added
2 parents 8d5f512 + 5d6bdc0 commit 4adcfc8

File tree

3 files changed

+78
-0
lines changed
  • glide/src/main/java/com/omega_r/libs/omegatypes/glide
  • omegatypes/src/main/java/com/omega_r/libs/omegatypes
  • picasso/src/main/java/com/omega_r/libs/omegatypes/picasso

3 files changed

+78
-0
lines changed

glide/src/main/java/com/omega_r/libs/omegatypes/glide/GlideImage.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,21 @@ class GlideImage(override val url: String) : Image(), UrlImage {
9090
return stream
9191
}
9292

93+
override fun equals(other: Any?): Boolean {
94+
if (this === other) return true
95+
if (javaClass != other?.javaClass) return false
96+
97+
other as GlideImage
98+
99+
if (url != other.url) return false
100+
101+
return true
102+
}
103+
104+
override fun hashCode(): Int {
105+
return url.hashCode()
106+
}
107+
108+
93109
}
94110

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Image.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ class ResourceImage(private val resId: Int) : Image() {
134134
context.resources.getDrawable(resId)!!
135135
}
136136
}
137+
138+
override fun equals(other: Any?): Boolean {
139+
if (this === other) return true
140+
if (javaClass != other?.javaClass) return false
141+
142+
other as ResourceImage
143+
144+
if (resId != other.resId) return false
145+
146+
return true
147+
}
148+
149+
override fun hashCode(): Int {
150+
return resId
151+
}
152+
137153
}
138154

139155
class DrawableImage(private val innerDrawable: Drawable) : Image() {
@@ -154,6 +170,21 @@ class DrawableImage(private val innerDrawable: Drawable) : Image() {
154170

155171
override fun getDrawable(context: Context) = innerDrawable
156172

173+
override fun equals(other: Any?): Boolean {
174+
if (this === other) return true
175+
if (javaClass != other?.javaClass) return false
176+
177+
other as DrawableImage
178+
179+
if (innerDrawable != other.innerDrawable) return false
180+
181+
return true
182+
}
183+
184+
override fun hashCode(): Int {
185+
return innerDrawable.hashCode()
186+
}
187+
157188
}
158189

159190
class BitmapImage(private val bitmap: Bitmap) : Image() {
@@ -171,6 +202,22 @@ class BitmapImage(private val bitmap: Bitmap) : Image() {
171202
}
172203

173204
override fun getDrawable(context: Context) = BitmapDrawable(context.resources, bitmap)
205+
206+
override fun equals(other: Any?): Boolean {
207+
if (this === other) return true
208+
if (javaClass != other?.javaClass) return false
209+
210+
other as BitmapImage
211+
212+
if (bitmap != other.bitmap) return false
213+
214+
return true
215+
}
216+
217+
override fun hashCode(): Int {
218+
return bitmap.hashCode()
219+
}
220+
174221
}
175222

176223
fun Bitmap.toInputStream(compressFormat: Bitmap.CompressFormat, quality: Int): InputStream {

picasso/src/main/java/com/omega_r/libs/omegatypes/picasso/PicassoImage.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,19 @@ class PicassoImage(override val url: String) : Image(), UrlImage {
112112
return stream
113113
}
114114

115+
override fun equals(other: Any?): Boolean {
116+
if (this === other) return true
117+
if (javaClass != other?.javaClass) return false
118+
119+
other as PicassoImage
120+
121+
if (url != other.url) return false
122+
123+
return true
124+
}
125+
126+
override fun hashCode(): Int {
127+
return url.hashCode()
128+
}
129+
115130
}

0 commit comments

Comments
 (0)