Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Fix statistics tiles height with different font sizes (EXPOSUREAPP-14969) #5904

Merged
merged 2 commits into from
Mar 20, 2023
Merged
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 @@ -36,8 +36,10 @@ class StatisticsHomeCard(

override var savedStateKey: String? = null

private val fontScale = context.resources.configuration.fontScale

private val statisticsLayoutManager: StatisticsLayoutManager by lazy {
StatisticsLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
StatisticsLayoutManager(context, LinearLayoutManager.HORIZONTAL, false, fontScale)
}

private val statisticsCardAdapter by lazy { StatisticsCardAdapter() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@ import android.util.AttributeSet
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt

/**
* A custom RecyclerView.LayoutManager implementation that extends
* the height of items to match RecyclerView. 
**/
class StatisticsLayoutManager : LinearLayoutManager {
constructor(context: Context?) : super(context)

constructor(
context: Context?,
@RecyclerView.Orientation orientation: Int,
reverseLayout: Boolean
) : super(context, orientation, reverseLayout)

constructor(
context: Context?,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes)
**/
class StatisticsLayoutManager(
context: Context?,
@RecyclerView.Orientation orientation: Int,
reverseLayout: Boolean,
private val fontScale: Float
) :
LinearLayoutManager(context, orientation, reverseLayout) {

override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
return spanLayoutSize(super.generateDefaultLayoutParams())
Expand All @@ -38,10 +31,23 @@ class StatisticsLayoutManager : LinearLayoutManager {
return spanLayoutSize(super.generateLayoutParams(lp))
}

override fun checkLayoutParams(lp: RecyclerView.LayoutParams?): Boolean {
if (lp != null) {
if (fontScale > 1.0F) {
lp.height = (HEIGHT_MULTIPLIER * fontScale).roundToInt()
}
}
return true
}

private fun spanLayoutSize(layoutParams: RecyclerView.LayoutParams): RecyclerView.LayoutParams {
return RecyclerView.LayoutParams(
layoutParams.width,
RecyclerView.LayoutParams.MATCH_PARENT
)
}

companion object {
const val HEIGHT_MULTIPLIER = 1050
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
style="@style/StatisticsCardValueLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_8"
android:layout_marginTop="@dimen/margin_18"
android:layout_marginEnd="@dimen/margin_8"
android:ellipsize="end"
android:maxLines="3"
android:text="@string/pandemic_radar_card_message"
android:textSize="@dimen/font_14"
android:maxLines="4"
android:ellipsize="end"
app:layout_constraintEnd_toStartOf="@id/background_image"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@id/subtitle"
Expand All @@ -77,8 +77,8 @@
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginHorizontal="@dimen/margin_24"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginBottom="@dimen/margin_6"
android:text="@string/pandemic_Radar_card_button_text"
app:icon="@drawable/ic_link"
Expand Down