diff --git a/app/src/main/java/org/tasks/location/MapPosition.java b/app/src/main/java/org/tasks/location/MapPosition.java deleted file mode 100644 index ad155bd2c..000000000 --- a/app/src/main/java/org/tasks/location/MapPosition.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.tasks.location; - -import android.os.Parcel; -import android.os.Parcelable; - -public class MapPosition implements Parcelable { - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - @Override - public MapPosition createFromParcel(Parcel in) { - return new MapPosition(in); - } - - @Override - public MapPosition[] newArray(int size) { - return new MapPosition[size]; - } - }; - private final double latitude; - private final double longitude; - private final float zoom; - - public MapPosition(double latitude, double longitude) { - this(latitude, longitude, 15.0f); - } - - public MapPosition(double latitude, double longitude, float zoom) { - this.latitude = latitude; - this.longitude = longitude; - this.zoom = zoom; - } - - private MapPosition(Parcel in) { - latitude = in.readDouble(); - longitude = in.readDouble(); - zoom = in.readFloat(); - } - - public double getLatitude() { - return latitude; - } - - public double getLongitude() { - return longitude; - } - - float getZoom() { - return zoom; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeDouble(latitude); - dest.writeDouble(longitude); - dest.writeFloat(zoom); - } -} diff --git a/app/src/main/java/org/tasks/location/MapPosition.kt b/app/src/main/java/org/tasks/location/MapPosition.kt new file mode 100644 index 000000000..9854add32 --- /dev/null +++ b/app/src/main/java/org/tasks/location/MapPosition.kt @@ -0,0 +1,59 @@ +package org.tasks.location + +import android.os.Parcel +import android.os.Parcelable + +class MapPosition : Parcelable { + val latitude: Double + val longitude: Double + val zoom: Float + + @JvmOverloads + constructor(latitude: Double, longitude: Double, zoom: Float = 15.0f) { + this.latitude = latitude + this.longitude = longitude + this.zoom = zoom + } + + private constructor(parcel: Parcel) { + latitude = parcel.readDouble() + longitude = parcel.readDouble() + zoom = parcel.readFloat() + } + + override fun describeContents() = 0 + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeDouble(latitude) + dest.writeDouble(longitude) + dest.writeFloat(zoom) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is MapPosition) return false + + if (latitude != other.latitude) return false + if (longitude != other.longitude) return false + if (zoom != other.zoom) return false + + return true + } + + override fun hashCode(): Int { + var result = latitude.hashCode() + result = 31 * result + longitude.hashCode() + result = 31 * result + zoom.hashCode() + return result + } + + override fun toString() = "MapPosition(latitude=$latitude, longitude=$longitude, zoom=$zoom)" + + companion object { + @JvmField val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel) = MapPosition(source) + + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + } +} \ No newline at end of file