Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make statistics menu less sad - decorations and colour #4203

Merged
merged 43 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
72e6acd
proof of concept for placing laurel leaf
matkoniecz Feb 4, 2022
8c2db12
extra code with some unexpected failures
matkoniecz Feb 5, 2022
ee0d534
Merge branch 'master' into laureat
matkoniecz Feb 5, 2022
bb49e68
proof of concept of nonterrible laurel wreaths
matkoniecz Feb 7, 2022
d3f8157
first laurel wreath that is actually nice
matkoniecz Feb 7, 2022
6140ad1
abandoned night mode attempt
matkoniecz Feb 10, 2022
f4f1abe
Revert "abandoned night mode attempt"
matkoniecz Jul 2, 2022
04ff843
Merge branch 'master' into laureat
matkoniecz Jul 2, 2022
5b2535a
ktlint terror
matkoniecz Jul 2, 2022
03c21f7
try to fix leading leaf offset on left side
matkoniecz Jul 2, 2022
2b117ff
uniformify drawable sizes so rotations will be predictable
matkoniecz Jul 2, 2022
c49444f
shorten stalk on leaf ending to eliminate artefact
matkoniecz Jul 3, 2022
3cea77e
more stringent testing of renderings
matkoniecz Jul 3, 2022
27e73b7
drop dead code and fix typo
matkoniecz Jul 3, 2022
7f2585a
start applying styling to real ranks
matkoniecz Jul 3, 2022
9a61547
avoid merging decoration with text
matkoniecz Jul 4, 2022
3117e03
more encouraging scaling of active days for new mappers
matkoniecz Jul 4, 2022
409ef51
remove test graphics
matkoniecz Jul 4, 2022
fc049b1
tweak colors for background
matkoniecz Jul 4, 2022
8cbecf0
tweak colors backround ranking bubbles
matkoniecz Jul 4, 2022
fb415ab
Merge branch 'master' into laureat
matkoniecz Jul 12, 2022
8bf90d2
note authorship
matkoniecz Jul 12, 2022
64eb57a
make placeholders more clear
matkoniecz Jul 12, 2022
aca6ef3
ktlint terror
matkoniecz Jul 12, 2022
a0dc92a
drop misleading comment
matkoniecz Jul 12, 2022
412435c
further comment fixes
matkoniecz Jul 12, 2022
5528e67
minor code refactoring
matkoniecz Jul 12, 2022
c3220a6
explain code, tiny moving to more logical order
matkoniecz Jul 12, 2022
90434fb
tweak reward scaling
matkoniecz Jul 12, 2022
79861bb
better describe what is going on
matkoniecz Jul 12, 2022
6d01823
drop inkscape cruft
matkoniecz Jul 12, 2022
1c09c1e
variables better explaining what is going on
matkoniecz Jul 12, 2022
f81533c
remove placeholders used for testing
matkoniecz Jul 12, 2022
56958af
use drawArc
matkoniecz Jul 13, 2022
6d34230
move LaurelWreath to a separate file
matkoniecz Jul 13, 2022
dcc559b
Merge branch 'master' into laureat
matkoniecz Oct 22, 2022
ca8a9b9
set to private as needed
matkoniecz Oct 22, 2022
4d2cbbe
stalk is drawn with arc
matkoniecz Oct 22, 2022
6625df7
cosmetic rename
matkoniecz Oct 22, 2022
33619fb
refactor, subtler stalk, draw arc once
matkoniecz Oct 22, 2022
4712728
switch to double-sided leaf
matkoniecz Oct 22, 2022
f8cf200
stop showing stalk of laurel wreath
matkoniecz Oct 23, 2022
91a1e78
better names
matkoniecz Oct 24, 2022
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 @@ -21,12 +21,15 @@ import de.westnordost.streetcomplete.util.ktx.createBitmap
import de.westnordost.streetcomplete.util.ktx.tryStartActivity
import de.westnordost.streetcomplete.util.ktx.viewLifecycleScope
import de.westnordost.streetcomplete.util.viewBinding
import de.westnordost.streetcomplete.view.LaurelWreathDrawable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.inject
import org.koin.core.qualifier.named
import java.io.File
import java.lang.Math.max
import java.lang.Math.min
import java.util.Locale

/** Shows the user profile: username, avatar, star count and a hint regarding unpublished changes */
Expand Down Expand Up @@ -147,12 +150,21 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
val daysActive = statisticsSource.daysActive
binding.daysActiveContainer.isGone = daysActive <= 0
binding.daysActiveText.text = daysActive.toString()
binding.daysActiveText.background = LaurelWreathDrawable(resources, min(daysActive + 20, 100))
}

