diff --git a/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt b/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt index 7d872c6e5e..78ae51ecbf 100644 --- a/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/main/program/ProgramFragment.kt @@ -102,6 +102,7 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView { setContent { val items by presenter.programs().observeAsState(emptyList()) val state by presenter.downloadState().observeAsState() + ProgramList( downLoadState = state, programs = items, diff --git a/app/src/main/java/org/dhis2/usescases/main/program/ProgramPresenter.kt b/app/src/main/java/org/dhis2/usescases/main/program/ProgramPresenter.kt index bd11703a83..c91caf2686 100644 --- a/app/src/main/java/org/dhis2/usescases/main/program/ProgramPresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/main/program/ProgramPresenter.kt @@ -151,6 +151,16 @@ class ProgramPresenter internal constructor( ) ) getStore() + getFiles() + } + fun getFiles() { + runBlocking(Dispatchers.IO) { + launch { +// val response = programRepository.downloadMediaToLocal("djduey498493") + val response = programRepository.downloadMediaToLocal("xCUZ3aNTSfm") + Timber.tag("DOWNLOAD").d("${response}") + } + } } fun onSyncStatusClick(program: ProgramViewModel) { diff --git a/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepository.kt b/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepository.kt index 6e165060a7..d2c9f7a0ed 100644 --- a/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepository.kt @@ -13,5 +13,5 @@ internal interface ProgramRepository { fun clearCache() fun getDataStoreData(): Flow> fun getFilteredDataStore(): Flow - suspend fun downloadMediaToLocal(uid: String) + suspend fun downloadMediaToLocal(uid: String): Byte } diff --git a/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepositoryImpl.kt b/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepositoryImpl.kt index ae4e3980a4..a9f1291e9d 100644 --- a/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepositoryImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/main/program/ProgramRepositoryImpl.kt @@ -68,7 +68,7 @@ internal class ProgramRepositoryImpl( ) } - override suspend fun downloadMediaToLocal(uid: String): Unit = withContext(Dispatchers.IO) { + override suspend fun downloadMediaToLocal(uid: String): Byte = withContext(Dispatchers.IO) { val service: UBService = d2.retrofit().create(UBService::class.java) val response = service.downloadFileResource(uid) diff --git a/app/src/main/java/org/dhis2/usescases/uiboost/network/UBService.kt b/app/src/main/java/org/dhis2/usescases/uiboost/network/UBService.kt index d8c270a118..d0beeb8b83 100644 --- a/app/src/main/java/org/dhis2/usescases/uiboost/network/UBService.kt +++ b/app/src/main/java/org/dhis2/usescases/uiboost/network/UBService.kt @@ -3,11 +3,12 @@ package org.dhis2.usescases.uiboost.network import org.dhis2.usescases.uiboost.data.model.MessageResponse import retrofit2.http.GET import retrofit2.http.Path +import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType interface UBService { @GET("documents/{uid}/data") suspend fun downloadFileResource( @Path("uid") uid: String - ): MessageResponse + ): Byte } \ No newline at end of file diff --git a/app/src/main/java/org/dhis2/usescases/uiboost/viewmodels/HomeProgramViewModel.kt b/app/src/main/java/org/dhis2/usescases/uiboost/viewmodels/HomeProgramViewModel.kt index da58353138..edc637c551 100644 --- a/app/src/main/java/org/dhis2/usescases/uiboost/viewmodels/HomeProgramViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/uiboost/viewmodels/HomeProgramViewModel.kt @@ -112,14 +112,10 @@ class HomeProgramViewModel @Inject internal constructor( fun getMediaDataStore() { runBlocking(Dispatchers.IO) { launch { -// uBoostRepository.getDataStore().collectLatest { -// _dataStoreDataElement.value = (it) -// } uBoostRepository.getFilteredMediaDataStore().collectLatest { _mediaDataStoreFiltered.value = it } } } - } } diff --git a/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt b/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt index 6081b330f6..8dea556e89 100644 --- a/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt +++ b/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt @@ -35,6 +35,7 @@ import org.dhis2.form.ui.event.RecyclerViewUiEvents import org.dhis2.form.ui.idling.FormCountingIdlingResource import org.dhis2.form.ui.intent.FormIntent import org.dhis2.form.ui.validation.validators.FieldMaskValidator +import org.dhis2.usescases.uiboost.data.model.media.Attribute import org.dhis2.usescases.uiboost.data.model.media.DataElement import org.dhis2.usescases.uiboost.data.model.media.MediaStoreConfig import org.hisp.dhis.android.core.arch.helpers.Result @@ -748,7 +749,31 @@ class FormViewModel( resp = null } } - Timber.tag("FORM_VIEW").d("${resp}") + return resp + } + fun checkAttribute(uid: String): List? { + val store = mediaDataStore.value + + var resp: List? = null + store?.let { + + val res = it.map { + it.attributes + } + val response = res.map { + it?.let { + it.filter { + it.attribute == uid + } + } + } + + if (response.get(0)?.isNotEmpty() == true) { + resp = response.get(0) + } else { + resp = null + } + } return resp }