Skip to content

Commit

Permalink
feat: [ANDROAPP-5523] change error access message at home
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Jan 25, 2024
1 parent 34db180 commit d8be1ea
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView {
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed,
)
setContent {
val items by presenter.programs().observeAsState(emptyList())
val items by presenter.programs.observeAsState()
val state by presenter.downloadState().observeAsState()
ProgramList(
downLoadState = state,
Expand Down Expand Up @@ -124,10 +124,6 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView {

//endregion

override fun swapProgramModelData(programs: List<ProgramViewModel>) {
binding.emptyView.visibility = if (programs.isEmpty()) View.VISIBLE else View.GONE
}

override fun showFilterProgress() {
Bindings.setViewVisibility(
binding.clearFilter,
Expand Down Expand Up @@ -157,7 +153,7 @@ class ProgramFragment : FragmentGlobalAbstract(), ProgramView {
val stepCondition = SparseBooleanArray()
stepCondition.put(
7,
presenter.programs().value?.size ?: 0 > 0,
(presenter.programs.value?.size ?: 0) > 0,
)
HelpManager.getInstance().show(
abstractActivity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.usescases.main.program

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.processors.PublishProcessor
Expand All @@ -23,7 +24,8 @@ class ProgramPresenter internal constructor(
private val syncStatusController: SyncStatusController,
) {

private val programs = MutableLiveData<List<ProgramViewModel>>(emptyList())
private val _programs = MutableLiveData<List<ProgramViewModel>>()
val programs: LiveData<List<ProgramViewModel>> = _programs
private val refreshData = PublishProcessor.create<Unit>()
var disposable: CompositeDisposable = CompositeDisposable()

Expand All @@ -48,8 +50,7 @@ class ProgramPresenter internal constructor(
.observeOn(schedulerProvider.ui())
.subscribe(
{ programs ->
this.programs.postValue(programs)
view.swapProgramModelData(programs)
_programs.postValue(programs)
},
{ throwable -> Timber.d(throwable) },
{ Timber.tag("INIT DATA").d("LOADING ENDED") },
Expand Down Expand Up @@ -119,8 +120,6 @@ class ProgramPresenter internal constructor(
filterManager.addOrgUnits(selectedOrgUnits)
}

fun programs() = programs

fun downloadState() = syncStatusController.observeDownloadProcess()

fun setIsDownloading() {
Expand Down
107 changes: 70 additions & 37 deletions app/src/main/java/org/dhis2/usescases/main/program/ProgramUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import androidx.compose.material.IconButton
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ErrorOutline
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -71,10 +73,14 @@ import org.dhis2.data.service.SyncStatusData
import org.dhis2.ui.MetadataIcon
import org.dhis2.ui.MetadataIconData
import org.hisp.dhis.android.core.common.State
import org.hisp.dhis.mobile.ui.designsystem.component.InfoBar
import org.hisp.dhis.mobile.ui.designsystem.component.InfoBarData
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor

@Composable
fun ProgramList(
programs: List<ProgramViewModel>,
programs: List<ProgramViewModel>?,
onItemClick: (programViewModel: ProgramViewModel) -> Unit,
onGranularSyncClick: (programViewModel: ProgramViewModel) -> Unit,
downLoadState: SyncStatusData?,
Expand All @@ -96,44 +102,51 @@ fun ProgramList(
DownloadMedia()
}

when (conf.orientation) {
Configuration.ORIENTATION_LANDSCAPE ->
LazyVerticalGrid(
columns = GridCells.Fixed(3),
contentPadding = PaddingValues(bottom = 56.dp),
) {
items(items = programs) { program ->
ProgramItem(
programViewModel = program,
onItemClick = onItemClick,
onGranularSyncClick = onGranularSyncClick,
)
Divider(
color = colorResource(id = R.color.divider_bg),
thickness = 1.dp,
startIndent = 72.dp,
)
programs?.let {
if (programs.isEmpty()) {
NoAccessMessage()
}

when (conf.orientation) {
Configuration.ORIENTATION_LANDSCAPE ->
LazyVerticalGrid(
columns = GridCells.Fixed(3),
contentPadding = PaddingValues(bottom = 56.dp),
) {
items(items = programs) { program ->
ProgramItem(
programViewModel = program,
onItemClick = onItemClick,
onGranularSyncClick = onGranularSyncClick,
)
Divider(
color = colorResource(id = R.color.divider_bg),
thickness = 1.dp,
startIndent = 72.dp,
)
}
}
}
else ->
LazyColumn(
modifier = Modifier.testTag(HOME_ITEMS),
contentPadding = PaddingValues(bottom = 56.dp),
) {
itemsIndexed(items = programs) { index, program ->
ProgramItem(
modifier = Modifier.semantics { testTag = HOME_ITEM.format(index) },
programViewModel = program,
onItemClick = onItemClick,
onGranularSyncClick = onGranularSyncClick,
)
Divider(
color = colorResource(id = R.color.divider_bg),
thickness = 1.dp,
startIndent = 72.dp,
)

else ->
LazyColumn(
modifier = Modifier.testTag(HOME_ITEMS),
contentPadding = PaddingValues(bottom = 56.dp),
) {
itemsIndexed(items = programs) { index, program ->
ProgramItem(
modifier = Modifier.semantics { testTag = HOME_ITEM.format(index) },
programViewModel = program,
onItemClick = onItemClick,
onGranularSyncClick = onGranularSyncClick,
)
Divider(
color = colorResource(id = R.color.divider_bg),
thickness = 1.dp,
startIndent = 72.dp,
)
}
}
}
}
}
}
}
Expand Down Expand Up @@ -391,6 +404,26 @@ fun DownloadMedia() {
}
}

@Composable
@Preview
fun NoAccessMessage() {
InfoBar(
modifier = Modifier.padding(Spacing.Spacing16),
infoBarData = InfoBarData(
text = stringResource(id = R.string.no_data_access),
icon = {
Icon(
imageVector = Icons.Outlined.ErrorOutline,
contentDescription = "error",
tint = SurfaceColor.Warning,
)
},
color = SurfaceColor.Warning,
backgroundColor = SurfaceColor.WarningContainer,
),
)
}

@Preview
@Composable
fun ProgramTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import org.dhis2.usescases.general.AbstractActivityContracts

interface ProgramView : AbstractActivityContracts.View {

fun swapProgramModelData(programs: List<ProgramViewModel>)

fun showFilterProgress()

fun openOrgUnitTreeSelector()
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/layout/fragment_program.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/filter" />

<TextView
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/empty_program_list"
android:textColor="@color/colorPrimary"
android:textSize="18sp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/filter" />
</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -973,4 +973,5 @@
<string name="mark_follow_up">Mark for follow-up</string>
<string name="remove">Remove</string>
<string name="coordinates">Coordinates</string>
<string name="no_data_access">You don’t have access to data.\nContact your administrator.</string>
</resources>

0 comments on commit d8be1ea

Please sign in to comment.