private fun updateGlobalRankText() {
// note that global rank merges multiple people with the same score
// in case that 1000 people made 11 edits all will have the same rank (say, 3814)
// in case that 1000 people made 10 edits all will have the same rank (in this case - 3815)
val rank = statisticsSource.rank
binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getEditCount() <= 100
binding.globalRankText.text = "#$rank"
val rankEnoughForFullMarks = 1000
val rankEnoughToStartGrowingReward = 3800
val ranksAboveThreshold = max(rankEnoughToStartGrowingReward - rank, 0)
val scaledRank = (ranksAboveThreshold * 100.0 / (rankEnoughToStartGrowingReward - rankEnoughForFullMarks)).toInt()
binding.globalRankText.background = LaurelWreathDrawable(resources, min(scaledRank, 100))
}

private suspend fun updateLocalRankText() {
Expand All @@ -164,15 +176,19 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
val shouldShow = statistics.rank != null && statistics.rank > 0 && statistics.count > 50
val countryLocale = Locale("", statistics.countryCode)
binding.localRankContainer.isGone = !shouldShow
binding.localRankText.text = "#${statistics.rank}"
binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry)
if (shouldShow) {
binding.localRankText.text = "#${statistics.rank}"
binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry)
binding.localRankText.background = LaurelWreathDrawable(resources, min(100 - statistics.rank!!, 100))
westnordost marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

private suspend fun updateAchievementLevelsText() {
val levels = withContext(Dispatchers.IO) { achievementsSource.getAchievements().sumOf { it.second } }
binding.achievementLevelsContainer.isGone = levels <= 0
binding.achievementLevelsText.text = "$levels"
binding.achievementLevelsText.background = LaurelWreathDrawable(resources, min(levels / 2, 100))
}

private fun openUrl(url: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.westnordost.streetcomplete.ktx

import android.graphics.Bitmap
import android.graphics.Matrix

fun Bitmap.flipHorizontally(): Bitmap {
val matrix = Matrix().apply { postScale(-1f, 1f, width/2f, width/2f) }
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package de.westnordost.streetcomplete.view

import android.content.res.Resources
import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable
import androidx.core.graphics.withRotation
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.ktx.flipHorizontally
import de.westnordost.streetcomplete.util.ktx.getBitmapDrawable

/*
Drawable providing decoration, suitable for a circular background
100 and more: fully grown wreath with all pretty elements
99 to 10: may be losing elements as it gets smaller
below: no decorative styling at all
*/
class LaurelWreathDrawable(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() {
private val pairOflaurelLeafs = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_pair)
private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending)
private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) }

private val antiAliasPaint: Paint = Paint().apply {
isAntiAlias = true
isFilterBitmap = true
}

override fun draw(canvas: Canvas) {
val canvasWidth: Int = bounds.width()
val canvasHeight: Int = bounds.height()
val circleRadius: Float = Math.min(canvasWidth, canvasHeight).toFloat() / 2f

canvas.drawCircle((canvasWidth / 2).toFloat(), (canvasHeight / 2).toFloat(), circleRadius, niceSubtleGreen)

if (percentageOfGrowth < 10) {
return
}

val decorationSegmentImageWidth = pairOflaurelLeafs.intrinsicWidth // width is the same as intrinsicWidth

val maximumDecorationSegmentCount = 11f

val circleCenterX = canvasWidth / 2f
val shownSegments = ((maximumDecorationSegmentCount - 1) * percentageOfGrowth / 100).toInt()
val howDistantIsDecorationFromCircleCenter = 0.78f

for (i in 1..shownSegments) {
// https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1)
var bitmap = pairOflaurelLeafs.bitmap
if (i == shownSegments) {
bitmap = horizontalEndingLeaf.bitmap
}

// left side
canvas.withRotation(i * 180.0f / maximumDecorationSegmentCount, canvasWidth / 2f, canvasHeight / 2f) {
// drawBitmap takes corner of the bitmap, we care about centering segments
canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * howDistantIsDecorationFromCircleCenter, antiAliasPaint)
}

// right side
val flippedBitmap = bitmap.flipHorizontally()
canvas.withRotation(-i * 180.0f / maximumDecorationSegmentCount, canvasWidth / 2f, canvasHeight / 2f) {
canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * howDistantIsDecorationFromCircleCenter, antiAliasPaint)
}
}
}

override fun setAlpha(alpha: Int) {
// This method is required
}

override fun setColorFilter(colorFilter: ColorFilter?) {
// This method is required
}

