From 613d7790b0eee9334bbc187faf99e95d26d1ceb4 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 26 Aug 2022 10:49:34 +0300 Subject: [PATCH 01/19] Add AppExecutorService class --- .../immunization/util/AppExecutorService.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java new file mode 100644 index 00000000..bf8a7b9f --- /dev/null +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java @@ -0,0 +1,48 @@ +package org.smartregister.immunization.util; + +import android.os.Handler; +import android.os.Looper; + +import androidx.annotation.NonNull; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Global ExecutorService for the whole application. + * + * This provides a single thread Executor and main thread Executor for use + */ +public class AppExecutorService { + + private ExecutorService executorService; + private Executor mainThread; + + public AppExecutorService(ExecutorService executorService, Executor mainThread) { + this.executorService = executorService; + this.mainThread = mainThread; + } + + public AppExecutorService() { + this(Executors.newSingleThreadExecutor(), + new AppExecutorService.MainThreadExecutor()); + } + + public ExecutorService executorService() { + return executorService; + } + + public Executor mainThread() { + return mainThread; + } + + private static class MainThreadExecutor implements Executor { + private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); + + @Override + public void execute(@NonNull Runnable command) { + mainThreadHandler.post(command); + } + } +} \ No newline at end of file From 6e85c41fa1564232fae72ac70c3fbf51c41b4174 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 26 Aug 2022 11:51:28 +0300 Subject: [PATCH 02/19] remove immunizationRowTask --- .../adapter/ImmunizationRowAdapter.java | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 23479e6d..7ca8e603 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -1,7 +1,6 @@ package org.smartregister.immunization.adapter; import android.content.Context; -import android.os.AsyncTask; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -21,7 +20,8 @@ import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; -import org.smartregister.util.Utils; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import java.util.ArrayList; import java.util.Calendar; @@ -30,12 +30,15 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.smartregister.immunization.util.VaccinatorUtils.generateScheduleList; import static org.smartregister.immunization.util.VaccinatorUtils.receivedVaccines; import static org.smartregister.util.Utils.getValue; +import timber.log.Timber; + /** * Created by raihan on 13/03/2017. */ @@ -83,10 +86,40 @@ public View getView(int position, View convertView, ViewGroup parent) { ImmunizationRowCard vaccineCard = new ImmunizationRowCard(context, editmode); vaccineCard.setId((int) getItemId(position)); vaccineCards.put(vaccineName, vaccineCard); - ImmunizationRowTask immunizationRowTask = new ImmunizationRowTask(vaccineCard, vaccineName, - vaccineGroup.getVaccineData().days_after_birth_due, - vaccineGroup.getChildDetails()); - Utils.startAsyncTask(immunizationRowTask, null); + Callable callable = () -> { + CommonPersonObjectClient childDetails = vaccineGroup.getChildDetails(); + int days_after_birth_due = vaccineGroup.getVaccineData().days_after_birth_due; + VaccineWrapper vaccineWrapper = new VaccineWrapper(); + vaccineWrapper.setId(childDetails.entityId()); + vaccineWrapper.setGender(childDetails.getDetails().get("gender")); + vaccineWrapper.setName(vaccineName); + + String dobString = getValue(childDetails.getColumnmaps(), "dob", false); + if (StringUtils.isNotBlank(dobString)) { + Calendar dobCalender = Calendar.getInstance(); + DateTime dateTime = new DateTime(dobString); + dobCalender.setTime(dateTime.toDate()); + dobCalender.add(Calendar.DATE, days_after_birth_due); + vaccineWrapper.setVaccineDate(new DateTime(dobCalender.getTime())); + } + + + Photo photo = ImageUtils.profilePhotoByClient(childDetails); + vaccineWrapper.setPhoto(photo); + + String zeirId = getValue(childDetails.getColumnmaps(), "zeir_id", false); + vaccineWrapper.setPatientNumber(zeirId); + vaccineWrapper.setPatientName( + getValue(childDetails.getColumnmaps(), "first_name", true) + " " + getValue(childDetails.getColumnmaps(), + "last_name", true)); + + updateWrapper(vaccineWrapper); + updateWrapperStatus(vaccineWrapper, childDetails); + return vaccineWrapper; + }; + ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = new ImmunizationRowCallableInteractorCallback(vaccineCard, vaccineName); + GenericInteractor interactor = new GenericInteractor(); + interactor.execute(callable, immunizationRowCallableInteractorCallback); } return vaccineCards.get(vaccineName); } catch (Exception e) { @@ -225,58 +258,18 @@ public void setAlertList(List alertList) { this.alertList = alertList; } - class ImmunizationRowTask extends AsyncTask { + class ImmunizationRowCallableInteractorCallback implements CallableInteractorCallBack{ private ImmunizationRowCard vaccineCard; - private String vaccineName; - private int days_after_birth_due; - - private CommonPersonObjectClient childDetails; - - ImmunizationRowTask(ImmunizationRowCard vaccineCard, String vaccineName, int days_after_birth_due, - CommonPersonObjectClient childDetails) { + ImmunizationRowCallableInteractorCallback(ImmunizationRowCard vaccineCard, String vaccineName) { this.vaccineCard = vaccineCard; this.vaccineName = vaccineName; - this.days_after_birth_due = days_after_birth_due; - this.childDetails = childDetails; - } - - @Override - protected VaccineWrapper doInBackground(Void... params) { - - VaccineWrapper vaccineWrapper = new VaccineWrapper(); - vaccineWrapper.setId(childDetails.entityId()); - vaccineWrapper.setGender(childDetails.getDetails().get("gender")); - vaccineWrapper.setName(vaccineName); - - String dobString = getValue(childDetails.getColumnmaps(), "dob", false); - if (StringUtils.isNotBlank(dobString)) { - Calendar dobCalender = Calendar.getInstance(); - DateTime dateTime = new DateTime(dobString); - dobCalender.setTime(dateTime.toDate()); - dobCalender.add(Calendar.DATE, days_after_birth_due); - vaccineWrapper.setVaccineDate(new DateTime(dobCalender.getTime())); - } - - - Photo photo = ImageUtils.profilePhotoByClient(childDetails); - vaccineWrapper.setPhoto(photo); - - String zeirId = getValue(childDetails.getColumnmaps(), "zeir_id", false); - vaccineWrapper.setPatientNumber(zeirId); - vaccineWrapper.setPatientName( - getValue(childDetails.getColumnmaps(), "first_name", true) + " " + getValue(childDetails.getColumnmaps(), - "last_name", true)); - - updateWrapper(vaccineWrapper); - updateWrapperStatus(vaccineWrapper, childDetails); - return vaccineWrapper; } @Override - protected void onPostExecute(VaccineWrapper vaccineWrapper) { + public void onResult(VaccineWrapper vaccineWrapper) { vaccineCard.setVaccineWrapper(vaccineWrapper); vaccineGroup.toggleRecordAllTV(); if (vaccineWrapper.getStatus() == null) { @@ -285,6 +278,11 @@ protected void onPostExecute(VaccineWrapper vaccineWrapper) { notifyDataSetChanged(); } } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } } private void removeVaccine(String vaccineName) { From f436e7cdf8fa286f266bb0d153fe708b95c98c18 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 6 Sep 2022 11:52:00 +0300 Subject: [PATCH 03/19] remove SaveVaccineTask --- .../adapter/ImmunizationRowAdapter.java | 19 +++- .../immunization/util/AppExecutorService.java | 48 -------- .../immunization/util/AppExecutors.java | 105 ++++++++++++++++++ .../immunization/util/CallableInteractor.java | 26 +++++ .../util/CallableInteractorCallBack.java | 9 ++ .../immunization/util/GenericInteractor.java | 37 ++++++ .../adapter/ImmunizationRowAdapterTest.java | 40 ++++++- .../immunization/sample/DetailActivity.java | 45 +++++--- 8 files changed, 262 insertions(+), 67 deletions(-) delete mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java create mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java create mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java create mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java create mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 7ca8e603..e9a16174 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -83,7 +83,7 @@ public View getView(int position, View convertView, ViewGroup parent) { .get(position); String vaccineName = vaccineData.name; if (!vaccineCards.containsKey(vaccineName)) { - ImmunizationRowCard vaccineCard = new ImmunizationRowCard(context, editmode); + ImmunizationRowCard vaccineCard = getImmunizationRowCard(); vaccineCard.setId((int) getItemId(position)); vaccineCards.put(vaccineName, vaccineCard); Callable callable = () -> { @@ -117,8 +117,8 @@ public View getView(int position, View convertView, ViewGroup parent) { updateWrapperStatus(vaccineWrapper, childDetails); return vaccineWrapper; }; - ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = new ImmunizationRowCallableInteractorCallback(vaccineCard, vaccineName); - GenericInteractor interactor = new GenericInteractor(); + ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = getImmunizationRowCallableInteractor(vaccineCard, vaccineName); + GenericInteractor interactor = getGenericInteractor(); interactor.execute(callable, immunizationRowCallableInteractorCallback); } return vaccineCards.get(vaccineName); @@ -128,6 +128,19 @@ public View getView(int position, View convertView, ViewGroup parent) { } } + public GenericInteractor getGenericInteractor() { + return new GenericInteractor(); + } + + public ImmunizationRowCallableInteractorCallback getImmunizationRowCallableInteractor(ImmunizationRowCard vaccineCard, String vaccineName) { + return new ImmunizationRowCallableInteractorCallback(vaccineCard, vaccineName); + } + + + public ImmunizationRowCard getImmunizationRowCard() { + return new ImmunizationRowCard(context, editmode); + } + public void update(ArrayList vaccinesToUpdate) { if (vaccineCards != null) { if (vaccinesToUpdate == null) {// Update all vaccines diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java deleted file mode 100644 index bf8a7b9f..00000000 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutorService.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.smartregister.immunization.util; - -import android.os.Handler; -import android.os.Looper; - -import androidx.annotation.NonNull; - -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * Global ExecutorService for the whole application. - * - * This provides a single thread Executor and main thread Executor for use - */ -public class AppExecutorService { - - private ExecutorService executorService; - private Executor mainThread; - - public AppExecutorService(ExecutorService executorService, Executor mainThread) { - this.executorService = executorService; - this.mainThread = mainThread; - } - - public AppExecutorService() { - this(Executors.newSingleThreadExecutor(), - new AppExecutorService.MainThreadExecutor()); - } - - public ExecutorService executorService() { - return executorService; - } - - public Executor mainThread() { - return mainThread; - } - - private static class MainThreadExecutor implements Executor { - private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); - - @Override - public void execute(@NonNull Runnable command) { - mainThreadHandler.post(command); - } - } -} \ No newline at end of file diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java new file mode 100644 index 00000000..5d334782 --- /dev/null +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java @@ -0,0 +1,105 @@ +package org.smartregister.immunization.util; + + +/** + * Created by keyman on 12/11/18. + */ + +import android.os.Handler; +import android.os.Looper; +import androidx.annotation.NonNull; + +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +/** + * Global executor pools for the whole application. + *

+ * Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind + * webservice requests). + */ +public class AppExecutors { + + private static final int THREAD_COUNT = 3; + + private final Executor diskIO; + + private final Executor networkIO; + + private final Executor mainThread; + + public AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) { + this.diskIO = diskIO; + this.networkIO = networkIO; + this.mainThread = mainThread; + } + + public AppExecutors() { + this(new DiskIOThreadExecutor(), Executors.newFixedThreadPool(THREAD_COUNT), + new MainThreadExecutor()); + } + + public Executor diskIO() { + return diskIO; + } + + public Executor networkIO() { + return networkIO; + } + + public Executor mainThread() { + return mainThread; + } + + /** + * Auto assign the executor by request type + * + * @param runnable + * @param request + */ + public void execute(@NonNull Runnable runnable, @NonNull Request request) { + switch (request) { + case DISK_THREAD: + diskIO().execute(runnable); + break; + case NETWORK_THREAD: + networkIO().execute(runnable); + break; + case MAIN_THREAD: + mainThread().execute(runnable); + break; + default: + throw new IllegalArgumentException("Unknown request"); + } + } + + private static class MainThreadExecutor implements Executor { + private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); + + @Override + public void execute(@NonNull Runnable command) { + mainThreadHandler.post(command); + } + } + + /** + * Executor that runs a task on a new background thread. + */ + private static class DiskIOThreadExecutor implements Executor { + + private final Executor mDiskIO; + + public DiskIOThreadExecutor() { + mDiskIO = Executors.newSingleThreadExecutor(); + } + + @Override + public void execute(@NonNull Runnable command) { + mDiskIO.execute(command); + } + } + + public enum Request { + MAIN_THREAD, NETWORK_THREAD, DISK_THREAD + } +} \ No newline at end of file diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java new file mode 100644 index 00000000..f19ee681 --- /dev/null +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java @@ -0,0 +1,26 @@ +package org.smartregister.immunization.util; + + +import java.util.concurrent.Callable; + +public interface CallableInteractor { + + /** + * This will execute any asyc code using the default request type as AppExecutors.Request.DISK_THREAD + * + * @param callable + * @param callBack + * @param + */ + void execute(Callable callable, CallableInteractorCallBack callBack); + + /** + * This will execute any asyc code using and get returned results + * + * @param callable + * @param callBack + * @param + */ + void execute(Callable callable, CallableInteractorCallBack callBack, AppExecutors.Request request); + +} diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java new file mode 100644 index 00000000..7860c207 --- /dev/null +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java @@ -0,0 +1,9 @@ +package org.smartregister.immunization.util; + +public interface CallableInteractorCallBack { + + void onResult(T t); + + void onError(Exception ex); + +} \ No newline at end of file diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java new file mode 100644 index 00000000..61ec6862 --- /dev/null +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java @@ -0,0 +1,37 @@ +package org.smartregister.immunization.util; + +import java.util.concurrent.Callable; + +import timber.log.Timber; + +public class GenericInteractor implements CallableInteractor { + + protected AppExecutors appExecutors; + + public GenericInteractor() { + appExecutors = new AppExecutors(); + } + + public GenericInteractor(AppExecutors appExecutors) { + this.appExecutors = appExecutors; + } + + @Override + public void execute(Callable callable, CallableInteractorCallBack callBack) { + execute(callable, callBack, AppExecutors.Request.DISK_THREAD); + } + + @Override + public void execute(Callable callable, CallableInteractorCallBack callBack, AppExecutors.Request request) { + Runnable runnable = () -> { + try { + T result = callable.call(); + appExecutors.mainThread().execute(() -> callBack.onResult(result)); + } catch (Exception e) { + Timber.e(e); + appExecutors.mainThread().execute(() -> callBack.onError(e)); + } + }; + appExecutors.execute(runnable, request); + } +} diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 9ed3cd62..88f565b5 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -30,7 +30,10 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.domain.jsonmapping.VaccineGroup; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.util.AppExecutors; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.VaccinatorUtils; +import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; import org.smartregister.util.JsonFormUtils; @@ -40,6 +43,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.Executor; /** * Created by onaio on 30/08/2017. @@ -47,7 +52,7 @@ @PrepareForTest({ImmunizationLibrary.class}) @Config(shadows = {FontTextViewShadow.class, ImageUtilsShadow.class, ImmunizationRowCardShadow.class}) @PowerMockIgnore({"javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*", "org.springframework.context.*", "org.apache.log4j.*"}) -public class ImmunizationRowAdapterTest extends BaseUnitTest { +public class ImmunizationRowAdapterTest extends BaseUnitTest implements Executor { private final String magicDate = "1985-07-24T00:00:00.000Z"; private final int magicNumber = 231231; @@ -191,4 +196,37 @@ public void testUpdateVaccineDate() { Assert.assertEquals(vaccineWrapper.getVaccineDate().year(), new DateTime().plusDays(28).year()); } + @Test + public void testImmunizationRowCallableInteractorCallbackOnResult(){ + ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = + Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); + GenericInteractor interactor = Mockito.spy(new GenericInteractor(new AppExecutors(this, this, this))); + VaccineWrapper vaccineWrapper = new VaccineWrapper(); + Callable vaccineWrapperCallable = ()-> vaccineWrapper; + ImmunizationRowCard mockImmunizationRowCard = Mockito.mock(ImmunizationRowCard.class); + + ImmunizationRowAdapter mockAdapter = Mockito + .spy(new ImmunizationRowAdapter(context, view, true, vaccinelist, alertlist)); + + +// Mockito.when(interactor.execute(Mockito.any(), Mockito.any())).ex + Mockito.doReturn(mockImmunizationRowCard) + .when(mockAdapter).getImmunizationRowCard(); + + Mockito.doReturn(interactor).when(mockAdapter).getGenericInteractor(); + Mockito.doReturn(immunizationRowCallableInteractorCallback).when(mockAdapter).getImmunizationRowCallableInteractor(Mockito.any(),Mockito.anyString()); + + mockAdapter.getView(1, view, null); + Mockito.verify(interactor).execute(Mockito.any(), Mockito.any()); + Mockito.verify(immunizationRowCallableInteractorCallback).onResult(vaccineWrapper); + +// Mockito.doAnswer(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)). +// when(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)); + + } + + @Override + public void execute(Runnable runnable) { + runnable.run(); + } } diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index d1de0e4c..0dc9964b 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -39,6 +39,9 @@ import org.smartregister.immunization.repository.RecurringServiceTypeRepository; import org.smartregister.immunization.repository.VaccineRepository; import org.smartregister.immunization.sample.tabfragments.ImmunizationFragment; +import org.smartregister.immunization.util.CallableInteractor; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.IMConstants; import org.smartregister.immunization.util.RecurringServiceUtils; import org.smartregister.immunization.util.VaccinateActionUtils; @@ -58,6 +61,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import static org.smartregister.util.Utils.getName; @@ -308,35 +312,46 @@ private void saveVaccine(List tags, final View view) { updateVaccineGroupViews(view); } else { VaccineWrapper[] arrayTags = tags.toArray(new VaccineWrapper[tags.size()]); - SaveVaccinesTask backgroundTask = new SaveVaccinesTask(); - backgroundTask.setView(view); - backgroundTask.execute(arrayTags); + Callable callable = ()->{ + for (VaccineWrapper tag:arrayTags){ + saveVaccine(tag); + } + return null; + }; + GenericInteractor interactor = getGenericInteractor(); + SaveVaccineCallableInteractorCallback saveVaccineCallableInteractorCallback = new SaveVaccineCallableInteractorCallback(); + saveVaccineCallableInteractorCallback.setView(view); + interactor.execute(callable, saveVaccineCallableInteractorCallback); + } } - private class SaveVaccinesTask extends AsyncTask { + private GenericInteractor getGenericInteractor() { + return new GenericInteractor(); + } + private class SaveVaccineCallableInteractorCallback implements CallableInteractorCallBack { private View view; - - public void setView(View view) { + public void setView(View view){ this.view = view; } @Override - protected void onPostExecute(Void aVoid) { - updateVaccineGroupViews(view); + public void onResult(Void unused) { + if (view == null || !(view instanceof ImmunizationRowGroup)) { + return; + } + final ImmunizationRowGroup vaccineGroup = (ImmunizationRowGroup) view; + + vaccineGroup.updateViews(); + } @Override - protected Void doInBackground(VaccineWrapper... vaccineWrappers) { - for (VaccineWrapper tag : vaccineWrappers) { - saveVaccine(tag); - } - return null; - } + public void onError(Exception ex) { + } } - private void updateVaccineGroupViews(View view) { if (view == null || !(view instanceof ImmunizationRowGroup)) { return; From dd4c90830c7f2f636a484fadd8ae089bdfe8368f Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 20 Sep 2022 11:25:58 +0300 Subject: [PATCH 04/19] fix immunizationRowAdapter test --- .../immunization/adapter/ImmunizationRowAdapter.java | 8 ++++---- .../adapter/ImmunizationRowAdapterTest.java | 11 ++++++----- .../immunization/sample/DetailActivity.java | 7 ++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index e9a16174..5ac2b475 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -16,12 +16,12 @@ import org.smartregister.immunization.domain.Vaccine; import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; -import org.smartregister.util.CallableInteractorCallBack; -import org.smartregister.util.GenericInteractor; import java.util.ArrayList; import java.util.Calendar; @@ -123,7 +123,7 @@ public View getView(int position, View convertView, ViewGroup parent) { } return vaccineCards.get(vaccineName); } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + Timber.e(e); return null; } } @@ -271,7 +271,7 @@ public void setAlertList(List alertList) { this.alertList = alertList; } - class ImmunizationRowCallableInteractorCallback implements CallableInteractorCallBack{ + class ImmunizationRowCallableInteractorCallback implements CallableInteractorCallBack { private ImmunizationRowCard vaccineCard; private String vaccineName; diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 88f565b5..7e01b2a2 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -200,9 +200,10 @@ public void testUpdateVaccineDate() { public void testImmunizationRowCallableInteractorCallbackOnResult(){ ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); - GenericInteractor interactor = Mockito.spy(new GenericInteractor(new AppExecutors(this, this, this))); - VaccineWrapper vaccineWrapper = new VaccineWrapper(); - Callable vaccineWrapperCallable = ()-> vaccineWrapper; + GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); +// VaccineWrapper vaccineWrapper = new VaccineWrapper(); +// Callable vaccineWrapperCallable = ()-> vaccineWrapper; ImmunizationRowCard mockImmunizationRowCard = Mockito.mock(ImmunizationRowCard.class); ImmunizationRowAdapter mockAdapter = Mockito @@ -213,12 +214,12 @@ public void testImmunizationRowCallableInteractorCallbackOnResult(){ Mockito.doReturn(mockImmunizationRowCard) .when(mockAdapter).getImmunizationRowCard(); - Mockito.doReturn(interactor).when(mockAdapter).getGenericInteractor(); + Mockito.when(mockAdapter.getGenericInteractor()).thenReturn(interactor); Mockito.doReturn(immunizationRowCallableInteractorCallback).when(mockAdapter).getImmunizationRowCallableInteractor(Mockito.any(),Mockito.anyString()); mockAdapter.getView(1, view, null); Mockito.verify(interactor).execute(Mockito.any(), Mockito.any()); - Mockito.verify(immunizationRowCallableInteractorCallback).onResult(vaccineWrapper); + Mockito.verify(immunizationRowCallableInteractorCallback).onResult(Mockito.any()); // Mockito.doAnswer(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)). // when(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)); diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 0dc9964b..9b571d9f 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -65,6 +65,8 @@ import static org.smartregister.util.Utils.getName; +import timber.log.Timber; + /** * Created by raihan on 1/03/2017. */ @@ -338,18 +340,17 @@ public void setView(View view){ @Override public void onResult(Void unused) { - if (view == null || !(view instanceof ImmunizationRowGroup)) { + if ( view == null || !(view instanceof ImmunizationRowGroup) ) { return; } final ImmunizationRowGroup vaccineGroup = (ImmunizationRowGroup) view; vaccineGroup.updateViews(); - } @Override public void onError(Exception ex) { - + Timber.e(ex); } } private void updateVaccineGroupViews(View view) { From 4741d1ce292434c4fb5fb11111817df24603073f Mon Sep 17 00:00:00 2001 From: hilpitome Date: Mon, 26 Sep 2022 00:32:14 +0300 Subject: [PATCH 05/19] create vaccineTask with appexcecutors --- .../adapter/VaccineCardAdapter.java | 72 +++++++++++++------ .../immunization/sample/DetailActivity.java | 5 +- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java index bbc7adee..ecc7d1d7 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java @@ -18,6 +18,8 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.listener.VaccineCardAdapterLoadingListener; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.VaccineCard; @@ -31,12 +33,15 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.smartregister.immunization.util.VaccinatorUtils.generateScheduleList; import static org.smartregister.util.Utils.getName; import static org.smartregister.util.Utils.getValue; +import timber.log.Timber; + /** * Created by Jason Rogena - jrogena@ona.io on 22/02/2017. */ @@ -91,10 +96,20 @@ public View getView(int position, View convertView, ViewGroup parent) { vaccineCard.setId((int) getItemId(position)); vaccineCards.put(vaccineName, vaccineCard); - VaccineRowTask vaccineRowTask = new VaccineRowTask(vaccineCard, vaccineData, - vaccineGroup.getChildDetails(), - vaccineGroup.getVaccineData().days_after_birth_due, position); - Utils.startAsyncTask(vaccineRowTask, null); + VaccineWrapperCallableTask vaccineWrapperCallableTask = + new VaccineWrapperCallableTask(vaccineCard, + vaccineData, + vaccineGroup.getChildDetails(), + vaccineGroup.getVaccineData().days_after_birth_due, + position); + + VaccineRowTaskCallableInteractorCallback vaccineRowTaskCallableInteractorCallback = + new VaccineRowTaskCallableInteractorCallback(vaccineCard, position); + + GenericInteractor interactor = getGenericInteractor(); + + interactor.execute(vaccineWrapperCallableTask, vaccineRowTaskCallableInteractorCallback); + } return vaccineCards.get(vaccineName); @@ -275,8 +290,11 @@ public void setVaccineCardAdapterLoadingListener(VaccineCardAdapterLoadingListen checkRemainingAsyncTasksStatus(); } - class VaccineRowTask extends AsyncTask { + public GenericInteractor getGenericInteractor() { + return new GenericInteractor(); + } + private class VaccineWrapperCallableTask implements Callable { private VaccineCard vaccineCard; private String vaccineName; @@ -287,24 +305,24 @@ class VaccineRowTask extends AsyncTask { private int position; private org.smartregister.immunization.domain.jsonmapping.Vaccine vaccineData; + VaccineWrapperCallableTask (VaccineCard vaccineCard, org.smartregister.immunization.domain.jsonmapping.Vaccine vaccineData, + CommonPersonObjectClient childDetails, Integer days_after_birth_due, int position){ + this.vaccineCard = vaccineCard; + vaccineName = vaccineData.name; + this.childDetails = childDetails; + this.days_after_birth_due = days_after_birth_due; + this.position = position; + this.vaccineData = vaccineData; + } - VaccineRowTask(VaccineCard vaccineCard, org.smartregister.immunization.domain.jsonmapping.Vaccine vaccineData, - CommonPersonObjectClient childDetails, Integer days_after_birth_due, int position) { - this.vaccineCard = vaccineCard; - vaccineName = vaccineData.name; - this.childDetails = childDetails; - this.days_after_birth_due = days_after_birth_due; - this.position = position; - this.vaccineData = vaccineData; - } @Override - protected VaccineWrapper doInBackground(Void... params) { + public VaccineWrapper call() throws Exception { VaccineWrapper vaccineWrapper = new VaccineWrapper(); vaccineWrapper.setId(childDetails.entityId()); vaccineWrapper.setGender(childDetails.getDetails().get("gender")); - vaccineWrapper.setName(vaccineName); - vaccineWrapper.setDefaultName(vaccineName); + vaccineWrapper.setName(vaccineData.name); + vaccineWrapper.setDefaultName(vaccineData.name); if (vaccineData.schedule != null && vaccineData.schedule.conditions != null) { vaccineWrapper.setNotGivenCondition(vaccineData.schedule.conditions.get(0).vaccine); } @@ -331,13 +349,21 @@ protected VaccineWrapper doInBackground(Void... params) { updateWrapper(vaccineWrapper); updateWrapperStatus(vaccineWrapper, type, childDetails); - return vaccineWrapper; } + } + + public class VaccineRowTaskCallableInteractorCallback implements CallableInteractorCallBack{ + private VaccineCard vaccineCard; + private int position; + VaccineRowTaskCallableInteractorCallback(VaccineCard vaccineCard, int position){ + this.vaccineCard = vaccineCard; + this.position = position; + } @Override - protected void onPostExecute(VaccineWrapper vaccineWrapper) { - vaccineCard.setVaccineWrapper(vaccineWrapper); + public void onResult(VaccineWrapper vaccineWrapper) { + this.vaccineCard.setVaccineWrapper(vaccineWrapper); //If last position, toggle RecordAll if (position == (getCount() - 1)) { @@ -346,6 +372,12 @@ protected void onPostExecute(VaccineWrapper vaccineWrapper) { notifyDataSetChanged(); notifyAsyncTaskCompleted(); } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } } + } diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 9b571d9f..3def8cdc 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -328,7 +328,7 @@ private void saveVaccine(List tags, final View view) { } } - private GenericInteractor getGenericInteractor() { + public GenericInteractor getGenericInteractor() { return new GenericInteractor(); } @@ -344,8 +344,9 @@ public void onResult(Void unused) { return; } final ImmunizationRowGroup vaccineGroup = (ImmunizationRowGroup) view; - + Timber.e("before update views"); vaccineGroup.updateViews(); + Timber.e("after update views"); } @Override From c6b92a0612571793dbdef2b9ce92e71f95812054 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 27 Sep 2022 10:40:42 +0300 Subject: [PATCH 06/19] migarate ServiceTask --- .../adapter/ServiceCardAdapter.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java index c40005be..2da51396 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java @@ -17,6 +17,8 @@ import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceCard; @@ -30,6 +32,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.smartregister.immunization.util.VaccinatorUtils.generateScheduleList; @@ -37,6 +40,8 @@ import static org.smartregister.util.Utils.getName; import static org.smartregister.util.Utils.getValue; +import timber.log.Timber; + /** * Created by keyman on 15/05/2017. */ @@ -122,8 +127,12 @@ public View getView(int position, View convertView, ViewGroup parent) { serviceCard.setId((int) getItemId(position)); serviceCards.put(type, serviceCard); - ServiceCardTask serviceRowTask = new ServiceCardTask(serviceCard, serviceGroup.getChildDetails(), type); - Utils.startAsyncTask(serviceRowTask, null); + ServiceCardTaskCallable callable = new ServiceCardTaskCallable(serviceGroup.getChildDetails(), type); + ServiceCardTaskCallableInteractorCallable callableInteractorCallaback = new ServiceCardTaskCallableInteractorCallable(serviceCard); + GenericInteractor interactor = genericInteractor(); + + interactor.execute(callable, callableInteractorCallaback); + } return serviceCards.get(type); @@ -291,22 +300,23 @@ public void updateWrapper(ServiceWrapper tag) { } - class ServiceCardTask extends AsyncTask { + public GenericInteractor genericInteractor(){ + return new GenericInteractor(); + } - private ServiceCard serviceCard; + public class ServiceCardTaskCallable implements Callable { private CommonPersonObjectClient childDetails; private String type; - ServiceCardTask(ServiceCard serviceCard, CommonPersonObjectClient childDetails, String type) { - this.serviceCard = serviceCard; + ServiceCardTaskCallable(CommonPersonObjectClient childDetails, String type) { this.childDetails = childDetails; this.type = type; } @Override - protected ServiceWrapper doInBackground(Void... params) { + public ServiceWrapper call() throws Exception { ServiceWrapper serviceWrapper = new ServiceWrapper(); serviceWrapper.setId(childDetails.entityId()); serviceWrapper.setGender(childDetails.getDetails().get("gender")); @@ -336,13 +346,27 @@ protected ServiceWrapper doInBackground(Void... params) { return serviceWrapper; } + } + + public class ServiceCardTaskCallableInteractorCallable implements CallableInteractorCallBack{ + + private ServiceCard serviceCard; + + public ServiceCardTaskCallableInteractorCallable(ServiceCard serviceCard){ + this.serviceCard = serviceCard; + } @Override - protected void onPostExecute(ServiceWrapper serviceWrapper) { + public void onResult(ServiceWrapper serviceWrapper) { serviceCard.setServiceWrapper(serviceWrapper); visibilityCheck(); notifyDataSetChanged(); } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } } public void updateServiceRecordList(List serviceRecordList) { From a84d2f5f8117f9e58969faee7f27c046c506dc66 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 27 Sep 2022 11:03:11 +0300 Subject: [PATCH 07/19] migrate ServerRowTask --- .../adapter/ServiceRowAdapter.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index 95ac0ec3..aaad1a6d 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -16,6 +16,8 @@ import org.smartregister.immunization.domain.ServiceType; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceRowCard; @@ -29,12 +31,15 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.smartregister.immunization.util.VaccinatorUtils.generateScheduleList; import static org.smartregister.util.Utils.getName; import static org.smartregister.util.Utils.getValue; +import timber.log.Timber; + /** * Created by keyman on 15/05/2017. */ @@ -88,9 +93,13 @@ public View getView(int position, View convertView, ViewGroup parent) { serviceRowCard.setId((int) getItemId(position)); serviceRowCards.put(serviceType.getName(), serviceRowCard); - ServiceRowTask serviceRowTask = new ServiceRowTask(serviceRowGroup.getChildDetails() - , serviceType, serviceRowCard); - Utils.startAsyncTask(serviceRowTask, null); + ServiceRowTaskCallable callable = new ServiceRowTaskCallable(serviceRowGroup.getChildDetails(), + serviceType); + ServiceRowTaskCallableInteractorCallBack callableInteractorCallBack + = new ServiceRowTaskCallableInteractorCallBack(serviceRowCard); + GenericInteractor interactor = getGenericInteractor(); + + interactor.execute(callable, callableInteractorCallBack); } return serviceRowCards.get(serviceType.getName()); @@ -174,25 +183,25 @@ public void updateWrapper(ServiceWrapper tag) { } } } + } + public GenericInteractor getGenericInteractor(){ + return new GenericInteractor(); } - class ServiceRowTask extends AsyncTask { + class ServiceRowTaskCallable implements Callable { private CommonPersonObjectClient childDetails; private ServiceType serviceType; - private ServiceRowCard serviceRowCard; - - ServiceRowTask(CommonPersonObjectClient childDetails, ServiceType serviceType, ServiceRowCard serviceRowCard) { + ServiceRowTaskCallable(CommonPersonObjectClient childDetails, ServiceType serviceType){ this.childDetails = childDetails; this.serviceType = serviceType; - this.serviceRowCard = serviceRowCard; } @Override - protected ServiceWrapper doInBackground(Void... params) { + public ServiceWrapper call() throws Exception { ServiceWrapper serviceWrapper = new ServiceWrapper(); serviceWrapper.setId(childDetails.entityId()); serviceWrapper.setGender(childDetails.getDetails().get("gender")); @@ -222,12 +231,25 @@ protected ServiceWrapper doInBackground(Void... params) { return serviceWrapper; } + } + + public class ServiceRowTaskCallableInteractorCallBack implements CallableInteractorCallBack { + private final ServiceRowCard serviceRowCard; + + ServiceRowTaskCallableInteractorCallBack(ServiceRowCard serviceRowCard){ + this.serviceRowCard = serviceRowCard; + } @Override - protected void onPostExecute(ServiceWrapper serviceWrapper) { + public void onResult(ServiceWrapper serviceWrapper) { serviceRowCard.setServiceWrapper(serviceWrapper); notifyDataSetChanged(); } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } } } From a48f55fe904ae96b700636a1675dbe23cdea2361 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 27 Sep 2022 12:56:33 +0300 Subject: [PATCH 08/19] migrate SaveServiceTask and UndoServiceTask --- .../immunization/sample/DetailActivity.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 3def8cdc..35796b23 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -18,6 +18,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Triple; +import org.checkerframework.checker.units.qual.A; +import org.checkerframework.framework.qual.Unused; import org.joda.time.DateTime; import org.json.JSONArray; import org.json.JSONException; @@ -39,6 +41,7 @@ import org.smartregister.immunization.repository.RecurringServiceTypeRepository; import org.smartregister.immunization.repository.VaccineRepository; import org.smartregister.immunization.sample.tabfragments.ImmunizationFragment; +import org.smartregister.immunization.util.AppExecutors; import org.smartregister.immunization.util.CallableInteractor; import org.smartregister.immunization.util.CallableInteractorCallBack; import org.smartregister.immunization.util.GenericInteractor; @@ -82,6 +85,7 @@ public class DetailActivity extends AppCompatActivity implements VaccinationActi public static final String EXTRA_CHILD_DETAILS = "child_details"; public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy"); private ImmunizationFragment immunizationFragment; + private AppExecutors appExecutors; public CommonPersonObjectClient getChildDetails() { return childDetails; @@ -234,7 +238,8 @@ private boolean isDataOk() { public void onVaccinateToday(ArrayList tags, View view) { if (tags != null && !tags.isEmpty()) { saveVaccine(tags, view); - Utils.startAsyncTask(new UpdateOfflineAlertsTask(), null); + appExecutors = new AppExecutors(); + appExecutors.diskIO().execute(UpdateOfflineAlertsTaskCallable::new); } } @@ -242,7 +247,8 @@ public void onVaccinateToday(ArrayList tags, View view) { public void onVaccinateEarlier(ArrayList tags, View view) { if (tags != null && !tags.isEmpty()) { saveVaccine(tags, view); - Utils.startAsyncTask(new UpdateOfflineAlertsTask(), null); + appExecutors = new AppExecutors(); + appExecutors.diskIO().execute(UpdateOfflineAlertsTaskCallable::new); } } @@ -265,7 +271,8 @@ public void onUndoVaccination(VaccineWrapper tag, View view) { wrappers.add(tag); updateVaccineGroupViews(view, wrappers, vaccineList, true); - Utils.startAsyncTask(new UpdateOfflineAlertsTask(), null); + appExecutors = new AppExecutors(); + appExecutors.diskIO().execute(UpdateOfflineAlertsTaskCallable::new); } } } @@ -495,7 +502,13 @@ public void onGiveEarlier(ServiceWrapper tag, View view) { @Override public void onUndoService(ServiceWrapper tag, View view) { - Utils.startAsyncTask(new UndoServiceTask(tag, view), null); + + UndoServiceCallableTask callableTask = new UndoServiceCallableTask(tag); + UndoServiceCallableInteractorCallback callableInteractorCallback = new UndoServiceCallableInteractorCallback(view, tag); + GenericInteractor interactor = getGenericInteractor(); + + interactor.execute(callableTask, callableInteractorCallback); + } public void saveService(ServiceWrapper tag, final View view) { @@ -551,26 +564,19 @@ protected Triple, List, List> do } } - private class UndoServiceTask extends AsyncTask { + private class UndoServiceCallableTask implements Callable, ArrayList, List>>{ - private View view; private ServiceWrapper tag; private List serviceRecordList; private ArrayList wrappers; private List alertList; - public UndoServiceTask(ServiceWrapper tag, View view) { + public UndoServiceCallableTask(ServiceWrapper tag){ this.tag = tag; - this.view = view; - } - - @Override - protected void onPreExecute() { - super.onPreExecute(); } @Override - protected Void doInBackground(Void... params) { + public Triple, ArrayList, List> call() throws Exception { if (tag != null) { if (tag.getDbKey() != null) { @@ -593,23 +599,41 @@ protected Void doInBackground(Void... params) { alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), alertArray); } } - return null; + return Triple.of(serviceRecordList, wrappers, alertList); } + } - @Override - protected void onPostExecute(Void params) { - super.onPostExecute(params); + private class UndoServiceCallableInteractorCallback implements CallableInteractorCallBack, ArrayList, List>> { + + private final View view; + private final ServiceWrapper tag; + UndoServiceCallableInteractorCallback(View view, ServiceWrapper tag){ + this.view = view; + this.tag = tag; + } + + @Override + public void onResult(Triple, ArrayList, List> serviceRecordsWrappersAlertsTriple) { tag.setUpdatedVaccineDate(null, false); tag.setDbKey(null); + ArrayList wrappers = serviceRecordsWrappersAlertsTriple.getMiddle(); + List serviceRecordList = serviceRecordsWrappersAlertsTriple.getLeft(); + List alertList = serviceRecordsWrappersAlertsTriple.getRight(); RecurringServiceUtils.updateServiceGroupViews(view, wrappers, serviceRecordList, alertList, true); } + + @Override + public void onError(Exception ex) { + + } } - private class UpdateOfflineAlertsTask extends AsyncTask { + private class UpdateOfflineAlertsTaskCallable implements Callable{ + @Override - protected Void doInBackground(Void... params) { + public Void call() throws Exception { DateTime birthDateTime = Utils.dobToDateTime(childDetails); if (birthDateTime != null) { VaccineSchedule.updateOfflineAlertsOnly(childDetails.entityId(), birthDateTime, IMConstants.VACCINE_TYPE.CHILD); From e7a9195f3b392d2df00fc2e04fc63b3aaa4801cc Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 27 Sep 2022 18:00:32 +0300 Subject: [PATCH 09/19] migrate sample SaveServiceTask --- .../immunization/sample/DetailActivity.java | 65 +++++++++++++++++-- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 35796b23..1440a1c5 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -517,14 +517,69 @@ public void saveService(ServiceWrapper tag, final View view) { } ServiceWrapper[] arrayTags = {tag}; - SaveServiceTask backgroundTask = new SaveServiceTask(); - backgroundTask.setView(view); - Utils.startAsyncTask(backgroundTask, arrayTags); + SaveServiceCallableTask saveServiceCallableTask = new SaveServiceCallableTask(arrayTags); + SaveServiceCallableInteractorCallaback callableInteractorCallaback = new SaveServiceCallableInteractorCallaback(view); + GenericInteractor interactor = getGenericInteractor(); + + interactor.execute(saveServiceCallableTask, callableInteractorCallaback); + + } + + public class SaveServiceCallableTask implements Callable, List, List>> { + + private final ServiceWrapper[] arrayTags; + + SaveServiceCallableTask(ServiceWrapper[] arrayTags){ + this.arrayTags = arrayTags; + } + @Override + public Triple, List, List> call() throws Exception { + ArrayList list = new ArrayList<>(); + + for (ServiceWrapper tag : arrayTags) { + RecurringServiceUtils.saveService(tag, childDetails.entityId(), null, null, null, null, null); + list.add(tag); + + ServiceSchedule.updateOfflineAlerts(tag.getType(), childDetails.entityId(), Utils.dobToDateTime(childDetails)); + } + + RecurringServiceRecordRepository recurringServiceRecordRepository = ImmunizationLibrary.getInstance().recurringServiceRecordRepository(); + List serviceRecordList = recurringServiceRecordRepository.findByEntityId(childDetails.entityId()); + + RecurringServiceTypeRepository recurringServiceTypeRepository = ImmunizationLibrary.getInstance().recurringServiceTypeRepository(); + List serviceTypes = recurringServiceTypeRepository.fetchAll(); + String[] alertArray = VaccinateActionUtils.allAlertNames(serviceTypes); + + AlertService alertService = ImmunizationLibrary.getInstance().context().alertService(); + List alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), alertArray); + + return Triple.of(list, serviceRecordList, alertList); + } + } + + private class SaveServiceCallableInteractorCallaback implements CallableInteractorCallBack, List, List>>{ + + private View view; + + SaveServiceCallableInteractorCallaback(View view){ + this.view = view; + } + + @Override + public void onResult(Triple, List, List> triple) { + RecurringServiceUtils.updateServiceGroupViews(view, triple.getLeft(), triple.getMiddle(), triple.getRight()); + + } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } } - public class SaveServiceTask extends AsyncTask, List, List>> { + private class SaveServiceTask extends AsyncTask, List, List>> { private View view; @@ -626,7 +681,7 @@ public void onResult(Triple, ArrayList, List @Override public void onError(Exception ex) { - + Timber.e(ex); } } From 1c826d849917afcffd296c3d3eed24c8065031bd Mon Sep 17 00:00:00 2001 From: hilpitome Date: Thu, 29 Sep 2022 10:51:58 +0300 Subject: [PATCH 10/19] code refactor --- .../immunization/adapter/ImmunizationRowAdapter.java | 4 +++- .../immunization/adapter/ImmunizationRowAdapterTest.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 5ac2b475..9312f068 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -50,6 +50,7 @@ public class ImmunizationRowAdapter extends BaseAdapter { private HashMap vaccineCards; private List vaccineList; private List alertList; + private GenericInteractor mInteractor; public ImmunizationRowAdapter(Context context, ImmunizationRowGroup vaccineGroup, boolean editmode, List vaccineList, List alertList) { @@ -59,6 +60,7 @@ public ImmunizationRowAdapter(Context context, ImmunizationRowGroup vaccineGroup this.vaccineList = vaccineList; this.alertList = alertList; vaccineCards = new HashMap<>(); + mInteractor = new GenericInteractor(); } @Override @@ -129,7 +131,7 @@ public View getView(int position, View convertView, ViewGroup parent) { } public GenericInteractor getGenericInteractor() { - return new GenericInteractor(); + return mInteractor; } public ImmunizationRowCallableInteractorCallback getImmunizationRowCallableInteractor(ImmunizationRowCard vaccineCard, String vaccineName) { diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 7e01b2a2..7203ced1 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -197,7 +197,7 @@ public void testUpdateVaccineDate() { } @Test - public void testImmunizationRowCallableInteractorCallbackOnResult(){ + public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); From 9bd9869507b2c92c8b24ac7931bbd67973f4decb Mon Sep 17 00:00:00 2001 From: hilpitome Date: Thu, 29 Sep 2022 12:58:35 +0300 Subject: [PATCH 11/19] test ImmunizationRowCallableOnError --- .../adapter/ImmunizationRowAdapterTest.java | 20 ++++++++- .../immunization/sample/DetailActivity.java | 41 ------------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 7203ced1..7c644c28 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -202,8 +202,7 @@ public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); interactor = Mockito.spy(interactor); -// VaccineWrapper vaccineWrapper = new VaccineWrapper(); -// Callable vaccineWrapperCallable = ()-> vaccineWrapper; + ImmunizationRowCard mockImmunizationRowCard = Mockito.mock(ImmunizationRowCard.class); ImmunizationRowAdapter mockAdapter = Mockito @@ -226,6 +225,23 @@ public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ } + @Test + public void testGetViewsCallsImmunizationCallbackInteractorOnError(){ + ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = + Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); + GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); + + Exception exception = new IllegalStateException("Some Exception"); + Callable callable = () -> { + throw exception; + }; + + interactor.execute(callable, immunizationRowCallableInteractorCallback); + + Mockito.verify(immunizationRowCallableInteractorCallback).onError(exception); + } + @Override public void execute(Runnable runnable) { runnable.run(); diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 1440a1c5..79e4824d 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -578,47 +578,6 @@ public void onError(Exception ex) { } } - - private class SaveServiceTask extends AsyncTask, List, List>> { - - private View view; - - public void setView(View view) { - this.view = view; - } - - @Override - protected void onPostExecute(Triple, List, List> triple) { - RecurringServiceUtils.updateServiceGroupViews(view, triple.getLeft(), triple.getMiddle(), triple.getRight()); - } - - @Override - protected Triple, List, List> doInBackground(ServiceWrapper... params) { - - ArrayList list = new ArrayList<>(); - - for (ServiceWrapper tag : params) { - RecurringServiceUtils.saveService(tag, childDetails.entityId(), null, null, null, null, null); - list.add(tag); - - ServiceSchedule.updateOfflineAlerts(tag.getType(), childDetails.entityId(), Utils.dobToDateTime(childDetails)); - } - - RecurringServiceRecordRepository recurringServiceRecordRepository = ImmunizationLibrary.getInstance().recurringServiceRecordRepository(); - List serviceRecordList = recurringServiceRecordRepository.findByEntityId(childDetails.entityId()); - - RecurringServiceTypeRepository recurringServiceTypeRepository = ImmunizationLibrary.getInstance().recurringServiceTypeRepository(); - List serviceTypes = recurringServiceTypeRepository.fetchAll(); - String[] alertArray = VaccinateActionUtils.allAlertNames(serviceTypes); - - AlertService alertService = ImmunizationLibrary.getInstance().context().alertService(); - List alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), alertArray); - - return Triple.of(list, serviceRecordList, alertList); - - } - } - private class UndoServiceCallableTask implements Callable, ArrayList, List>>{ private ServiceWrapper tag; From a71feab9b55c0c0ebdf4d9e4eec9e1efb729d299 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Tue, 4 Oct 2022 12:32:02 +0300 Subject: [PATCH 12/19] test new service row task --- .../adapter/ServiceRowAdapter.java | 10 +++--- .../adapter/ServiceRowAdapterTest.java | 31 ++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index aaad1a6d..83ce955e 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -1,7 +1,6 @@ package org.smartregister.immunization.adapter; import android.content.Context; -import android.os.AsyncTask; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -22,7 +21,6 @@ import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceRowCard; import org.smartregister.immunization.view.ServiceRowGroup; -import org.smartregister.util.Utils; import java.util.ArrayList; import java.util.Calendar; @@ -96,7 +94,7 @@ public View getView(int position, View convertView, ViewGroup parent) { ServiceRowTaskCallable callable = new ServiceRowTaskCallable(serviceRowGroup.getChildDetails(), serviceType); ServiceRowTaskCallableInteractorCallBack callableInteractorCallBack - = new ServiceRowTaskCallableInteractorCallBack(serviceRowCard); + = getServiceRowTaskCallableInteractor(serviceRowCard); GenericInteractor interactor = getGenericInteractor(); interactor.execute(callable, callableInteractorCallBack); @@ -104,11 +102,15 @@ public View getView(int position, View convertView, ViewGroup parent) { return serviceRowCards.get(serviceType.getName()); } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); + Timber.e(e); return null; } } + public ServiceRowTaskCallableInteractorCallBack getServiceRowTaskCallableInteractor(ServiceRowCard serviceRowCard) { + return new ServiceRowTaskCallableInteractorCallBack(serviceRowCard); + } + public void update(ArrayList servicesToUpdate) { if (serviceRowCards != null) { if (servicesToUpdate == null) {// Update all vaccines diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java index 56fcda96..1063b9db 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java @@ -10,6 +10,8 @@ import org.junit.Test; import org.mockito.Mock; import androidx.test.core.app.ApplicationProvider; + +import org.mockito.Mockito; import org.robolectric.annotation.Config; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Alert; @@ -22,6 +24,8 @@ import org.smartregister.immunization.domain.ServiceTypeTest; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.domain.ServiceWrapperTest; +import org.smartregister.immunization.util.AppExecutors; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.view.ServiceRowGroup; import java.util.ArrayList; @@ -29,12 +33,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Executor; /** * Created by onaio on 30/08/2017. */ @Config (shadows = {FontTextViewShadow.class, ImageUtilsShadow.class, ServiceRowCardShadow.class}) -public class ServiceRowAdapterTest extends BaseUnitTest { +public class ServiceRowAdapterTest extends BaseUnitTest implements Executor { private final int magicNumber = 231231; private final String magicDate = "1985-07-24T00:00:00.000Z"; @@ -142,4 +147,28 @@ public void assertGetViewReturnsServiceRowView() { Assert.assertEquals(serviceRowAdapter.getView(0, null, null) != null, true); } + @Test + public void testGetViewCallsServiceRowTaskCallableInteractorCallBackOnResult(){ + ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack serviceRowTaskCallableInteractorCallBack = + Mockito.mock(ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack.class); + GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); + + + ServiceRowAdapter mockAdapter = Mockito + .spy(new ServiceRowAdapter(ApplicationProvider.getApplicationContext(), view, false, serviceTypeList, serviceRecordList, alertList)); + + Mockito.when(mockAdapter.getGenericInteractor()).thenReturn(interactor); + Mockito.doReturn(serviceRowTaskCallableInteractorCallBack).when(mockAdapter).getServiceRowTaskCallableInteractor(Mockito.any()); + + mockAdapter.getView(0, view, null); + Mockito.verify(interactor).execute(Mockito.any(), Mockito.any()); + Mockito.verify(serviceRowTaskCallableInteractorCallBack).onResult(Mockito.any()); + + } + + @Override + public void execute(Runnable runnable) { + runnable.run(); + } } From 7cd361198cbb78c04351554133e1c14993984a05 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Thu, 6 Oct 2022 12:43:53 +0300 Subject: [PATCH 13/19] test ServiceRowAdapter task executor --- .../adapter/ServiceCardAdapter.java | 18 +++++++----- .../adapter/ServiceCardAdapterTest.java | 29 +++++++++++++++++-- .../adapter/ServiceRowAdapterTest.java | 18 ++++++++++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java index 2da51396..ddee8ccc 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java @@ -1,7 +1,6 @@ package org.smartregister.immunization.adapter; import android.content.Context; -import android.os.AsyncTask; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -23,7 +22,6 @@ import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceCard; import org.smartregister.immunization.view.ServiceGroup; -import org.smartregister.util.Utils; import java.util.ArrayList; import java.util.Calendar; @@ -55,6 +53,7 @@ public class ServiceCardAdapter extends BaseAdapter { private Map> serviceTypeMap; private boolean isChildActive = true; + private GenericInteractor mGenericInteractor; public ServiceCardAdapter(Context context, ServiceGroup serviceGroup, List serviceRecordList, List alertList, Map> serviceTypeMap) { @@ -64,6 +63,7 @@ public ServiceCardAdapter(Context context, ServiceGroup serviceGroup, List(); + mGenericInteractor = new GenericInteractor(); } public void updateAll() { @@ -128,8 +128,8 @@ public View getView(int position, View convertView, ViewGroup parent) { serviceCards.put(type, serviceCard); ServiceCardTaskCallable callable = new ServiceCardTaskCallable(serviceGroup.getChildDetails(), type); - ServiceCardTaskCallableInteractorCallable callableInteractorCallaback = new ServiceCardTaskCallableInteractorCallable(serviceCard); - GenericInteractor interactor = genericInteractor(); + ServiceCardTaskCallableInteractorCallable callableInteractorCallaback = getServiceCardTaskCallableInteractorCallable(serviceCard); + GenericInteractor interactor = getGenericInteractor(); interactor.execute(callable, callableInteractorCallaback); @@ -143,6 +143,10 @@ public View getView(int position, View convertView, ViewGroup parent) { } + public ServiceCardTaskCallableInteractorCallable getServiceCardTaskCallableInteractorCallable(ServiceCard serviceCard) { + return new ServiceCardTaskCallableInteractorCallable(serviceCard); + } + public boolean atLeastOneVisibleCard() { if (serviceCards != null) { for (ServiceCard serviceCard : serviceCards.values()) { @@ -300,8 +304,8 @@ public void updateWrapper(ServiceWrapper tag) { } - public GenericInteractor genericInteractor(){ - return new GenericInteractor(); + public GenericInteractor getGenericInteractor(){ + return mGenericInteractor; } public class ServiceCardTaskCallable implements Callable { @@ -316,7 +320,7 @@ public class ServiceCardTaskCallable implements Callable { } @Override - public ServiceWrapper call() throws Exception { + public ServiceWrapper call() { ServiceWrapper serviceWrapper = new ServiceWrapper(); serviceWrapper.setId(childDetails.entityId()); serviceWrapper.setGender(childDetails.getDetails().get("gender")); diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java index 6058a214..827438be 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java @@ -24,6 +24,8 @@ import org.smartregister.immunization.domain.ServiceTypeTest; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.domain.ServiceWrapperTest; +import org.smartregister.immunization.util.AppExecutors; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.view.ServiceCard; import org.smartregister.immunization.view.ServiceGroup; @@ -32,12 +34,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Executor; /** * Created by onaio on 30/08/2017. */ @Config(shadows = {FontTextViewShadow.class, ImageUtilsShadow.class, ServiceCardShadow.class}) -public class ServiceCardAdapterTest extends BaseUnitTest { +public class ServiceCardAdapterTest extends BaseUnitTest implements Executor { private final String magicDate = "1985-07-24T00:00:00.000Z"; private final String type = "SERVICETYPE"; @@ -57,6 +60,7 @@ public class ServiceCardAdapterTest extends BaseUnitTest { private List serviceTypeList = new ArrayList<>(); private List serviceRecordList = new ArrayList<>(); private Map> alertList = new HashMap<>(); + private HashMap> serviceTypeMap; public static List getServiceTypeKeys(HashMap> vaccineData) { List keys = new ArrayList<>(); @@ -106,7 +110,7 @@ public void setDataForTest(String dateTimeString) { List alertlist = new ArrayList(); alertlist.add(alert); - Map> serviceTypeMap = new HashMap<>(); + serviceTypeMap = new HashMap<>(); ServiceType serviceType = new ServiceType(); serviceType.setId(0l); serviceType.setType(ServiceTypeTest.TYPE); @@ -192,4 +196,25 @@ public void testUpdateChildsActiveStatus() { serviceCardAdapter.updateChildsActiveStatus(); Mockito.verify(serviceCard).updateChildsActiveStatus(); } + + @Test + public void testGetViewCallsServiceCardTaskCallableInteractorCallableOnResult(){ + ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable serviceCardTaskCallableInteractorCallable + = Mockito.mock(ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable.class); + GenericInteractor interactor= new GenericInteractor(new AppExecutors(this, this , this)); + interactor = Mockito.spy(interactor); + + ServiceCardAdapter mockAdapter = Mockito.spy(serviceCardAdapter); + Mockito.when(mockAdapter.getGenericInteractor()).thenReturn(interactor); + Mockito.when(mockAdapter.getServiceCardTaskCallableInteractorCallable(Mockito.any())).thenReturn(serviceCardTaskCallableInteractorCallable); + + mockAdapter.getView(0, view, null); + Mockito.verify(serviceCardTaskCallableInteractorCallable).onResult(Mockito.any()); + + } + + @Override + public void execute(Runnable runnable) { + runnable.run(); + } } diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java index 1063b9db..c0867687 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java @@ -33,6 +33,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.Executor; /** @@ -161,12 +162,29 @@ public void testGetViewCallsServiceRowTaskCallableInteractorCallBackOnResult(){ Mockito.when(mockAdapter.getGenericInteractor()).thenReturn(interactor); Mockito.doReturn(serviceRowTaskCallableInteractorCallBack).when(mockAdapter).getServiceRowTaskCallableInteractor(Mockito.any()); + mockAdapter.getView(0, view, null); Mockito.verify(interactor).execute(Mockito.any(), Mockito.any()); Mockito.verify(serviceRowTaskCallableInteractorCallBack).onResult(Mockito.any()); } + @Test + public void testGetViewCallsServiceRowTaskCallableInteractorCallbackonError(){ + ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack serviceRowTaskCallableInteractorCallBack + = Mockito.mock(ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack.class); + GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + Exception exception = new IllegalStateException("some exception"); + Callable callable = () -> { + throw exception; + }; + + interactor.execute(callable, serviceRowTaskCallableInteractorCallBack); + + Mockito.verify(serviceRowTaskCallableInteractorCallBack).onError(exception); + + } + @Override public void execute(Runnable runnable) { runnable.run(); From 344625cadb3d29bc960ee69fbcadcd358ecde165 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 7 Oct 2022 13:02:26 +0300 Subject: [PATCH 14/19] eliminate asyncTasks from MainActivity --- .../adapter/ServiceCardAdapterTest.java | 17 + .../immunization/sample/MainActivity.java | 320 ++++++++++-------- 2 files changed, 190 insertions(+), 147 deletions(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java index 827438be..cf017098 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.concurrent.Executor; /** @@ -213,6 +214,22 @@ public void testGetViewCallsServiceCardTaskCallableInteractorCallableOnResult(){ } + @Test + public void testGetViewCallsServiceRowTaskCallableInteractorCallbackonError(){ + ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable serviceCardTaskCallableInteractorCallable + = Mockito.mock(ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable.class); + GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + Exception exception = new IllegalStateException("some exception"); + Callable callable = () -> { + throw exception; + }; + + interactor.execute(callable, serviceCardTaskCallableInteractorCallable); + + Mockito.verify(serviceCardTaskCallableInteractorCallable).onError(exception); + + } + @Override public void execute(Runnable runnable) { runnable.run(); diff --git a/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java index fc64fe57..9fdae022 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.Intent; -import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -50,6 +49,9 @@ import org.smartregister.immunization.sample.util.SampleUtil; import org.smartregister.immunization.service.intent.RecurringIntentService; import org.smartregister.immunization.service.intent.VaccineIntentService; +import org.smartregister.immunization.util.AppExecutors; +import org.smartregister.immunization.util.CallableInteractorCallBack; +import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.IMConstants; import org.smartregister.immunization.util.IMDatabaseConstants; import org.smartregister.immunization.util.RecurringServiceUtils; @@ -69,6 +71,9 @@ import java.util.List; import java.util.Map; import java.util.Random; +import java.util.concurrent.Callable; + +import timber.log.Timber; /** * Created by Jason Rogena - jrogena@ona.io on 16/02/2017. @@ -85,6 +90,7 @@ public class MainActivity extends AppCompatActivity implements VaccinationAction private CommonPersonObjectClient childDetails = SampleUtil.dummyDetatils(); private ArrayList vaccineGroups; private ArrayList serviceGroups; + private GenericInteractor genericInteractor = new GenericInteractor(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -173,12 +179,15 @@ public void onClick(View v) { AlertService alertService = ImmunizationLibrary.getInstance().context().alertService(); - UpdateViewTask updateViewTask = new UpdateViewTask(); - updateViewTask.setVaccineRepository(vaccineRepository); - updateViewTask.setRecurringServiceTypeRepository(recurringServiceTypeRepository); - updateViewTask.setRecurringServiceRecordRepository(recurringServiceRecordRepository); - updateViewTask.setAlertService(alertService); - Utils.startAsyncTask(updateViewTask, null); + UpdateViewTaskCallableInteractorCallback updateViewTaskCallableInteractorCallback = new UpdateViewTaskCallableInteractorCallback(); + UpdateViewTaskCallable callable = new UpdateViewTaskCallable(); + callable.setVaccineRepository(vaccineRepository); + callable.setRecurringServiceTypeRepository(recurringServiceTypeRepository); + callable.setRecurringServiceRecordRepository(recurringServiceRecordRepository); + callable.setAlertService(alertService); + + genericInteractor.execute(callable, updateViewTaskCallableInteractorCallback); + } private void updateChildIdViews() { @@ -395,7 +404,9 @@ public void onVaccinateEarlier(ArrayList tags, View v) { @Override public void onUndoVaccination(VaccineWrapper tag, View v) { - Utils.startAsyncTask(new UndoVaccineTask(tag, v), null); + UndoVaccineTaskRunnable runnable = new UndoVaccineTaskRunnable( tag, v ); + AppExecutors executors = new AppExecutors(); + executors.diskIO().execute(runnable); } public void addVaccinationDialogFragment(ArrayList vaccineWrappers, VaccineGroup vaccineGroup) { @@ -454,10 +465,10 @@ private void saveVaccine(ArrayList tags, final View view) { VaccineRepository vaccineRepository = ImmunizationLibrary.getInstance().vaccineRepository(); VaccineWrapper[] arrayTags = tags.toArray(new VaccineWrapper[tags.size()]); - SaveVaccinesTask backgroundTask = new SaveVaccinesTask(); - backgroundTask.setVaccineRepository(vaccineRepository); - backgroundTask.setView(view); - Utils.startAsyncTask(backgroundTask, arrayTags); + + SaveVaccineTaskCallable callable = new SaveVaccineTaskCallable(arrayTags, vaccineRepository); + SaveVaccineTaskCallbackInteractorCallback callback = new SaveVaccineTaskCallbackInteractorCallback(view); + genericInteractor.execute(callable, callback); } @@ -628,7 +639,9 @@ public void onGiveEarlier(ServiceWrapper tag, View v) { @Override public void onUndoService(ServiceWrapper tag, View v) { - Utils.startAsyncTask(new UndoServiceTask(tag), null); + UndoServiceTaskCallable callable = new UndoServiceTaskCallable(tag); + UndoServiceTaskCallableInteractorCallback callback = new UndoServiceTaskCallableInteractorCallback(tag); + genericInteractor.execute(callable, callback); } public void saveService(ServiceWrapper tag, final View view) { @@ -637,43 +650,58 @@ public void saveService(ServiceWrapper tag, final View view) { } ServiceWrapper[] arrayTags = {tag}; - SaveServiceTask backgroundTask = new SaveServiceTask(); String providerId = ImmunizationLibrary.getInstance().context().allSharedPreferences().fetchRegisteredANM(); - backgroundTask.setProviderId(providerId); - backgroundTask.setView(view); - Utils.startAsyncTask(backgroundTask, arrayTags); - } + SaveServiceTaskCallable callable = new SaveServiceTaskCallable(arrayTags, providerId); + SaveServiceTaskCallableInteractorCallback callback = new SaveServiceTaskCallableInteractorCallback(view); - private class SaveVaccinesTask extends AsyncTask, List>> { + genericInteractor.execute(callable, callback); + } + public class SaveVaccineTaskCallbackInteractorCallback implements CallableInteractorCallBack, List>, List, List>>{ private View view; - private VaccineRepository vaccineRepository; - private AlertService alertService; - private List affectedVaccines; - private List vaccineList; - private List alertList; - public void setView(View view) { + SaveVaccineTaskCallbackInteractorCallback(View view){ this.view = view; } - public void setVaccineRepository(VaccineRepository vaccineRepository) { - this.vaccineRepository = vaccineRepository; - alertService = ImmunizationLibrary.getInstance().context().alertService(); - affectedVaccines = new ArrayList<>(); - } @Override - protected void onPostExecute(Pair, List> pair) { - updateVaccineGroupViews(view, pair.first, pair.second); + public void onResult(Triple, List>, List, List> triple) { + Pair, List> pair = triple.getLeft(); + List affectedVaccines = triple.getMiddle(); + List vaccineList = pair.second; + ArrayList vaccineWrappers = pair.first; + List alertList = triple.getRight(); + + updateVaccineGroupViews(view, vaccineWrappers, vaccineList); updateVaccineGroupsUsingAlerts(affectedVaccines, vaccineList, alertList); } @Override - protected Pair, List> doInBackground(VaccineWrapper... vaccineWrappers) { + public void onError(Exception ex) { + Timber.e(ex); + } + } + + public class SaveVaccineTaskCallable implements Callable, List>, List, List>> { + + private VaccineRepository vaccineRepository; + private AlertService alertService; + private List affectedVaccines; + private List vaccineList; + private List alertList; + private VaccineWrapper[] vaccineWrappers; + + SaveVaccineTaskCallable(VaccineWrapper[] vaccineWrappers, VaccineRepository vaccineRepository){ + this.vaccineWrappers = vaccineWrappers; + this.vaccineRepository = vaccineRepository; + alertService = ImmunizationLibrary.getInstance().context().alertService(); + } + @Override + public Triple, List>, List, List> call() { ArrayList list = new ArrayList<>(); if (vaccineRepository != null) { for (VaccineWrapper tag : vaccineWrappers) { @@ -682,7 +710,6 @@ protected Pair, List> doInBackground(VaccineW } } - Pair, List> pair = new Pair<>(list, vaccineList); String dobString = Utils.getValue(childDetails.getColumnmaps(), "dob", false); if (!TextUtils.isEmpty(dobString)) { DateTime dateTime = new DateTime(dobString); @@ -692,11 +719,13 @@ protected Pair, List> doInBackground(VaccineW alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), VaccinateActionUtils.allAlertNames(IMConstants.VACCINE_TYPE.CHILD)); - return pair; + Pair, List> pair = new Pair<>(list, vaccineList); + + return Triple.of(pair, affectedVaccines, alertList); } } - private class UpdateViewTask extends AsyncTask>> { + private class UpdateViewTaskCallable implements Callable>>{ private VaccineRepository vaccineRepository; private RecurringServiceTypeRepository recurringServiceTypeRepository; @@ -718,57 +747,8 @@ public void setRecurringServiceRecordRepository(RecurringServiceRecordRepository public void setAlertService(AlertService alertService) { this.alertService = alertService; } - - - @SuppressWarnings("unchecked") - @Override - protected void onPostExecute(Map> map) { - - List vaccineList = new ArrayList<>(); - - Map> serviceTypeMap = new LinkedHashMap<>(); - List serviceRecords = new ArrayList<>(); - - List alertList = new ArrayList<>(); - - if (map.containsKey(Vaccine.class.getName())) { - NamedObject namedObject = map.get(Vaccine.class.getName()); - if (namedObject != null) { - vaccineList = (List) namedObject.object; - } - - } - - if (map.containsKey(ServiceType.class.getName())) { - NamedObject namedObject = map.get(ServiceType.class.getName()); - if (namedObject != null) { - serviceTypeMap = (Map>) namedObject.object; - } - - } - - if (map.containsKey(ServiceRecord.class.getName())) { - NamedObject namedObject = map.get(ServiceRecord.class.getName()); - if (namedObject != null) { - serviceRecords = (List) namedObject.object; - } - - } - - if (map.containsKey(Alert.class.getName())) { - NamedObject namedObject = map.get(Alert.class.getName()); - if (namedObject != null) { - alertList = (List) namedObject.object; - } - - } - - updateServiceViews(serviceTypeMap, serviceRecords, alertList); - updateVaccinationViews(vaccineList, alertList); - } - @Override - protected Map> doInBackground(Void... voids) { + public Map> call() { String dobString = Utils.getValue(childDetails.getColumnmaps(), IMDatabaseConstants.Client.DOB, false); if (!TextUtils.isEmpty(dobString)) { DateTime dateTime = new DateTime(dobString); @@ -826,8 +806,60 @@ protected Map> doInBackground(Void... voids) { } } - private class UndoVaccineTask extends AsyncTask { + private class UpdateViewTaskCallableInteractorCallback implements CallableInteractorCallBack>>{ + + @Override + public void onResult(Map> map) { + List vaccineList = new ArrayList<>(); + + Map> serviceTypeMap = new LinkedHashMap<>(); + List serviceRecords = new ArrayList<>(); + + List alertList = new ArrayList<>(); + + if (map.containsKey(Vaccine.class.getName())) { + NamedObject namedObject = map.get(Vaccine.class.getName()); + if (namedObject != null) { + vaccineList = (List) namedObject.object; + } + + } + if (map.containsKey(ServiceType.class.getName())) { + NamedObject namedObject = map.get(ServiceType.class.getName()); + if (namedObject != null) { + serviceTypeMap = (Map>) namedObject.object; + } + + } + + if (map.containsKey(ServiceRecord.class.getName())) { + NamedObject namedObject = map.get(ServiceRecord.class.getName()); + if (namedObject != null) { + serviceRecords = (List) namedObject.object; + } + + } + + if (map.containsKey(Alert.class.getName())) { + NamedObject namedObject = map.get(Alert.class.getName()); + if (namedObject != null) { + alertList = (List) namedObject.object; + } + + } + + updateServiceViews(serviceTypeMap, serviceRecords, alertList); + updateVaccinationViews(vaccineList, alertList); + } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } + } + + private class UndoVaccineTaskRunnable implements Runnable { private final VaccineRepository vaccineRepository; private final AlertService alertService; private VaccineWrapper tag; @@ -836,20 +868,16 @@ private class UndoVaccineTask extends AsyncTask { private List alertList; private List affectedVaccines; - public UndoVaccineTask(VaccineWrapper tag, View v) { + public UndoVaccineTaskRunnable(VaccineWrapper tag, View v){ this.tag = tag; this.v = v; vaccineRepository = ImmunizationLibrary.getInstance().vaccineRepository(); alertService = ImmunizationLibrary.getInstance().context().alertService(); - } - @Override - protected void onPreExecute() { - super.onPreExecute(); } @Override - protected Void doInBackground(Void... params) { + public void run() { if (tag != null) { if (tag.getDbKey() != null) { @@ -865,23 +893,6 @@ protected Void doInBackground(Void... params) { } } } - return null; - } - - @Override - protected void onPostExecute(Void params) { - super.onPostExecute(params); - - // Refresh the vaccine group with the updated vaccine - tag.setUpdatedVaccineDate(null, false); - tag.setDbKey(null); - - View view = getLastOpenedView(); - - ArrayList wrappers = new ArrayList<>(); - wrappers.add(tag); - updateVaccineGroupViews(view, wrappers, vaccineList, true); - updateVaccineGroupsUsingAlerts(affectedVaccines, vaccineList, alertList); } } @@ -895,30 +906,22 @@ public NamedObject(String name, T object) { } } - public class SaveServiceTask extends AsyncTask, List, List>> { + public class SaveServiceTaskCallable implements Callable, List, List>>{ - private View view; private String providerId; + private ServiceWrapper[] arrayTags; - public void setView(View view) { - this.view = view; - } - - public void setProviderId(String providerId) { + SaveServiceTaskCallable(ServiceWrapper[] arrayTags, String providerId){ + this.arrayTags = arrayTags; this.providerId = providerId; } @Override - protected void onPostExecute(Triple, List, List> triple) { - RecurringServiceUtils.updateServiceGroupViews(view, triple.getLeft(), triple.getMiddle(), triple.getRight()); - } - - @Override - protected Triple, List, List> doInBackground(ServiceWrapper... params) { + public Triple, List, List> call() { ArrayList list = new ArrayList<>(); - for (ServiceWrapper tag : params) { + for (ServiceWrapper tag : arrayTags) { RecurringServiceUtils.saveService(tag, childDetails.entityId(), providerId, null, null, null, null); list.add(tag); @@ -936,30 +939,66 @@ protected Triple, List, List> do List alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), alertArray); return Triple.of(list, serviceRecordList, alertList); - } } - private class UndoServiceTask extends AsyncTask { + public class SaveServiceTaskCallableInteractorCallback implements CallableInteractorCallBack, List, List>>{ private View view; + + SaveServiceTaskCallableInteractorCallback(View view){ + this.view = view; + } + + @Override + public void onResult(Triple, List, List> triple) { + RecurringServiceUtils.updateServiceGroupViews(view, triple.getLeft(), triple.getMiddle(), triple.getRight()); + } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } + } + + public class UndoServiceTaskCallableInteractorCallback implements CallableInteractorCallBack, List, List>>{ + private ServiceWrapper tag; - private List serviceRecordList; - private ArrayList wrappers; - private List alertList; + private View view; - public UndoServiceTask(ServiceWrapper tag) { + + public UndoServiceTaskCallableInteractorCallback(ServiceWrapper tag) { this.tag = tag; this.view = RecurringServiceUtils.getLastOpenedServiceView(serviceGroups); } @Override - protected void onPreExecute() { - super.onPreExecute(); + public void onResult(Triple, List, List> triple) { + tag.setUpdatedVaccineDate(null, false); + tag.setDbKey(null); + + RecurringServiceUtils.updateServiceGroupViews(view, triple.getLeft(), triple.getMiddle(), triple.getRight(), true); + + } + + @Override + public void onError(Exception ex) { + Timber.e(ex); + } + } + public class UndoServiceTaskCallable implements Callable, List, List>>{ + + private ServiceWrapper tag; + + UndoServiceTaskCallable(ServiceWrapper tag){ + this.tag = tag; } @Override - protected Void doInBackground(Void... params) { + public Triple, List, List> call() { + ArrayList wrappers = new ArrayList<>(); + List serviceRecordList = new ArrayList<>(); + List alertList = new ArrayList<>(); if (tag != null) { if (tag.getDbKey() != null) { @@ -982,20 +1021,7 @@ protected Void doInBackground(Void... params) { alertList = alertService.findByEntityIdAndAlertNames(childDetails.entityId(), alertArray); } } - return null; - } - - @Override - protected void onPostExecute(Void params) { - super.onPostExecute(params); - - tag.setUpdatedVaccineDate(null, false); - tag.setDbKey(null); - - RecurringServiceUtils.updateServiceGroupViews(view, wrappers, serviceRecordList, alertList, true); - + return Triple.of(wrappers, serviceRecordList, alertList); } } - - } From 9bc424772e314e60fdef9299b32958f40b0d45e1 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Thu, 23 Feb 2023 11:51:14 +0300 Subject: [PATCH 15/19] reuse background processing classes from opensrp-core --- .../adapter/ImmunizationRowAdapter.java | 5 ++--- .../adapter/ImmunizationRowAdapterTest.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 9312f068..8ad3f729 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -1,7 +1,6 @@ package org.smartregister.immunization.adapter; import android.content.Context; -import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; @@ -16,12 +15,12 @@ import org.smartregister.immunization.domain.Vaccine; import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import java.util.ArrayList; import java.util.Calendar; diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 7c644c28..ac25a043 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -30,11 +30,11 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.domain.jsonmapping.VaccineGroup; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.util.AppExecutors; -import org.smartregister.immunization.util.GenericInteractor; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; +import org.smartregister.util.AppExecutors; +import org.smartregister.util.GenericInteractor; import org.smartregister.util.JsonFormUtils; import java.lang.reflect.Type; @@ -64,6 +64,8 @@ public class ImmunizationRowAdapterTest extends BaseUnitTest implements Executo private VaccineWrapper wrapper; private ArrayList wrappers; private ImmunizationRowGroup view; + private GenericInteractor interactor; + @Mock private CommonPersonObjectClient commonPersonObjectClient; @@ -72,6 +74,10 @@ public void setUp() { org.mockito.MockitoAnnotations.initMocks(this); view = new ImmunizationRowGroup(ApplicationProvider.getApplicationContext(), false); setDataForTest(magicDate); + interactor = new GenericInteractor(); + ReflectionHelpers.setField(interactor, "appExecutors", + new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); } public void setDataForTest(String dateTimeString) { @@ -200,8 +206,6 @@ public void testUpdateVaccineDate() { public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); - GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); - interactor = Mockito.spy(interactor); ImmunizationRowCard mockImmunizationRowCard = Mockito.mock(ImmunizationRowCard.class); @@ -229,8 +233,6 @@ public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ public void testGetViewsCallsImmunizationCallbackInteractorOnError(){ ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback immunizationRowCallableInteractorCallback = Mockito.mock(ImmunizationRowAdapter.ImmunizationRowCallableInteractorCallback.class); - GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); - interactor = Mockito.spy(interactor); Exception exception = new IllegalStateException("Some Exception"); Callable callable = () -> { From a358ba568ef11befdb072e16ca28dfe8d805b57c Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 24 Feb 2023 14:39:55 +0300 Subject: [PATCH 16/19] refactor other classes to reuse client-core code --- .../adapter/ServiceCardAdapter.java | 4 +- .../adapter/ServiceRowAdapter.java | 4 +- .../adapter/VaccineCardAdapter.java | 4 +- .../immunization/util/AppExecutors.java | 105 ------------------ .../immunization/util/CallableInteractor.java | 26 ----- .../util/CallableInteractorCallBack.java | 9 -- .../immunization/util/GenericInteractor.java | 37 ------ .../adapter/ImmunizationRowAdapterTest.java | 3 - .../adapter/ServiceCardAdapterTest.java | 14 ++- .../adapter/ServiceRowAdapterTest.java | 15 ++- .../immunization/sample/DetailActivity.java | 9 +- .../immunization/sample/MainActivity.java | 6 +- 12 files changed, 34 insertions(+), 202 deletions(-) delete mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java delete mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java delete mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java delete mode 100644 opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java index 915edfb3..ca32b77a 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceCardAdapter.java @@ -20,8 +20,8 @@ import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceCard; diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index 5947d6cd..33c7f3d3 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -18,8 +18,8 @@ import org.smartregister.immunization.domain.ServiceType; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.ServiceRowCard; diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java index fd4d43f2..c1df66be 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java @@ -21,8 +21,8 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.listener.VaccineCardAdapterLoadingListener; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.util.ImageUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.VaccineCard; diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java deleted file mode 100644 index 5d334782..00000000 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/AppExecutors.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.smartregister.immunization.util; - - -/** - * Created by keyman on 12/11/18. - */ - -import android.os.Handler; -import android.os.Looper; -import androidx.annotation.NonNull; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -/** - * Global executor pools for the whole application. - *

- * Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind - * webservice requests). - */ -public class AppExecutors { - - private static final int THREAD_COUNT = 3; - - private final Executor diskIO; - - private final Executor networkIO; - - private final Executor mainThread; - - public AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) { - this.diskIO = diskIO; - this.networkIO = networkIO; - this.mainThread = mainThread; - } - - public AppExecutors() { - this(new DiskIOThreadExecutor(), Executors.newFixedThreadPool(THREAD_COUNT), - new MainThreadExecutor()); - } - - public Executor diskIO() { - return diskIO; - } - - public Executor networkIO() { - return networkIO; - } - - public Executor mainThread() { - return mainThread; - } - - /** - * Auto assign the executor by request type - * - * @param runnable - * @param request - */ - public void execute(@NonNull Runnable runnable, @NonNull Request request) { - switch (request) { - case DISK_THREAD: - diskIO().execute(runnable); - break; - case NETWORK_THREAD: - networkIO().execute(runnable); - break; - case MAIN_THREAD: - mainThread().execute(runnable); - break; - default: - throw new IllegalArgumentException("Unknown request"); - } - } - - private static class MainThreadExecutor implements Executor { - private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); - - @Override - public void execute(@NonNull Runnable command) { - mainThreadHandler.post(command); - } - } - - /** - * Executor that runs a task on a new background thread. - */ - private static class DiskIOThreadExecutor implements Executor { - - private final Executor mDiskIO; - - public DiskIOThreadExecutor() { - mDiskIO = Executors.newSingleThreadExecutor(); - } - - @Override - public void execute(@NonNull Runnable command) { - mDiskIO.execute(command); - } - } - - public enum Request { - MAIN_THREAD, NETWORK_THREAD, DISK_THREAD - } -} \ No newline at end of file diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java deleted file mode 100644 index f19ee681..00000000 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractor.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.smartregister.immunization.util; - - -import java.util.concurrent.Callable; - -public interface CallableInteractor { - - /** - * This will execute any asyc code using the default request type as AppExecutors.Request.DISK_THREAD - * - * @param callable - * @param callBack - * @param - */ - void execute(Callable callable, CallableInteractorCallBack callBack); - - /** - * This will execute any asyc code using and get returned results - * - * @param callable - * @param callBack - * @param - */ - void execute(Callable callable, CallableInteractorCallBack callBack, AppExecutors.Request request); - -} diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java deleted file mode 100644 index 7860c207..00000000 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/CallableInteractorCallBack.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.smartregister.immunization.util; - -public interface CallableInteractorCallBack { - - void onResult(T t); - - void onError(Exception ex); - -} \ No newline at end of file diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java deleted file mode 100644 index 61ec6862..00000000 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/GenericInteractor.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.smartregister.immunization.util; - -import java.util.concurrent.Callable; - -import timber.log.Timber; - -public class GenericInteractor implements CallableInteractor { - - protected AppExecutors appExecutors; - - public GenericInteractor() { - appExecutors = new AppExecutors(); - } - - public GenericInteractor(AppExecutors appExecutors) { - this.appExecutors = appExecutors; - } - - @Override - public void execute(Callable callable, CallableInteractorCallBack callBack) { - execute(callable, callBack, AppExecutors.Request.DISK_THREAD); - } - - @Override - public void execute(Callable callable, CallableInteractorCallBack callBack, AppExecutors.Request request) { - Runnable runnable = () -> { - try { - T result = callable.call(); - appExecutors.mainThread().execute(() -> callBack.onResult(result)); - } catch (Exception e) { - Timber.e(e); - appExecutors.mainThread().execute(() -> callBack.onError(e)); - } - }; - appExecutors.execute(runnable, request); - } -} diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index ac25a043..ff9f999c 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -224,9 +224,6 @@ public void testGetViewCallsImmunizationRowCallableInteractorCallbackOnResult(){ Mockito.verify(interactor).execute(Mockito.any(), Mockito.any()); Mockito.verify(immunizationRowCallableInteractorCallback).onResult(Mockito.any()); -// Mockito.doAnswer(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)). -// when(interactor.execute(vaccineWrapperCallable, immunizationRowCallableInteractorCallback)); - } @Test diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java index cf017098..49129ca2 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java @@ -13,6 +13,7 @@ import org.powermock.reflect.Whitebox; import androidx.test.core.app.ApplicationProvider; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Alert; import org.smartregister.domain.AlertStatus; @@ -24,8 +25,8 @@ import org.smartregister.immunization.domain.ServiceTypeTest; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.domain.ServiceWrapperTest; -import org.smartregister.immunization.util.AppExecutors; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.AppExecutors; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.view.ServiceCard; import org.smartregister.immunization.view.ServiceGroup; @@ -63,6 +64,8 @@ public class ServiceCardAdapterTest extends BaseUnitTest implements Executor { private Map> alertList = new HashMap<>(); private HashMap> serviceTypeMap; + private GenericInteractor interactor; + public static List getServiceTypeKeys(HashMap> vaccineData) { List keys = new ArrayList<>(); if (vaccineData == null || vaccineData.isEmpty()) { @@ -81,6 +84,9 @@ public void setUp() { serviceCardAdapter = new ServiceCardAdapter(ApplicationProvider.getApplicationContext(), view, serviceTypeList, serviceRecordList, alertList); org.mockito.MockitoAnnotations.initMocks(this); + interactor = new GenericInteractor(); + ReflectionHelpers.setField(interactor, "appExecutors", + new AppExecutors(this, this, this)); } public void setDataForTest(String dateTimeString) { @@ -202,8 +208,6 @@ public void testUpdateChildsActiveStatus() { public void testGetViewCallsServiceCardTaskCallableInteractorCallableOnResult(){ ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable serviceCardTaskCallableInteractorCallable = Mockito.mock(ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable.class); - GenericInteractor interactor= new GenericInteractor(new AppExecutors(this, this , this)); - interactor = Mockito.spy(interactor); ServiceCardAdapter mockAdapter = Mockito.spy(serviceCardAdapter); Mockito.when(mockAdapter.getGenericInteractor()).thenReturn(interactor); @@ -218,7 +222,7 @@ public void testGetViewCallsServiceCardTaskCallableInteractorCallableOnResult(){ public void testGetViewCallsServiceRowTaskCallableInteractorCallbackonError(){ ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable serviceCardTaskCallableInteractorCallable = Mockito.mock(ServiceCardAdapter.ServiceCardTaskCallableInteractorCallable.class); - GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + Exception exception = new IllegalStateException("some exception"); Callable callable = () -> { throw exception; diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java index c0867687..e52d92e4 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceRowAdapterTest.java @@ -13,6 +13,7 @@ import org.mockito.Mockito; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Alert; import org.smartregister.domain.AlertStatus; @@ -24,8 +25,8 @@ import org.smartregister.immunization.domain.ServiceTypeTest; import org.smartregister.immunization.domain.ServiceWrapper; import org.smartregister.immunization.domain.ServiceWrapperTest; -import org.smartregister.immunization.util.AppExecutors; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.AppExecutors; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.view.ServiceRowGroup; import java.util.ArrayList; @@ -60,6 +61,8 @@ public class ServiceRowAdapterTest extends BaseUnitTest implements Executor { private List serviceRecordList = new ArrayList<>(); private List alertList = new ArrayList<>(); + private GenericInteractor interactor; + @Before public void setUp() throws Exception { view = new ServiceRowGroup(ApplicationProvider.getApplicationContext(), true); @@ -67,6 +70,11 @@ public void setUp() throws Exception { serviceRowAdapter = new ServiceRowAdapter(ApplicationProvider.getApplicationContext(), view, true, serviceTypeList, serviceRecordList, alertList); org.mockito.MockitoAnnotations.initMocks(this); + interactor = new GenericInteractor(); + ReflectionHelpers.setField(interactor, "appExecutors", + new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); + } public void setDataForTest(String dateTimeString) { @@ -152,7 +160,7 @@ public void assertGetViewReturnsServiceRowView() { public void testGetViewCallsServiceRowTaskCallableInteractorCallBackOnResult(){ ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack serviceRowTaskCallableInteractorCallBack = Mockito.mock(ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack.class); - GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); + interactor = Mockito.spy(interactor); @@ -173,7 +181,6 @@ public void testGetViewCallsServiceRowTaskCallableInteractorCallBackOnResult(){ public void testGetViewCallsServiceRowTaskCallableInteractorCallbackonError(){ ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack serviceRowTaskCallableInteractorCallBack = Mockito.mock(ServiceRowAdapter.ServiceRowTaskCallableInteractorCallBack.class); - GenericInteractor interactor = new GenericInteractor(new AppExecutors(this, this, this)); Exception exception = new IllegalStateException("some exception"); Callable callable = () -> { throw exception; diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index 8dd97184..c1b5cdde 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -43,10 +43,9 @@ import org.smartregister.immunization.repository.RecurringServiceTypeRepository; import org.smartregister.immunization.repository.VaccineRepository; import org.smartregister.immunization.sample.tabfragments.ImmunizationFragment; -import org.smartregister.immunization.util.AppExecutors; -import org.smartregister.immunization.util.CallableInteractor; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.AppExecutors; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.util.IMConstants; import org.smartregister.immunization.util.RecurringServiceUtils; import org.smartregister.immunization.util.VaccinateActionUtils; @@ -68,6 +67,8 @@ import java.util.Map; import java.util.concurrent.Callable; +import timber.log.Timber; + /** * Created by raihan on 1/03/2017. */ diff --git a/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java index 2e0f1adc..b0b1e381 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/MainActivity.java @@ -48,9 +48,9 @@ import org.smartregister.immunization.sample.util.SampleUtil; import org.smartregister.immunization.service.intent.RecurringIntentService; import org.smartregister.immunization.service.intent.VaccineIntentService; -import org.smartregister.immunization.util.AppExecutors; -import org.smartregister.immunization.util.CallableInteractorCallBack; -import org.smartregister.immunization.util.GenericInteractor; +import org.smartregister.util.AppExecutors; +import org.smartregister.util.CallableInteractorCallBack; +import org.smartregister.util.GenericInteractor; import org.smartregister.immunization.util.IMConstants; import org.smartregister.immunization.util.IMDatabaseConstants; import org.smartregister.immunization.util.RecurringServiceUtils; From 2525ae1818d7893e1004eb27ce17d49f713bad37 Mon Sep 17 00:00:00 2001 From: Hilary Baraka Egesa Date: Mon, 27 Feb 2023 12:30:18 +0300 Subject: [PATCH 17/19] fix codacy issues --- .../smartregister/immunization/adapter/VaccineCardAdapter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java index c1df66be..6ecda651 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java @@ -5,7 +5,6 @@ import static org.smartregister.util.Utils.getValue; import android.content.Context; -import android.os.AsyncTask; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; @@ -27,7 +26,6 @@ import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.immunization.view.VaccineCard; import org.smartregister.immunization.view.VaccineGroup; -import org.smartregister.util.Utils; import java.util.ArrayList; import java.util.Calendar; From e31496ca4b54f1338e4385a0338fd82b87460ba0 Mon Sep 17 00:00:00 2001 From: Hilary Baraka Egesa Date: Mon, 27 Feb 2023 12:34:40 +0300 Subject: [PATCH 18/19] fix codacy issue --- .../immunization/adapter/ServiceCardAdapterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java index 49129ca2..d72db11a 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ServiceCardAdapterTest.java @@ -117,7 +117,7 @@ public void setDataForTest(String dateTimeString) { List alertlist = new ArrayList(); alertlist.add(alert); - serviceTypeMap = new HashMap<>(); + HashMap> serviceTypeMap = new HashMap<>(); ServiceType serviceType = new ServiceType(); serviceType.setId(0l); serviceType.setType(ServiceTypeTest.TYPE); From ca83f75e4ecc459f8e03e4a4f81d3b85b61ad802 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 3 Mar 2023 14:32:30 +0300 Subject: [PATCH 19/19] update artifact version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 865d31e1..91ec69d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=5.0.0-SNAPSHOT +VERSION_NAME=5.1.0-SNAPSHOT VERSION_CODE=3 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization