Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: made ImageTransformation.kt immutable
- Loading branch information
Showing
6 changed files
with
191 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 13 additions & 38 deletions
51
app/src/main/java/openfoodfacts/github/scrachx/openfood/images/ImageTransformation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,23 @@ | ||
package openfoodfacts.github.scrachx.openfood.images | ||
|
||
import android.graphics.Rect | ||
import org.apache.commons.lang3.builder.ToStringBuilder | ||
|
||
class ImageTransformation( | ||
var rotationInDegree: Int = 0, | ||
var cropRectangle: Rect? = null | ||
data class ImageTransformation( | ||
val rotationInDegree: Int = 0, | ||
val cropRectangle: Rect? = null, | ||
var imageUrl: String? = null, | ||
var imageId: String? = null, | ||
) { | ||
var imageUrl: String? = null | ||
var imageId: String? = null | ||
fun isUrlEmpty() = imageUrl.isNullOrBlank() | ||
|
||
override fun toString() = ToStringBuilder(this) | ||
.append(rotationInDegree) | ||
.append(cropRectangle) | ||
.append(imageUrl) | ||
.toString() | ||
fun toMap(): Map<String, String> = buildMap { | ||
this[ANGLE] = rotationInDegree.toString() | ||
|
||
|
||
override fun hashCode(): Int { | ||
var result = rotationInDegree | ||
result = 31 * result + if (cropRectangle != null) cropRectangle.hashCode() else 0 | ||
result = 31 * result + if (imageUrl != null) imageUrl.hashCode() else 0 | ||
return result | ||
} | ||
|
||
fun isEmpty() = imageUrl.isNullOrBlank() | ||
fun isNotEmpty(): Boolean = !isEmpty() | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
if (cropRectangle != null) { | ||
this[LEFT] = cropRectangle.left.toString() | ||
this[RIGHT] = cropRectangle.right.toString() | ||
this[TOP] = cropRectangle.top.toString() | ||
this[BOTTOM] = cropRectangle.bottom.toString() | ||
} | ||
val that = other as ImageTransformation | ||
if (rotationInDegree != that.rotationInDegree) { | ||
return false | ||
} | ||
if (if (cropRectangle != null) cropRectangle != that.cropRectangle else that.cropRectangle != null) { | ||
return false | ||
} | ||
return if (imageUrl != null) imageUrl == that.imageUrl else that.imageUrl == null | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.