Show toot stat inline (#3413)
* Show toot stat inline * Correct elements position * Format stats and show it according to setting * inline toot statistics setting * Code formatting * Use kotlin functions * Change the statistics setting description * Use capital letters for all variants * increase the statistics margin * Merge fixes * Code review fixes * move setReblogsCount and setFavouritedCount to StatusViewHolder * code cleaning * code cleaning * import lexicographical order --------- Co-authored-by: Grigorii Ioffe <zikasaks@gmail.com> Co-authored-by: grigoriiioffe <zikasaks@icloud.com>
This commit is contained in:
parent
9087d0ecdd
commit
75e7b9f1a5
16 changed files with 146 additions and 4 deletions
|
|
@ -0,0 +1,26 @@
|
|||
@file:JvmName("NumberUtils")
|
||||
|
||||
package com.keylesspalace.tusky.util
|
||||
|
||||
import java.text.DecimalFormat
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sign
|
||||
|
||||
val shortLetters = arrayOf(' ', 'K', 'M', 'B', 'T', 'P', 'E')
|
||||
|
||||
fun shortNumber(number: Number): String {
|
||||
val numberAsDouble = number.toDouble()
|
||||
val nonNegativeValue = abs(numberAsDouble)
|
||||
var sign = ""
|
||||
if (numberAsDouble.sign < 0) { sign = "-" }
|
||||
val value = floor(log10(nonNegativeValue)).toInt()
|
||||
val base = value / 3
|
||||
if (value >= 3 && base < shortLetters.size) {
|
||||
return DecimalFormat("$sign#0.0").format(nonNegativeValue / 10.0.pow((base * 3).toDouble())) + shortLetters[base]
|
||||
} else {
|
||||
return DecimalFormat("$sign#,##0").format(nonNegativeValue)
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,8 @@ data class StatusDisplayOptions(
|
|||
val hideStats: Boolean,
|
||||
@get:JvmName("animateEmojis")
|
||||
val animateEmojis: Boolean,
|
||||
@get:JvmName("showStatsInline")
|
||||
val showStatsInline: Boolean,
|
||||
@get:JvmName("showSensitiveMedia")
|
||||
val showSensitiveMedia: Boolean,
|
||||
@get:JvmName("openSpoiler")
|
||||
|
|
@ -119,6 +121,7 @@ data class StatusDisplayOptions(
|
|||
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
|
||||
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
|
||||
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
|
||||
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false),
|
||||
showSensitiveMedia = account.alwaysShowSensitiveMedia,
|
||||
openSpoiler = account.alwaysOpenSpoiler
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue