Skip to content

Commit

Permalink
finish implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Jan 26, 2022
1 parent 6096fec commit e07a3fb
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.annotation.AnyThread
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.view.isGone
import androidx.preference.PreferenceManager
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry
import de.westnordost.streetcomplete.databinding.QuestStreetSidePuzzleWithLastAnswerButtonBinding
import de.westnordost.streetcomplete.util.normalizeDegrees
import de.westnordost.streetcomplete.view.Image
import de.westnordost.streetcomplete.view.ResImage
import de.westnordost.streetcomplete.view.Text
import de.westnordost.streetcomplete.view.*
import de.westnordost.streetcomplete.view.image_select.DisplayItem
import de.westnordost.streetcomplete.view.image_select.ImageListPickerDialog
import de.westnordost.streetcomplete.view.image_select.Item
import de.westnordost.streetcomplete.view.image_select.Item2
import de.westnordost.streetcomplete.view.setImage
import kotlin.math.absoluteValue

abstract class AStreetSideSelectFragment<I,T> : AbstractQuestFormAnswerFragment<T>() {
Expand All @@ -34,7 +34,7 @@ abstract class AStreetSideSelectFragment<I,T> : AbstractQuestFormAnswerFragment<
private lateinit var favs: LastPickedValuesStore<LastSelection<I>>
private val lastSelection get() = favs.get().firstOrNull()

open val cellLayoutId = R.layout.cell_labeled_image_select
open val cellLayoutId = R.layout.cell_icon_select_with_label_below

open val defaultImage get() = ResImage(if (countryInfo.isLeftHandTraffic) R.drawable.ic_street_side_unknown_l else R.drawable.ic_street_side_unknown)

Expand Down Expand Up @@ -126,7 +126,7 @@ abstract class AStreetSideSelectFragment<I,T> : AbstractQuestFormAnswerFragment<
private fun showSelectionDialog(isRight: Boolean) {
val ctx = context ?: return

ImageListPickerDialog(ctx, items.map { it.toDisplayItem() }, cellLayoutId, 2) { item ->
ImageListPickerDialog(ctx, items.map { it.asItem() }, cellLayoutId, 2) { item ->
onSelectedSide(items.find { it.value == item.value }!!, isRight)
}.show()
}
Expand Down Expand Up @@ -218,12 +218,37 @@ private data class LastSelection<T>(
val right: StreetSideDisplayItem<T>
)

data class StreetSideDisplayItem<T>(
val value: T,
val image: Image,
val icon: Image = image,
val floatingIcon: Image? = null,
val title: Text? = null) {
interface StreetSideDisplayItem<T> {
val value: T
val image: Image
val title: Text?
val icon: Image
val floatingIcon: Image?

fun toDisplayItem(): DisplayItem<T> = Item2(value, icon, title)
fun asItem(): DisplayItem<T>
}

data class StreetSideItem<T>(
override val value: T,
@DrawableRes val imageId: Int,
@StringRes val titleId: Int? = null,
@DrawableRes val iconId: Int = imageId,
@DrawableRes val floatingIconId: Int? = null
) : StreetSideDisplayItem<T> {
override val image: Image get() = ResImage(imageId)
override val title: Text? get() = titleId?.let { ResText(it) }
override val icon: Image get() = ResImage(iconId)
override val floatingIcon: Image? get() = floatingIconId?.let { ResImage(it) }

override fun asItem() = Item(value, iconId, titleId)
}

data class StreetSideItem2<T>(
override val value: T,
override val image: Image,
override val title: Text? = null,
override val icon: Image = image,
override val floatingIcon: Image? = null
) : StreetSideDisplayItem<T> {
override fun asItem() = Item2(value, icon, title)
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package de.westnordost.streetcomplete.quests.shoulder

import android.os.Bundle
import android.view.View
import android.widget.TextView
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.AStreetSideSelectFragment
import de.westnordost.streetcomplete.quests.StreetSideDisplayItem
import de.westnordost.streetcomplete.view.ResImage
import de.westnordost.streetcomplete.view.ResText
import de.westnordost.streetcomplete.quests.StreetSideItem

class AddShoulderForm : AStreetSideSelectFragment<Boolean, ShoulderSides>() {

override val contentLayoutResId = R.layout.quest_shoulder_explanation

override val items = listOf(
StreetSideDisplayItem(
value = false,
image = ResImage(R.drawable.ic_shoulder_no_illustration),
icon = ResImage(R.drawable.ic_shoulder_no),
title = ResText(R.string.quest_shoulder_value_no)
StreetSideItem(
false,
R.drawable.ic_shoulder_illustration_no,
R.string.quest_shoulder_value_no,
R.drawable.ic_shoulder_no
),
StreetSideDisplayItem(
value = true,
image = ResImage(R.drawable.ic_shoulder_yes_illustration),
icon = ResImage(R.drawable.ic_shoulder_yes),
title = ResText(R.string.quest_shoulder_value_yes)
StreetSideItem(
true,
R.drawable.ic_shoulder_illustration_yes,
R.string.quest_shoulder_value_yes,
R.drawable.ic_shoulder_yes
)
)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.descriptionLabel).setText(R.string.quest_shoulder_explanation)
}

override fun onClickOk(leftSide: Boolean, rightSide: Boolean) {
applyAnswer(ShoulderSides(leftSide, rightSide))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import de.westnordost.streetcomplete.quests.AStreetSideSelectFragment

class AddSidewalkForm : AStreetSideSelectFragment<Sidewalk, SidewalkSides>() {

override val items = Sidewalk.values().map { it.asStreetSideDisplayItem() }
override val items = Sidewalk.values().map { it.asStreetSideItem() }

override fun onClickOk(leftSide: Sidewalk, rightSide: Sidewalk) {
applyAnswer(SidewalkSides(leftSide, rightSide))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package de.westnordost.streetcomplete.quests.sidewalk

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.StreetSideDisplayItem
import de.westnordost.streetcomplete.quests.StreetSideItem
import de.westnordost.streetcomplete.quests.sidewalk.Sidewalk.*
import de.westnordost.streetcomplete.view.ResImage
import de.westnordost.streetcomplete.view.ResText
import de.westnordost.streetcomplete.view.image_select.DisplayItem
import de.westnordost.streetcomplete.view.image_select.Item

val Sidewalk.iconResId get() = when(this) {
YES -> R.drawable.ic_sidewalk_yes
Expand All @@ -29,10 +30,8 @@ val Sidewalk.titleResId get() = when(this) {
SEPARATE -> R.string.quest_sidewalk_value_separate
}

fun Sidewalk.asStreetSideDisplayItem() = StreetSideDisplayItem(
this,
ResImage(imageResId),
ResImage(iconResId),
floatingIconResId?.let { ResImage(it) },
ResText(titleResId)
)
fun Sidewalk.asStreetSideItem(): StreetSideDisplayItem<Sidewalk> =
StreetSideItem(this, imageResId, titleResId, iconResId, floatingIconResId)

fun Sidewalk.asItem(): DisplayItem<Sidewalk> =
Item(this, iconResId, titleResId)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M0,0h136v256h-136z"
android:strokeWidth=".80861"
android:pathData="M0,0h152v256h-152z"
android:strokeWidth=".85485"
android:fillColor="#808080"/>
<path
android:pathData="M104,0h16v256h-16z"
android:pathData="M120,0h16v256h-16z"
android:fillColor="#fcfcfc"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M0,0h208v256h-208z"
android:pathData="M0,0h224v256h-224z"
android:strokeWidth="1.0378"
android:fillColor="#808080"/>
<path
android:pathData="M104,0h16v256h-16z"
android:pathData="M120,0h16v256h-16z"
android:fillColor="#fff"/>
</vector>
15 changes: 10 additions & 5 deletions app/src/main/res/drawable/ic_shoulder_no.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M0,0h136v256h-136z"
android:strokeWidth=".80861"
android:pathData="M0,0h152v256h-152z"
android:strokeWidth=".85485"
android:fillColor="#808080"/>
<path
android:pathData="M104,0h16v256h-16z"
android:pathData="M120,0h16v256h-16z"
android:fillColor="#fcfcfc"/>
<path
android:pathData="m144,96 l64,64m-63.965,0 l63.965,-64"
android:pathData="m176,108 l64,64m-63.965,0 l63.965,-64"
android:strokeAlpha="0.2"
android:strokeWidth="20"
android:strokeColor="#000"
android:strokeLineCap="round"/>
<path
android:pathData="m176,96 l64,64m-63.965,0 l63.965,-64"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#c30"
android:strokeLineCap="round"/>
</vector>
15 changes: 11 additions & 4 deletions app/src/main/res/drawable/ic_shoulder_yes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M0,0h208v256h-208z"
android:pathData="M0,0h224v256h-224z"
android:strokeWidth="1.0378"
android:fillColor="#808080"/>
<path
android:pathData="M104,0h16v256h-16z"
android:pathData="M120,0h16v256h-16z"
android:fillColor="#fff"/>
<path
android:pathData="m136.42,128 l32,32 56,-64"
android:pathData="m152.42,140 l32,32 56,-64"
android:strokeAlpha="0.2"
android:strokeLineJoin="round"
android:strokeWidth="20"
android:strokeColor="#000"
android:strokeLineCap="round"/>
<path
android:pathData="m152.42,128 l32,32 56,-64"
android:strokeLineJoin="round"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#3c0"
android:strokeLineCap="round"/>
</vector>
2 changes: 0 additions & 2 deletions app/src/main/res/drawable/ic_sidewalk_separate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
android:pathData="m239.63,119.62 l-51.897,-36.571m-83.534,64.825c35.557,-35.166 82.687,-33.317 135.43,-28.253m0,0 l-52.941,33.088"
android:strokeAlpha="0.2"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#000"
android:strokeLineCap="round"/>
<path
android:pathData="m239.63,107.62 l-51.897,-36.571m-83.534,64.825c35.557,-35.166 82.687,-33.317 135.43,-28.253m0,0 l-52.941,33.088"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#e48f00"
android:strokeLineCap="round"/>
</vector>
6 changes: 0 additions & 6 deletions app/src/main/res/layout/quest_shoulder_explanation.xml

This file was deleted.

5 changes: 5 additions & 0 deletions res/graphics/shoulder graphics/illustration_no.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions res/graphics/shoulder graphics/illustration_yes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions res/graphics/shoulder graphics/no.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions res/graphics/shoulder graphics/no_illustration.svg

This file was deleted.

7 changes: 4 additions & 3 deletions res/graphics/shoulder graphics/yes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions res/graphics/shoulder graphics/yes_illustration.svg

This file was deleted.

4 changes: 4 additions & 0 deletions res/graphics/sidewalk graphics/illustration_no.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions res/graphics/sidewalk graphics/illustration_yes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions res/graphics/sidewalk graphics/no.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions res/graphics/sidewalk graphics/yes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e07a3fb

Please sign in to comment.