Skip to content

Commit 150a37d

Browse files
committed
add back code to save report to local db and remote server
1 parent bd48cde commit 150a37d

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

app/src/main/java/com/lcl/lclmeasurementtool/MainActivityViewModel.kt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,9 @@ class MainActivityViewModel @Inject constructor(
183183
)
184184

185185
try {
186-
val response = networkApi.register(registration)
187-
// Log.d(TAG, "response is ${response.isSuccessful}")
188-
// if (response.isSuccessful) {
186+
networkApi.register(registration)
189187
login(ByteString.copyFrom(h_pkr), ByteString.copyFrom(Hex.decodeHex(sk_t)))
190188
_loginState.value = LoginStatus.RegistrationSucceeded
191-
// }
192189
} catch (e: HttpException) {
193190
Log.d(TAG, "error occurred during registration. error is $e")
194191
_loginState.value = LoginStatus.RegistrationFailed(e.message())
@@ -363,7 +360,37 @@ class MainActivityViewModel @Inject constructor(
363360
val curTime = TimeUtil.getCurrentTime()
364361
val cellID = signalStrengthMonitor.getCellID()
365362

366-
// TODO: add data to db + report to remote server
363+
// add data to db + report to remote server
364+
locationService.lastLocation().combine(userDataRepository.userData) { location, userPreference ->
365+
Pair(location, userPreference)
366+
}.collect {
367+
val signalStrengthReportModel = SignalStrengthReportModel(
368+
it.first.latitude,
369+
it.first.longitude,
370+
curTime,
371+
cellID,
372+
it.second.deviceID,
373+
signalStrengthResult.value.dbm,
374+
signalStrengthResult.value.level.level
375+
)
376+
377+
val connectivityReportModel = ConnectivityReportModel(
378+
it.first.latitude,
379+
it.first.longitude,
380+
curTime,
381+
cellID,
382+
it.second.deviceID,
383+
(_mLabUploadResult.value as ConnectivityTestResult.Result).result.toDouble(),
384+
(_mLabDownloadResult.value as ConnectivityTestResult.Result).result.toDouble(),
385+
(_mLabPingResult.value as PingResultState.Success).result.avg!!.toDouble(),
386+
(_mLabPingResult.value as PingResultState.Success).result.numLoss!!.toDouble(),
387+
)
388+
389+
saveToDB(signalStrengthReportModel, connectivityReportModel)
390+
391+
report(signalStrengthReportModel, it.second)
392+
report(connectivityReportModel, it.second)
393+
}
367394
} catch (e: Exception) {
368395
Log.d(TAG, "catch $e")
369396
}
@@ -403,6 +430,8 @@ class MainActivityViewModel @Inject constructor(
403430
if (e.code() in 500..599) {
404431
Log.d(TAG, "server error")
405432
}
433+
} catch (e: Exception) {
434+
Log.d(TAG, "unknown exception occurred when uploading data. $e")
406435
}
407436
}
408437

0 commit comments

Comments
 (0)