Skip to content

Commit

Permalink
Final commit before 1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
petermcneil committed May 2, 2019
1 parent 354c237 commit 23e8932
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CreateDropFragment : Fragment(), View.OnClickListener, OnMapReadyCallback
snackBar.setText(sb.toString()).show()
} else {
input.map { it.value.isErrorEnabled = false }
val eitherLocation = locationUtil.lastKnownLocation()
val eitherLocation = locationUtil.getLastKnownLocation()
if (eitherLocation is Either.Right<Location>) {
val location = eitherLocation.value
val dropLocation = DropLocation(location.latitude, location.longitude)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/mcneil/peter/drop/util/FirebaseUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class FirebaseUtil : GeoFire.CompletionListener {
dropsForLocation(location, LocationDropListener(callback), radius)
}

private fun dropsForLocation(location: Location, listener: GeoQueryEventListener, radius: Double = 0.01, empty: Boolean = false) {
private fun dropsForLocation(location: Location, listener: GeoQueryEventListener, radius: Double = 0.01) {
Log.d(TAG, "dropsForLocation: Called")
if (!::lastKnownLocation.isInitialized) lastKnownLocation = location

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/mcneil/peter/drop/util/LocationUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class LocationUtil(val locationManager: LocationManager, val locationClient: Fus
}
}

fun lastKnownLocation(): Either<String, Location> {
return if(lastKnownLocation == null) {
Either.Left("")
fun getLastKnownLocation(): Either<String, Location> {
return if(::lastKnownLocation.isInitialized) {
Either.Left("Not initialised")
} else {
Either.Right(lastKnownLocation)
}
Expand Down
46 changes: 37 additions & 9 deletions app/src/test/java/mcneil/peter/drop/util/ValidateTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mcneil.peter.drop.util

import org.junit.Assert.assertFalse
import mcneil.peter.drop.model.Either
import org.junit.Assert.fail
import org.junit.Test

/**
Expand All @@ -12,24 +13,51 @@ class ValidateTest {

@Test
fun emailValid() {
assert(Validate.email("harry@example.com").first)
assert(Validate.email("harry@pop.ski").first)
val ex = Validate.email("harry@example.com")
if (ex is Either.Right) {
assert(ex.value)
} else {
fail()
}

val pop = Validate.email("harry@pop.ski")
if (pop is Either.Right) {
assert(pop.value)
} else {
fail()
}
}

@Test
fun emailInvalid() {
assertFalse(Validate.email("harry@").first)
assertFalse(Validate.email("harry@com").first)
assertFalse(Validate.email("harry@example.").first)
val t1 = Validate.email("harry@")
val t2 = Validate.email("harry@com")
val t3 = Validate.email("harry@example.")

if (t1 is Either.Right) {
fail()
}
if (t2 is Either.Right) {
fail()
}
if (t3 is Either.Right) {
fail()
}

}

@Test
fun passwordValid() {
assert(Validate.password("12345678").first)
val p1 = Validate.password("12345678")
if(p1 is Either.Right) {
assert(p1.value)
}
}

@Test
fun passwordInvalid() {
assertFalse(Validate.password("1234567").first)
}
val p1 = Validate.password("1234567")
if (p1 is Either.Right) {
fail()
} }
}

0 comments on commit 23e8932

Please sign in to comment.