Skip to content

Commit

Permalink
#18 운전 기록 전송 - LatLng 클래스 대신 Location 클래스, http logging
Browse files Browse the repository at this point in the history
  • Loading branch information
comye1 committed Mar 26, 2022
1 parent 2def83a commit b52922a
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 140 deletions.
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
}
}
aaptOptions {
noCompress = "tflite"
// noCompress = "tflite"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -57,8 +57,8 @@ android {

dependencies {

implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
// implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
// implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
def nav_version = "2.4.1"

implementation 'androidx.core:core-ktx:1.7.0'
Expand Down Expand Up @@ -125,8 +125,8 @@ dependencies {
// Easy Permissions
implementation 'pub.devrel:easypermissions:3.0.0'

// Import tflite dependencies
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'
// // Import tflite dependencies
// implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.0.4')
Expand All @@ -147,4 +147,7 @@ dependencies {

// ml kit
implementation 'com.google.android.gms:play-services-mlkit-face-detection:17.0.1'

// http logging
implementation("com.squareup.okhttp3:logging-interceptor:4.9.3")
}
275 changes: 155 additions & 120 deletions app/src/main/java/com/comye1/dontsleepdriver/DSDActivity.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.comye1.dontsleepdriver.data

import com.comye1.dontsleepdriver.data.model.*
import retrofit2.Call
import retrofit2.http.*

interface DSDApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
package com.comye1.dontsleepdriver.data.model

import com.google.android.gms.maps.model.LatLng

data class DrivingBody(
val startTime: String,
val endTime: String,
val totalTime: Int,
val gpsData: List<LatLng>,
val gpsLevel: List<Int>,
val avgSleepLevel: Double
)
val gpsData: Array<Location>,
val gpsLevel: Array<Int>,
val avgSleepLevel: Double,
val totalTime: Int
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as DrivingBody

if (startTime != other.startTime) return false
if (endTime != other.endTime) return false
if (!gpsData.contentEquals(other.gpsData)) return false
if (!gpsLevel.contentEquals(other.gpsLevel)) return false
if (avgSleepLevel != other.avgSleepLevel) return false
if (totalTime != other.totalTime) return false

return true
}

override fun hashCode(): Int {
var result = startTime.hashCode()
result = 31 * result + endTime.hashCode()
result = 31 * result + gpsData.contentHashCode()
result = 31 * result + gpsLevel.contentHashCode()
result = 31 * result + avgSleepLevel.hashCode()
result = 31 * result + totalTime
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.comye1.dontsleepdriver.data.model

data class DrivingData(
val id: Int,
val startTime: String,
val endTime: String,
val avgSleepLevel: Double,
val totalTime: Int,
val driverId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.comye1.dontsleepdriver.data.model
data class DrivingPostResponse(
val success: Boolean,
val message: String,
val data: DrivingResponse?,
val data: DrivingData?,
val error: String
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.comye1.dontsleepdriver.data.model

import com.google.android.gms.maps.model.LatLng

data class DrivingResponse(
val id: Int,
val startTime: String,
val endTime: String,
val totalTime: Int,
val gpsData: List<LatLng>,
val gpsData: List<Location>,
val gpsLevel: List<Int>,
val avgSleepLevel: Double
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.comye1.dontsleepdriver.data.model

data class Location(
val lat: Double,
val lng: Double
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import androidx.core.content.edit
import com.comye1.dontsleepdriver.data.DSDApi
import com.comye1.dontsleepdriver.data.model.*
import com.comye1.dontsleepdriver.util.Resource
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import dagger.hilt.android.scopes.ActivityScoped
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import javax.inject.Inject

@ActivityScoped
Expand Down Expand Up @@ -178,15 +183,18 @@ class DSDRepository @Inject constructor(
return Resource.Success(response.data)
}

suspend fun postDrivingItem(driving: DrivingBody): Resource<DrivingResponse> {
suspend fun postDrivingItem(driving: DrivingBody): Resource<DrivingData> {
val token = getSavedToken() ?: return Resource.Error("token does not exist")

Log.d("postDrivingItem","repository")

val response = try {
api.postDriving(token.toTokenMap(), driving)
} catch (e: Exception) {
Log.d("repo 9 exception", e.toString())
return Resource.Error(e.message ?: "")
Log.d("repo 10 exception", e.localizedMessage?: "")
return Resource.Error(e.toString())
}
Log.d("repo 9 success", response.data.toString())
Log.d("repo 10 success", response.data.toString())
response.data?.let {
return Resource.Success(it)
}
Expand Down

0 comments on commit b52922a

Please sign in to comment.