diff --git a/app/src/org/commcare/tasks/EntityLoaderHelper.kt b/app/src/org/commcare/tasks/EntityLoaderHelper.kt index 65670553a..70b6c6aaa 100644 --- a/app/src/org/commcare/tasks/EntityLoaderHelper.kt +++ b/app/src/org/commcare/tasks/EntityLoaderHelper.kt @@ -15,6 +15,9 @@ import org.commcare.suite.model.EntityDatum import org.javarosa.core.model.condition.EvaluationContext import org.javarosa.core.model.instance.TreeReference +/** + * Helper class to load entities for an entity screen + */ class EntityLoaderHelper( detail: Detail, sessionDatum: EntityDatum?, diff --git a/app/src/org/commcare/tasks/EntityLoaderListener.java b/app/src/org/commcare/tasks/EntityLoaderListener.java index 4425957aa..eeccfe0d6 100644 --- a/app/src/org/commcare/tasks/EntityLoaderListener.java +++ b/app/src/org/commcare/tasks/EntityLoaderListener.java @@ -10,7 +10,7 @@ public interface EntityLoaderListener { void attachLoader(EntityLoaderTask task); void deliverLoadResult(List> entities, List references, - NodeEntityFactory factory, int focusTargetIndex); + NodeEntityFactory factory, int focusTargetIndex); void deliverLoadError(Exception e); diff --git a/app/src/org/commcare/tasks/EntityLoaderTask.java b/app/src/org/commcare/tasks/EntityLoaderTask.java index 3cecf32b3..68b6cc045 100644 --- a/app/src/org/commcare/tasks/EntityLoaderTask.java +++ b/app/src/org/commcare/tasks/EntityLoaderTask.java @@ -22,7 +22,8 @@ * @author ctsims */ public class EntityLoaderTask - extends ManagedAsyncTask>, List>> implements + extends + ManagedAsyncTask>, List>> implements EntityLoadingProgressListener { private final static Object lock = new Object(); @@ -34,12 +35,13 @@ public class EntityLoaderTask /** * Creates a new instance - * @param detail detail we want to load + * + * @param detail detail we want to load * @param entityDatum entity datum corresponding to the entity list, null for entity detail screens - * @param evalCtx evaluation context + * @param evalCtx evaluation context */ public EntityLoaderTask(Detail detail, @Nullable EntityDatum entityDatum, EvaluationContext evalCtx) { - entityLoaderHelper = new EntityLoaderHelper(detail, entityDatum , evalCtx); + entityLoaderHelper = new EntityLoaderHelper(detail, entityDatum, evalCtx); } @Override diff --git a/app/src/org/commcare/tasks/PrimeEntityCache.kt b/app/src/org/commcare/tasks/PrimeEntityCache.kt index 37a0cad8d..f19ec50fd 100644 --- a/app/src/org/commcare/tasks/PrimeEntityCache.kt +++ b/app/src/org/commcare/tasks/PrimeEntityCache.kt @@ -5,8 +5,10 @@ import androidx.work.Worker import androidx.work.WorkerParameters import org.javarosa.core.services.Logger -class PrimeEntityCache(appContext: Context, workerParams: WorkerParameters) - : Worker(appContext, workerParams) { +/** + * Android Worker to prime cache for entity screens + */ +class PrimeEntityCache(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) { override fun doWork(): Result { try { diff --git a/app/src/org/commcare/tasks/PrimeEntityCacheHelper.kt b/app/src/org/commcare/tasks/PrimeEntityCacheHelper.kt index 5caab2e60..95fcd2725 100644 --- a/app/src/org/commcare/tasks/PrimeEntityCacheHelper.kt +++ b/app/src/org/commcare/tasks/PrimeEntityCacheHelper.kt @@ -27,8 +27,10 @@ import org.javarosa.xpath.XPathException class PrimeEntityCacheHelper private constructor() : Cancellable { private var entityLoaderHelper: EntityLoaderHelper? = null + @Volatile private var inProgress = false + @Volatile private var currentDatumInProgress: String? = null private var listener: EntityLoadingProgressListener? = null @@ -171,6 +173,7 @@ class PrimeEntityCacheHelper private constructor() : Cancellable { entityLoaderHelper!!.cacheEntities(entities) entities } + else -> entityLoaderHelper!!.cacheEntities(entityDatum.nodeset).first } _cachedEntitiesState.value = cachedEntities