fix trending tags for rtl languages (#4889)
closes https://github.com/tuskyapp/Tusky/issues/4887 And some other small improvements like better paddings and font sizes. Also the `status_info` in `item_status` now looks nicer in rtl mode.
This commit is contained in:
parent
170358fe89
commit
8f8b8195a1
9 changed files with 60 additions and 73 deletions
|
|
@ -41,7 +41,7 @@ class TrendingTagViewHolder(
|
|||
binding.totalAccounts.text = formatNumber(totalAccounts, 1000)
|
||||
|
||||
binding.currentUsage.text = numberFormat.format(tagViewData.usage.last())
|
||||
binding.currentAccounts.text = numberFormat.format(tagViewData.usage.last())
|
||||
binding.currentAccounts.text = numberFormat.format(tagViewData.accounts.last())
|
||||
|
||||
itemView.setOnClickListener {
|
||||
onViewTag(tagViewData.name)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import kotlin.math.abs
|
|||
import kotlin.math.ln
|
||||
import kotlin.math.pow
|
||||
|
||||
private val numberFormatter: NumberFormat = NumberFormat.getInstance()
|
||||
private val ln_1k = ln(1000.0)
|
||||
|
||||
/**
|
||||
|
|
@ -19,6 +18,7 @@ private val ln_1k = ln(1000.0)
|
|||
* a suffix appropriate to the scaling is appended.
|
||||
*/
|
||||
fun formatNumber(num: Long, min: Int = 100000): String {
|
||||
val numberFormatter: NumberFormat = NumberFormat.getInstance()
|
||||
val absNum = abs(num)
|
||||
if (absNum < min) return numberFormatter.format(num)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.graphics.Paint
|
|||
import android.graphics.Path
|
||||
import android.graphics.PathMeasure
|
||||
import android.graphics.Rect
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorInt
|
||||
|
|
@ -29,6 +30,7 @@ import androidx.core.content.res.use
|
|||
import com.google.android.material.R as materialR
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import com.keylesspalace.tusky.R
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class GraphView @JvmOverloads constructor(
|
||||
|
|
@ -68,63 +70,40 @@ class GraphView @JvmOverloads constructor(
|
|||
private var primaryLinePath: Path = Path()
|
||||
private var secondaryLinePath: Path = Path()
|
||||
|
||||
private var isRtlLayout: Boolean = false
|
||||
|
||||
var maxTrendingValue: Long = 300
|
||||
var primaryLineData: List<Long> = if (isInEditMode) {
|
||||
listOf(
|
||||
30,
|
||||
60,
|
||||
70,
|
||||
80,
|
||||
130,
|
||||
190,
|
||||
80
|
||||
)
|
||||
listOf(30, 60, 70, 80, 130, 190, 80)
|
||||
} else {
|
||||
listOf(
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
)
|
||||
listOf(1, 1, 1, 1, 1, 1, 1)
|
||||
}
|
||||
set(value) {
|
||||
field = value.map { max(1, it) }
|
||||
if (isRtlLayout) {
|
||||
field = field.reversed()
|
||||
}
|
||||
primaryLinePath.reset()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
var secondaryLineData: List<Long> = if (isInEditMode) {
|
||||
listOf(
|
||||
10,
|
||||
20,
|
||||
40,
|
||||
60,
|
||||
100,
|
||||
132,
|
||||
20
|
||||
)
|
||||
listOf(10, 20, 40, 60, 100, 132, 20)
|
||||
} else {
|
||||
listOf(
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
)
|
||||
listOf(1, 1, 1, 1, 1, 1, 1)
|
||||
}
|
||||
set(value) {
|
||||
field = value.map { max(1, it) }
|
||||
if (isRtlLayout) {
|
||||
field = field.reversed()
|
||||
}
|
||||
secondaryLinePath.reset()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
init {
|
||||
initFromXML(attrs)
|
||||
isRtlLayout = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL
|
||||
}
|
||||
|
||||
private fun initFromXML(attr: AttributeSet?) {
|
||||
|
|
@ -291,7 +270,7 @@ class GraphView @JvmOverloads constructor(
|
|||
linePath = secondaryLinePath,
|
||||
linePaint = secondaryLinePaint,
|
||||
circlePaint = secondaryCirclePaint,
|
||||
lineThickness = lineWidth
|
||||
lineThickness = lineWidth,
|
||||
)
|
||||
drawLine(
|
||||
canvas = canvas,
|
||||
|
|
@ -317,8 +296,11 @@ class GraphView @JvmOverloads constructor(
|
|||
)
|
||||
|
||||
val pm = PathMeasure(linePath, false)
|
||||
|
||||
val dotPosition = if (isRtlLayout) 0f else pm.length
|
||||
|
||||
val coord = floatArrayOf(0f, 0f)
|
||||
pm.getPosTan(pm.length * 1f, coord, null)
|
||||
pm.getPosTan(dotPosition, coord, null)
|
||||
|
||||
drawCircle(coord[0], coord[1], lineThickness * 2f, circlePaint)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue