Skip to content

Commit

Permalink
Display surface as floating circular image
Browse files Browse the repository at this point in the history
  • Loading branch information
arrival-spring committed Feb 12, 2022
1 parent 664aa20 commit b42f1bb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ dependencies {

// opening hours parser
implementation("ch.poole:OpeningHoursParser:0.26.0")

// circular image view
implementation("de.hdodenhof:circleimageview:3.1.0")
}

/** Localizations that should be pulled from POEditor etc. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@ class AddSidewalkSurfaceForm : AbstractQuestFormAnswerFragment<SidewalkSurfaceAn
}

private fun onSelectedSide(surface: SurfaceAnswer, isRight: Boolean) {
val icon = ResImage(surface.value.asItem().drawableId!!)
val title = ResText(surface.value.asItem().titleId!!)
val image = ResImage(surface.value.asItem().drawableId!!)

if (isRight) {
binding.puzzleView.replaceRightSideImage(icon)
binding.puzzleView.setRightSideText(title)
binding.puzzleView.replaceRightSideFloatingCircularImage(image)
binding.puzzleView.replaceRightSideImage(ResImage(R.drawable.ic_sidewalk_illustration_yes))
rightSide = surface
} else {
binding.puzzleView.replaceLeftSideImage(icon)
binding.puzzleView.setLeftSideText(title)
binding.puzzleView.replaceLeftSideFloatingCircularImage(image)
binding.puzzleView.replaceLeftSideImage(ResImage(R.drawable.ic_sidewalk_illustration_yes))
leftSide = surface
}
updateLastAnswerButtonVisibility()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ class StreetSideSelectPuzzle @JvmOverloads constructor(
binding.rightSideFloatingIcon.isGone = image == null
}

fun replaceLeftSideFloatingCircularImage(image: Image?) {
setLeftSideFloatingCircularImage(image)
binding.leftSideFloatingCircularImage.animateFallDown()
}

fun replaceRightSideFloatingCircularImage(image: Image?) {
setRightSideFloatingCircularImage(image)
binding.rightSideFloatingCircularImage.animateFallDown()
}

fun setLeftSideFloatingCircularImage(image: Image?) {
binding.leftSideFloatingCircularImage.setImage(image)
binding.leftSideFloatingCircularImage.isGone = image == null
}

fun setRightSideFloatingCircularImage(image: Image?) {
binding.rightSideFloatingCircularImage.setImage(image)
binding.rightSideFloatingCircularImage.isGone = image == null
}

fun replaceLeftSideFloatingIcon(image: Image?) {
setLeftSideFloatingIcon(image)
binding.leftSideFloatingIcon.animateFallDown()
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout/view_side_select_puzzle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
tools:src="@drawable/ic_no_parking"
tools:visibility="visible" />

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/leftSideFloatingCircularImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:clickable="false"
android:focusable="false"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/surface_asphalt"
app:civ_border_width="2dp"
app:civ_border_color="#FFCCCCCC"
tools:visibility="visible" />

</RelativeLayout>

<RelativeLayout
Expand Down Expand Up @@ -112,6 +126,20 @@
tools:src="@drawable/ic_no_parking"
/>

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/rightSideFloatingCircularImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:clickable="false"
android:focusable="false"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/surface_asphalt"
app:civ_border_width="2dp"
app:civ_border_color="#FFCCCCCC"
tools:visibility="visible" />

</RelativeLayout>

</RelativeLayout>
Expand Down

1 comment on commit b42f1bb

@westnordost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! You don't need a custom view for that nor an external dependency! Making a drawable circular is no black magic. Please check out view/RotatedCircleDrawable. You don't even need it rotated, but you can still just use that class.

Please sign in to comment.