Skip to content

Commit

Permalink
Drop MCC hack for layouts (#5298)
Browse files Browse the repository at this point in the history
* Drop MCC logic from max speed quest form

* Drop MCC logic from max weight quest form
  • Loading branch information
FloEdelmann authored Oct 11, 2023
1 parent 2cc29a5 commit fbef023
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class AddMaxSpeedForm : AbstractOsmQuestForm<MaxSpeedAnswer>() {
}

private val SpeedType.layoutResId get() = when (this) {
SIGN -> R.layout.quest_maxspeed_sign
ZONE -> R.layout.quest_maxspeed_zone_sign
SIGN -> getMaxSpeedSignLayoutResId(countryInfo.countryCode)
ZONE -> getMaxSpeedZoneSignLayoutResId(countryInfo.countryCode)
LIVING_STREET -> R.layout.quest_maxspeed_living_street_sign
NSL -> R.layout.quest_maxspeed_national_speed_limit_sign
ADVISORY -> countryInfo.advisorySpeedLimitSignLayoutResId ?: R.layout.quest_maxspeed_advisory_blue
Expand Down Expand Up @@ -324,3 +324,14 @@ class AddMaxSpeedForm : AbstractOsmQuestForm<MaxSpeedAnswer>() {
private enum class SpeedType {
SIGN, ZONE, LIVING_STREET, ADVISORY, NO_SIGN, NSL
}

private fun getMaxSpeedSignLayoutResId(countryCode: String): Int = when (countryCode) {
"CA" -> R.layout.quest_maxspeed_sign_ca
"US" -> R.layout.quest_maxspeed_sign_us
else -> R.layout.quest_maxspeed_sign
}

private fun getMaxSpeedZoneSignLayoutResId(countryCode: String): Int = when (countryCode) {
"IL" -> R.layout.quest_maxspeed_zone_sign_il
else -> R.layout.quest_maxspeed_zone_sign
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class AddMaxWeightForm : AbstractOsmQuestForm<MaxWeightAnswer>() {

private fun showSignSelectionDialog() {
val ctx = context ?: return
val items = MaxWeightSign.values().map { it.asItem(layoutInflater) }
val items = MaxWeightSign.values().map {
it.asItem(layoutInflater, countryInfo.countryCode)
}
ImageListPickerDialog(ctx, items, R.layout.cell_labeled_icon_select, 2) { selected ->
selected.value?.let { setMaxWeightSign(it) }
checkIsFormComplete()
Expand All @@ -97,7 +99,8 @@ class AddMaxWeightForm : AbstractOsmQuestForm<MaxWeightAnswer>() {
binding.selectSignButton.isInvisible = true
binding.inputSignContainer.removeAllViews()

layoutInflater.inflate(sign.layoutResourceId, binding.inputSignContainer)
val layoutResourceId = sign.getLayoutResourceId(countryInfo.countryCode)
layoutInflater.inflate(layoutResourceId, binding.inputSignContainer)
initMaxWeightInput()
focusMaxWeightInput()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import de.westnordost.streetcomplete.view.DrawableImage
import de.westnordost.streetcomplete.view.image_select.DisplayItem
import de.westnordost.streetcomplete.view.image_select.Item2

fun MaxWeightSign.asItem(inflater: LayoutInflater): DisplayItem<MaxWeightSign> =
Item2(this, DrawableImage(BitmapDrawable(inflater.context.resources, createBitmap(inflater))))

val MaxWeightSign.layoutResourceId get() = when (this) {
MaxWeightSign.MAX_WEIGHT -> R.layout.quest_maxweight_sign
MaxWeightSign.MAX_GROSS_VEHICLE_MASS -> R.layout.quest_maxweight_mgv_sign
MaxWeightSign.MAX_AXLE_LOAD -> R.layout.quest_maxweight_axleload_sign
MaxWeightSign.MAX_TANDEM_AXLE_LOAD -> R.layout.quest_maxweight_tandem_axleload_sign
}
fun MaxWeightSign.asItem(
inflater: LayoutInflater,
countryCode: String,
): DisplayItem<MaxWeightSign> = Item2(
this,
DrawableImage(BitmapDrawable(
inflater.context.resources,
createBitmap(inflater, countryCode)
)),
)

private fun MaxWeightSign.createBitmap(inflater: LayoutInflater): Bitmap {
private fun MaxWeightSign.createBitmap(inflater: LayoutInflater, countryCode: String): Bitmap {
val container = FrameLayout(inflater.context)
container.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
inflater.inflate(layoutResourceId, container)
inflater.inflate(getLayoutResourceId(countryCode), container)

container.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
Expand All @@ -42,3 +43,32 @@ private fun MaxWeightSign.createBitmap(inflater: LayoutInflater): Bitmap {
container.draw(this)
}
}

fun MaxWeightSign.getLayoutResourceId(countryCode: String) = when (this) {
MaxWeightSign.MAX_WEIGHT -> getMaxWeightSignLayoutResId(countryCode)
MaxWeightSign.MAX_GROSS_VEHICLE_MASS -> getMaxWeightMgvSignLayoutResId(countryCode)
MaxWeightSign.MAX_AXLE_LOAD -> getMaxWeightAxleLoadSignLayoutResId(countryCode)
MaxWeightSign.MAX_TANDEM_AXLE_LOAD -> getMaxWeightTandemAxleLoadSignLayoutResId(countryCode)
}

private fun getMaxWeightSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_us_sign
else -> R.layout.quest_maxweight_sign
}

private fun getMaxWeightMgvSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_mgv_us_sign
"DE" -> R.layout.quest_maxweight_mgv_de_sign
"GB" -> R.layout.quest_maxweight_mgv_gb_sign
else -> R.layout.quest_maxweight_mgv_sign
}

private fun getMaxWeightAxleLoadSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_axleload_us_sign
else -> R.layout.quest_maxweight_axleload_sign
}

private fun getMaxWeightTandemAxleLoadSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_tandem_axleload_us_sign
else -> R.layout.quest_maxweight_tandem_axleload_sign
}
9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc234/quest_maxweight_mgv_sign.xml

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/res/layout-mcc262/quest_maxweight_mgv_sign.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/layout-mcc302/quest_maxspeed_sign.xml

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc302/quest_maxweight_mgv_sign.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc302/quest_maxweight_sign.xml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/layout-mcc310/quest_maxspeed_sign.xml

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc310/quest_maxweight_mgv_sign.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc310/quest_maxweight_sign.xml

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc505/quest_maxweight_mgv_sign.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/layout-mcc505/quest_maxweight_sign.xml

This file was deleted.

This file was deleted.

0 comments on commit fbef023

Please sign in to comment.