-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modify configuration files to support Kotlin & Jetpack Compose As discussed this morning, we plan on moving to Kotlin and Jetpack compose. This commit marks the beginning of the modification to make it. * Update minSdk to comply with firebase requirement Changes: * Change from minSdk:24 to minSdk:28 to comply with the firebase realtime database requirements * Delete old java activity file and write basic test Changes: * Remove `GreetingActivity.java` and `MainActivity.java` and dependencies * Write simple `ComposeActvitityTest.kt` * fix: Support for coverage with Kotlin * Added Mockito * Fixed the build.gradle with proper versions * 🔥 💯 :triump: base 😡 --------- Co-authored-by: BoyeGuillaume <guillaume.boye@epfl.ch>
- Loading branch information
1 parent
9eea88f
commit 75d9314
Showing
7 changed files
with
165 additions
and
9 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
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/github/geohunt/app/model/database/Database.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,34 @@ | ||
package com.github.geohunt.app.model.database | ||
|
||
import android.app.Activity | ||
import android.graphics.Bitmap | ||
import com.github.geohunt.app.model.database.api.Challenge | ||
import com.github.geohunt.app.model.database.api.Location | ||
import java.util.concurrent.CompletableFuture | ||
|
||
|
||
interface Database { | ||
fun createChallenge(bitmap: Bitmap, location: Location) : CompletableFuture<Challenge> | ||
|
||
fun getChallengeById(cid: String) : CompletableFuture<Challenge> | ||
|
||
fun getNearbyChallenge(location: Location) : CompletableFuture<List<Challenge>> | ||
|
||
// fun getProfileById(uid: String) : CompletableFuture<Profile> | ||
|
||
} | ||
|
||
/** | ||
* Utility class to create a new database handle (this is used for testing purpose | ||
* to replace the database instance with a mock one using mockito) | ||
*/ | ||
object DatabaseFactory { | ||
|
||
/** | ||
* Create a new instance of a database | ||
*/ | ||
fun createDatabaseHandle(activity: Activity) : Database { | ||
TODO("Not implemented") | ||
} | ||
} | ||
|
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/github/geohunt/app/model/database/api/Challenge.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,41 @@ | ||
package com.github.geohunt.app.model.database.api | ||
|
||
import java.time.LocalDateTime | ||
|
||
interface Challenge | ||
{ | ||
/** | ||
* The challenge's id. | ||
*/ | ||
val cid: String | ||
|
||
/** | ||
* The author's id | ||
*/ | ||
val uid: String | ||
|
||
/** | ||
* Publication date | ||
*/ | ||
val published: LocalDateTime | ||
|
||
/** | ||
* Expiration date | ||
*/ | ||
val expirationDate: LocalDateTime? | ||
|
||
val thumbnail: PictureImage | ||
|
||
/** | ||
* The approximate location of the challenge | ||
*/ | ||
val coarseLocation: Location | ||
|
||
/** | ||
* The true position of the challenge | ||
*/ | ||
val correctLocation: Location | ||
|
||
val claims: List<String> | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/github/geohunt/app/model/database/api/Claim.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,12 @@ | ||
package com.github.geohunt.app.model.database.api | ||
|
||
import java.time.LocalDateTime | ||
|
||
interface Claim { | ||
val id: String | ||
val cid: String | ||
val uid: String | ||
|
||
val time: LocalDateTime | ||
val location: Location | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/github/geohunt/app/model/database/api/Location.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,42 @@ | ||
package com.github.geohunt.app.model.database.api | ||
|
||
import java.nio.ByteBuffer | ||
import java.util.zip.CRC32 | ||
import kotlin.math.absoluteValue | ||
import kotlin.math.roundToLong | ||
|
||
data class Location(var latitude: Double, | ||
var longitude: Double) { | ||
override fun toString(): String { | ||
return "${getDMS(latitude, 'N', 'S')}, ${getDMS(longitude, 'E', 'W')}" | ||
} | ||
|
||
private fun getDMS(v: Double, positive: Char, negative: Char) : String { | ||
var value = v.absoluteValue | ||
|
||
val degree = value.toInt() | ||
|
||
value = (value - degree) * 60.0 | ||
val minutes = value.toInt() | ||
|
||
value = (value - minutes) * 60.0 | ||
|
||
return "$degree° $minutes' ${String.format("%.2f", value)}'' ${if (v > 0.0) positive else negative}" | ||
} | ||
|
||
companion object { | ||
fun getCoarseHash(location: Location) : String { | ||
val crc32 = CRC32() | ||
|
||
// Define a ~11.1km lattice (at the equator) | ||
var coarseLatitude = (location.latitude * 10.0).roundToLong() | ||
var coarseLongitude = (location.longitude * 10.0).roundToLong() | ||
|
||
val byteBuffer = ByteBuffer.allocate(2 * Long.SIZE_BYTES) | ||
.putLong(0, coarseLatitude) | ||
.putLong(Double.SIZE_BYTES, coarseLongitude) | ||
crc32.update(byteBuffer) | ||
return crc32.value.toString(36) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/github/geohunt/app/model/database/api/PictureImage.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,13 @@ | ||
package com.github.geohunt.app.model.database.api | ||
|
||
import android.graphics.Bitmap | ||
import java.util.concurrent.CompletableFuture | ||
|
||
interface PictureImage { | ||
val iid : String | ||
val bitmap : Bitmap? | ||
|
||
fun load() : CompletableFuture<Bitmap> | ||
|
||
fun save() : CompletableFuture<Void> | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/github/geohunt/app/model/database/api/User.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,16 @@ | ||
package com.github.geohunt.app.model.database.api | ||
|
||
import com.github.geohunt.app.model.database.api.PictureImage | ||
|
||
interface User { | ||
var displayName: String? | ||
|
||
val uid: String | ||
|
||
val profilePicture: PictureImage? | ||
|
||
val challenges: List<String> | ||
val hunts: List<String> | ||
|
||
var score: Number | ||
} |