-
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.
Merge pull request #374 from rfcx/feature/bourhan-improvement
improvement from feedback
- Loading branch information
Showing
16 changed files
with
145 additions
and
30 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
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
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
6 changes: 5 additions & 1 deletion
6
...rg/rfcx/incidents/data/remote/guardian/registration/GuardianRegisterProductionEndpoint.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package org.rfcx.incidents.data.remote.guardian.registration | ||
|
||
import org.rfcx.incidents.entity.guardian.registration.GuardianRegisterRequest | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface GuardianRegisterProductionEndpoint { | ||
@POST("guardians") | ||
suspend fun register(@Body registration: GuardianRegisterRequest): GuardianRegisterResponse | ||
suspend fun registerSuspend(@Body registration: GuardianRegisterRequest): GuardianRegisterResponse | ||
|
||
@POST("guardians") | ||
fun register(@Body registration: GuardianRegisterRequest): Call<GuardianRegisterResponse> | ||
} |
6 changes: 5 additions & 1 deletion
6
...a/org/rfcx/incidents/data/remote/guardian/registration/GuardianRegisterStagingEndpoint.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package org.rfcx.incidents.data.remote.guardian.registration | ||
|
||
import org.rfcx.incidents.entity.guardian.registration.GuardianRegisterRequest | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface GuardianRegisterStagingEndpoint { | ||
@POST("guardians") | ||
suspend fun register(@Body registration: GuardianRegisterRequest): GuardianRegisterResponse | ||
suspend fun registerSuspend(@Body registration: GuardianRegisterRequest): GuardianRegisterResponse | ||
|
||
@POST("guardians") | ||
fun register(@Body registration: GuardianRegisterRequest): Call<GuardianRegisterResponse> | ||
} |
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
69 changes: 69 additions & 0 deletions
69
app/src/main/java/org/rfcx/incidents/service/deploy/RegistrationSyncWorker.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,69 @@ | ||
package org.rfcx.incidents.service.deploy | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.work.Constraints | ||
import androidx.work.ExistingWorkPolicy | ||
import androidx.work.NetworkType | ||
import androidx.work.OneTimeWorkRequestBuilder | ||
import androidx.work.WorkInfo | ||
import androidx.work.WorkManager | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
import io.realm.Realm | ||
import org.rfcx.incidents.data.local.guardian.GuardianRegistrationDb | ||
import org.rfcx.incidents.data.local.realm.AppRealm | ||
import org.rfcx.incidents.data.remote.common.service.ServiceFactory | ||
import org.rfcx.incidents.entity.guardian.registration.toRequest | ||
|
||
class RegistrationSyncWorker(private val context: Context, params: WorkerParameters) : Worker(context, params) { | ||
override fun doWork(): Result { | ||
val prodService = ServiceFactory.makeGuardianRegisterProductionService(context) | ||
val stagingService = ServiceFactory.makeGuardianRegisterStagingService(context) | ||
val db = GuardianRegistrationDb(Realm.getInstance(AppRealm.configuration())) | ||
val unsent = db.getAllUnsentForWorker() | ||
|
||
Log.d(TAG, "doWork: found ${unsent.size} unsent") | ||
var someFailed = false | ||
unsent.forEach { | ||
when (it.env) { | ||
"production" -> { | ||
val result = prodService.register(it.toRequest()).execute() | ||
if (result.isSuccessful) { | ||
db.markSent(it.guid) | ||
} else { | ||
db.markUnsent(it.guid) | ||
someFailed = true | ||
} | ||
} | ||
"staging" -> { | ||
val result = stagingService.register(it.toRequest()).execute() | ||
if (result.isSuccessful) { | ||
db.markSent(it.guid) | ||
} else { | ||
db.markUnsent(it.guid) | ||
someFailed = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
return if (someFailed) Result.retry() else Result.success() | ||
} | ||
|
||
companion object { | ||
private const val TAG = "RegistrationSyncWorker" | ||
private const val UNIQUE_WORK_KEY = "RegistrationSyncWorkerUniqueKey" | ||
|
||
fun enqueue() { | ||
val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build() | ||
val workRequest = OneTimeWorkRequestBuilder<RegistrationSyncWorker>().setConstraints(constraints).build() | ||
WorkManager.getInstance().enqueueUniqueWork(UNIQUE_WORK_KEY, ExistingWorkPolicy.KEEP, workRequest) | ||
} | ||
|
||
fun workInfos(): LiveData<List<WorkInfo>> { | ||
return WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(UNIQUE_WORK_KEY) | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
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