override fun getOpacity(): Int =
// Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE
PixelFormat.OPAQUE
}
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_laurel_leaf_ending.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16.7dp"
android:height="14.774dp"
android:viewportWidth="16.7"
android:viewportHeight="14.774">
<path
android:fillColor="#FF000000"
android:pathData="m2.615,7.307h10.748v0.048h-10.748z"
android:strokeWidth="0.713252"
android:strokeColor="#065006"
android:fillType="evenOdd"
android:fillAlpha="0.244816"/>
<path
android:pathData="m14.867,7.714c-0.92,0.493 -0.3,0.145 -1.049,0.625 -1.515,0.97 -4.763,1.159 -6.519,1.021 -2.601,-0.205 -7.299,-2.103 -7.299,-2.103 0,0 1.664,-0.673 3.317,-1.132 1.264,-0.351 2.585,-0.763 3.913,-0.751 2.447,0.023 6.172,0.913 7.184,1.518 0.562,0.105 0.443,0.033 0.443,0.033z"
android:strokeLineJoin="miter"
android:strokeWidth="0.14293"
android:fillColor="#006a00"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
</vector>
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_laurel_leaf_pair.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16.7dp"
android:height="14.774dp"
android:viewportWidth="16.7"
android:viewportHeight="14.774">
<path
android:pathData="m13.761,7.426c-0.801,-0.689 -0.944,-0.846 -1.022,-1.393 -0.157,-1.105 -1.992,-2.763 -3.174,-3.568 -1.751,-1.193 -6.933,-2.479 -6.933,-2.479 0,0 1.293,0.773 1.939,1.753 0.494,0.75 1.01,1.72 1.493,2.204 0.989,0.991 1.703,1.659 3.154,2.379 1.871,0.929 2.126,0.251 3.037,0.587 0.477,0.176 1.203,0.692 1.203,0.692z"
android:strokeLineJoin="miter"
android:strokeWidth="0.14293"
android:fillColor="#006a00"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
<path
android:pathData="m13.761,7.342c-0.801,0.689 -0.944,0.846 -1.022,1.393 -0.157,1.105 -1.992,2.763 -3.174,3.568 -1.751,1.193 -6.933,2.479 -6.933,2.479 0,-0 1.293,-0.773 1.939,-1.753 0.494,-0.75 1.01,-1.72 1.493,-2.204 0.989,-0.991 1.703,-1.659 3.154,-2.379 1.871,-0.929 2.126,-0.251 3.037,-0.587 0.477,-0.176 1.203,-0.692 1.203,-0.692z"
android:strokeLineJoin="miter"
android:strokeWidth="0.14293"
android:fillColor="#006a00"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
</vector>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/ic_laurel_leaf_stalk.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16.7dp"
android:height="14.774dp"
android:viewportWidth="16.7"
android:viewportHeight="14.774">
<path
android:pathData="M2.976,12.355h10.748v0.048h-10.748z"
android:strokeWidth="0.713252"
android:fillColor="#f9006b"
android:strokeColor="#065006"
android:fillType="evenOdd"
android:fillAlpha="0.244816"/>
</vector>
16 changes: 8 additions & 8 deletions app/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@

<TextView
android:id="@+id/localRankText"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:background="@drawable/background_inverted_text_circle"
android:gravity="center"
android:padding="8dp"
Expand Down Expand Up @@ -164,8 +164,8 @@

<TextView
android:id="@+id/globalRankText"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:background="@drawable/background_inverted_text_circle"
android:gravity="center"
android:padding="8dp"
Expand Down Expand Up @@ -198,8 +198,8 @@

<TextView
android:id="@+id/daysActiveText"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:background="@drawable/background_inverted_text_circle"
android:gravity="center"
android:padding="8dp"
Expand Down Expand Up @@ -232,8 +232,8 @@

<TextView
android:id="@+id/achievementLevelsText"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:background="@drawable/background_inverted_text_circle"
android:gravity="center"
android:padding="8dp"
Expand Down
4 changes: 4 additions & 0 deletions res/graphics/authors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ lanes/
car4.svg
car5.svg

laurel_wreath/
laurel_leaf_rotated.svg CC0 Mateusz Konieczny (if even copyright is applicable here)
laurel_leaf_ending.svg CC0 Mateusz Konieczny (if even copyright is applicable here)

links/
link_neis_one.svg

Expand Down
34 changes: 34 additions & 0 deletions res/graphics/laurel_wreath/ic_laurel_leaf_pair.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions res/graphics/laurel_wreath/laurel_leaf_ending.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.