Skip to content

Commit

Permalink
Compose migration (#26)
Browse files Browse the repository at this point in the history
* 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
Maeeen and BoyeGuillaume committed Mar 8, 2023
1 parent 9eea88f commit 75d9314
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 9 deletions.
16 changes: 7 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,18 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.navigation:navigation-compose:2.5.3'

// Add compose dependencies
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
implementation 'androidx.core:core-ktx:+'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
implementation 'com.google.android.gms:play-services-location:19.0.1'

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.2.3')

// Authentication
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.firebaseui:firebase-ui-auth:7.2.0'

// Tests
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand All @@ -86,6 +82,8 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
testImplementation "org.mockito:mockito-inline:4.1.0"
}
Expand All @@ -110,7 +108,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea
'android/**/*.*',
]

def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: fileFilter)
def debugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories.setFrom(files([mainSrc]))
Expand Down
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")
}
}

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>
}

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
}
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)
}
}
}
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>
}
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
}

0 comments on commit 75d9314

Please sign in to comment.