Skip to content

Commit

Permalink
fix: [ANDROAPP-6457] limit max height of expanded cards in maps (#3910)
Browse files Browse the repository at this point in the history
Co-authored-by: Xavier Molloy <[email protected]>
  • Loading branch information
Balcan and xavimolloy authored Dec 17, 2024
1 parent b642569 commit 115ce42
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
7 changes: 5 additions & 2 deletions app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.intent.Intents
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource
import java.util.concurrent.TimeUnit
import org.dhis2.AppTest
import org.dhis2.AppTest.Companion.DB_TO_IMPORT
import org.dhis2.common.BaseRobot
Expand All @@ -22,16 +24,15 @@ import org.dhis2.commons.idlingresource.CountingIdlingResourceSingleton
import org.dhis2.commons.idlingresource.SearchIdlingResourceSingleton
import org.dhis2.commons.prefs.Preference
import org.dhis2.form.ui.idling.FormCountingIdlingResource
import org.dhis2.maps.utils.OnMapReadyIdlingResourceSingleton
import org.dhis2.usescases.eventsWithoutRegistration.EventIdlingResourceSingleton
import org.dhis2.usescases.programEventDetail.eventList.EventListIdlingResourceSingleton
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.TeiDataIdlingResourceSingleton
import org.dhis2.maps.utils.OnMapReadyIdlingResourceSingleton
import org.junit.After
import org.junit.Before
import org.junit.ClassRule
import org.junit.Rule
import org.junit.rules.Timeout
import java.util.concurrent.TimeUnit

open class BaseTest {

Expand Down Expand Up @@ -86,6 +87,7 @@ open class BaseTest {
TeiDataIdlingResourceSingleton.countingIdlingResource,
EventIdlingResourceSingleton.countingIdlingResource,
OnMapReadyIdlingResourceSingleton.countingIdlingResource,
AnalyticsCountingIdlingResource.countingIdlingResource,
)
}

Expand All @@ -98,6 +100,7 @@ open class BaseTest {
SearchIdlingResourceSingleton.countingIdlingResource,
TeiDataIdlingResourceSingleton.countingIdlingResource,
EventIdlingResourceSingleton.countingIdlingResource,
AnalyticsCountingIdlingResource.countingIdlingResource,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ class TeiDashboardTest : BaseTest() {

teiDashboardRobot(composeTestRule) {
goToAnalytics()
composeTestRule.waitForIdle()
}

indicatorsRobot(composeTestRule) {
composeTestRule.waitForIdle()
checkDetails("0", "4817")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,5 @@ class TeiDashboardCardMapper(
this.filter { it.first.valueType() != ValueType.IMAGE }
.filter { it.first.valueType() != ValueType.COORDINATE }
.filter { it.first.valueType() != ValueType.FILE_RESOURCE }
.filter { it.second.value()?.isNotEmpty() == true }
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TrackedEntityInstanceInfoProvider(
ValueType.IMAGE,
ValueType.FILE_RESOURCE,
ValueType.COORDINATE,
).contains(attribute.valueType)
).contains(attribute.valueType) && attribute.value != null
}.map { attribute ->
AdditionalInfoItem(
key = attribute.displayFormName,
Expand Down
22 changes: 19 additions & 3 deletions dhis2_android_maps/src/main/java/org/dhis2/maps/views/MapScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Icon
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import org.dhis2.maps.R
import org.dhis2.maps.location.LocationState
Expand All @@ -34,7 +41,15 @@ fun MapScreen(
onItem: @Composable LazyItemScope.(item: MapItemModel) -> Unit,

) {
Box(modifier = Modifier.fillMaxSize()) {
var pagerMaxHeight by remember { mutableStateOf(Dp.Unspecified) }

Box(
modifier = Modifier
.fillMaxSize()
.onGloballyPositioned {
pagerMaxHeight = (it.size.height * 0.7).dp
},
) {
map()
Column(
modifier = Modifier
Expand All @@ -46,7 +61,8 @@ fun MapScreen(
MapItemHorizontalPager(
modifier = Modifier
.align(Alignment.BottomCenter)
.testTag("MAP_CAROUSEL"),
.testTag("MAP_CAROUSEL")
.heightIn(max = pagerMaxHeight),
state = listState,
items = items,
onItem = onItem,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dhis2.org.analytics.charts.idling

import androidx.test.espresso.idling.CountingIdlingResource

object AnalyticsCountingIdlingResource {
private const val RESOURCE = "ANALYTICS"

@JvmField
val countingIdlingResource = CountingIdlingResource(RESOURCE)
fun increment() {
countingIdlingResource.increment()
}

fun decrement() {
if (!countingIdlingResource.isIdleNow) {
countingIdlingResource.decrement()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dhis2.org.R
import dhis2.org.analytics.charts.data.AnalyticGroup
import dhis2.org.analytics.charts.di.AnalyticsComponentProvider
import dhis2.org.analytics.charts.extensions.isNotCurrent
import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource
import dhis2.org.analytics.charts.ui.di.AnalyticsFragmentModule
import dhis2.org.analytics.charts.ui.dialog.SearchColumnDialog
import dhis2.org.databinding.AnalyticsGroupBinding
Expand Down Expand Up @@ -250,6 +251,7 @@ class GroupAnalyticsFragment : Fragment() {
}
}
}
AnalyticsCountingIdlingResource.decrement()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dhis2.org.analytics.charts.Charts
import dhis2.org.analytics.charts.data.AnalyticGroup
import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -119,6 +120,7 @@ class GroupAnalyticsViewModel(
}

fun fetchAnalytics(groupUid: String?) {
AnalyticsCountingIdlingResource.increment()
currentGroup = groupUid
viewModelScope.launch {
val result = async(context = Dispatchers.IO) {
Expand Down

0 comments on commit 115ce42

Please sign in to comment.