@@ -183,12 +183,9 @@ class MainActivityViewModel @Inject constructor(
183
183
)
184
184
185
185
try {
186
- val response = networkApi.register(registration)
187
- // Log.d(TAG, "response is ${response.isSuccessful}")
188
- // if (response.isSuccessful) {
186
+ networkApi.register(registration)
189
187
login(ByteString .copyFrom(h_pkr), ByteString .copyFrom(Hex .decodeHex(sk_t)))
190
188
_loginState .value = LoginStatus .RegistrationSucceeded
191
- // }
192
189
} catch (e: HttpException ) {
193
190
Log .d(TAG , " error occurred during registration. error is $e " )
194
191
_loginState .value = LoginStatus .RegistrationFailed (e.message())
@@ -363,7 +360,37 @@ class MainActivityViewModel @Inject constructor(
363
360
val curTime = TimeUtil .getCurrentTime()
364
361
val cellID = signalStrengthMonitor.getCellID()
365
362
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
+ }
367
394
} catch (e: Exception ) {
368
395
Log .d(TAG , " catch $e " )
369
396
}
@@ -403,6 +430,8 @@ class MainActivityViewModel @Inject constructor(
403
430
if (e.code() in 500 .. 599 ) {
404
431
Log .d(TAG , " server error" )
405
432
}
433
+ } catch (e: Exception ) {
434
+ Log .d(TAG , " unknown exception occurred when uploading data. $e " )
406
435
}
407
436
}
408
437
0 commit comments