Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check attrbute #21

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ internal interface ProgramRepository {
fun clearCache()
fun getDataStoreData(): Flow<List<DataStoreEntry>>
fun getFilteredDataStore(): Flow<DataStoreAppConfig?>
suspend fun downloadMediaToLocal(uid: String)
suspend fun downloadMediaToLocal(uid: String): Byte
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

}
}
27 changes: 26 additions & 1 deletion form/src/main/java/org/dhis2/form/ui/FormViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -748,7 +749,31 @@ class FormViewModel(
resp = null
}
}
Timber.tag("FORM_VIEW").d("${resp}")
return resp
}
fun checkAttribute(uid: String): List<Attribute>? {
val store = mediaDataStore.value

var resp: List<Attribute>? = 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
}

Expand Down