Skip to content

Commit

Permalink
migrate SyncserviceJob to work manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Aug 5, 2024
1 parent 4fcf06c commit f6f365c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=6.1.4-SNAPSHOT
VERSION_NAME=6.1.5-ALPHA-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
Expand Down
9 changes: 4 additions & 5 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#Mon May 30 16:27:42 EAT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
org.gradle.configureondemand=true
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
org.gradle.parallel=true
zipStoreBase=GRADLE_USER_HOME
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2048m
zipStorePath=wrapper/dists
5 changes: 5 additions & 0 deletions opensrp-core/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module com.sun.tools.javac.code {
requires jdk.compiler;

opens com.sun.tools.javac.code to unnamed;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.smartregister.job;

import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import org.smartregister.sync.intent.SettingsSyncIntentService;

// replaces SyncSettingsServiceJob
public class SyncSettingsServiceWorker extends Worker {
public SyncSettingsServiceWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}

@NonNull
@Override
public Result doWork() {
Intent intent = new Intent(getApplicationContext(), SettingsSyncIntentService.class);
getApplicationContext().startService(intent);
return Result.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
public class ClientProcessorForJava {

public static final String JSON_ARRAY = "json_array";

public static final String demo = "field";
protected static final String VALUES_KEY = "values";
protected static final String detailsUpdated = "detailsUpdated";
protected static ClientProcessorForJava instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.smartregister.sync.intent;

import android.app.PendingIntent;
import android.content.Intent;
import android.util.Log;

Expand All @@ -8,12 +9,16 @@
import org.smartregister.Context;
import org.smartregister.CoreLibrary;
import org.smartregister.job.SyncServiceJob;
import org.smartregister.job.SyncSettingsServiceWorker;
import org.smartregister.sync.helper.SyncSettingsServiceHelper;

import timber.log.Timber;

import static org.smartregister.util.Log.logError;

import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;

/**
* Created by ndegwamartin on 14/09/2018.
*/
Expand All @@ -34,7 +39,9 @@ public SettingsSyncIntentService() {
protected void onHandleIntent(Intent intent) {
boolean isSuccessfulSync = processSettings(intent);
if (isSuccessfulSync) {
SyncServiceJob.scheduleJobImmediately(SyncServiceJob.TAG);
// Schedule the sync job using WorkManager
OneTimeWorkRequest syncWorkRequest = new OneTimeWorkRequest.Builder(SyncSettingsServiceWorker.class).build();
WorkManager.getInstance(this).enqueue(syncWorkRequest);
}
}

Expand Down

0 comments on commit f6f365c

Please sign in to comment.