Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* - Migrate to kotlin * - Using Parcelize over Autoparcel library * - Factory migrated to kotlin * - Added test Co-authored-by: leighdouglas <leighcdouglas1@gmail.com>
- Loading branch information
1 parent
565349e
commit 853db18
Showing
5 changed files
with
181 additions
and
142 deletions.
There are no files selected for viewing
75 changes: 0 additions & 75 deletions
75
app/src/main/java/com/kickstarter/mock/factories/LocationFactory.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/kickstarter/mock/factories/LocationFactory.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.kickstarter.mock.factories | ||
|
||
import com.kickstarter.models.Location | ||
import com.kickstarter.models.Location.Companion.builder | ||
|
||
object LocationFactory { | ||
@JvmStatic | ||
fun germany(): Location { | ||
return builder() | ||
.id(1L) | ||
.displayableName("Berlin, Germany") | ||
.name("Berlin") | ||
.state("Berlin") | ||
.country("DE") | ||
.expandedCountry("Germany") | ||
.build() | ||
} | ||
|
||
@JvmStatic | ||
fun mexico(): Location { | ||
return builder() | ||
.id(2L) | ||
.displayableName("Mexico City, Mexico") | ||
.name("Mexico City") | ||
.state("Mexico") | ||
.country("MX") | ||
.expandedCountry("Mexico") | ||
.build() | ||
} | ||
|
||
fun nigeria(): Location { | ||
return builder() | ||
.id(3L) | ||
.displayableName("Nigeria") | ||
.name("Nigeria") | ||
.state("Imo State") | ||
.country("NG") | ||
.expandedCountry("Nigeria") | ||
.build() | ||
} | ||
|
||
@JvmStatic | ||
fun sydney(): Location { | ||
return builder() | ||
.id(4L) | ||
.name("Sydney") | ||
.displayableName("Sydney, AU") | ||
.country("AU") | ||
.state("NSW") | ||
.projectsCount(33) | ||
.expandedCountry("Australia") | ||
.build() | ||
} | ||
|
||
@JvmStatic | ||
fun unitedStates(): Location { | ||
return builder() | ||
.id(5L) | ||
.displayableName("Brooklyn, NY") | ||
.name("Brooklyn") | ||
.state("NY") | ||
.country("US") | ||
.expandedCountry("United States") | ||
.build() | ||
} | ||
|
||
fun empty(): Location { | ||
return builder() | ||
.id(-1L) | ||
.displayableName("") | ||
.name("") | ||
.country("") | ||
.expandedCountry("") | ||
.build() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.kickstarter.models | ||
|
||
import android.os.Parcelable | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
class Location private constructor( | ||
private val id: Long, | ||
private val city: String, | ||
private val country: String, | ||
private val displayableName: String, | ||
private val expandedCountry: String, | ||
private val name: String, | ||
private val projectsCount: Int, | ||
private val state: String | ||
) : Parcelable, Relay { | ||
|
||
fun displayableName() = this.displayableName | ||
fun city() = this.city | ||
fun country() = this.country | ||
fun expandedCountry() = this.expandedCountry | ||
fun name() = this.name | ||
fun state() = this.state | ||
fun projectsCount() = this.projectsCount | ||
override fun id(): Long = this.id | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var id: Long = 0L, | ||
private var city: String = "", | ||
private var country: String = "", | ||
private var displayableName: String = "", | ||
private var expandedCountry: String = "", | ||
private var name: String = "", | ||
private var projectsCount: Int = 0, | ||
private var state: String = "" | ||
) : Parcelable { | ||
fun displayableName(dName: String?) = apply { dName?.let { this.displayableName = it } } | ||
fun city(city: String?) = apply { city?.let { this.city = it } } | ||
fun country(count: String?) = apply { count?.let { this.country = it } } | ||
fun expandedCountry(expCount: String?) = apply { expCount?.let { this.expandedCountry = it } } | ||
fun name(name: String?) = apply { name?.let { this.name = it } } | ||
fun state(state: String?) = apply { state?.let { this.state = it } } | ||
fun projectsCount(pCount: Int?) = apply { pCount?.let { this.projectsCount = it } } | ||
fun id(id: Long?) = apply { id?.let { this.id = it } } | ||
fun build() = Location( | ||
id = id, | ||
city = city, | ||
country = country, | ||
displayableName = displayableName, | ||
expandedCountry = expandedCountry, | ||
name = name, | ||
projectsCount = projectsCount, | ||
state = state | ||
) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
id = id, | ||
city = city, | ||
country = country, | ||
displayableName = displayableName, | ||
expandedCountry = expandedCountry, | ||
name = name, | ||
projectsCount = projectsCount, | ||
state = state | ||
) | ||
|
||
override fun equals(obj: Any?): Boolean { | ||
var equals = super.equals(obj) | ||
if (obj is Location) { | ||
equals = id() == obj.id() && | ||
city() == obj.city() && | ||
country() == obj.country() && | ||
displayableName() == obj.displayableName() && | ||
expandedCountry() == obj.expandedCountry() && | ||
name() == obj.name() && | ||
projectsCount() == obj.projectsCount() && | ||
state() == obj.state() | ||
} | ||
return equals | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return super.hashCode() | ||
} | ||
} |
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