Fix incorrectly incrementing IDs before sending to server. (#1026)
* Fix incorrectly incrementing IDs before sending to server. * Add TimelineRepositoryTest, fix adding placeholder, fix String#dec() * Add more TimelineRepository tests, fix bugs * Add tests for adding statuses from DB.
This commit is contained in:
parent
85610a8311
commit
63952813c8
11 changed files with 631 additions and 208 deletions
|
@ -0,0 +1,22 @@
|
|||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.text.Spanned
|
||||
|
||||
/**
|
||||
* Abstracting away Android-specific things.
|
||||
*/
|
||||
interface HtmlConverter {
|
||||
fun fromHtml(html: String): Spanned
|
||||
|
||||
fun toHtml(text: Spanned): String
|
||||
}
|
||||
|
||||
internal class HtmlConverterImpl : HtmlConverter {
|
||||
override fun fromHtml(html: String): Spanned {
|
||||
return HtmlUtils.fromHtml(html)
|
||||
}
|
||||
|
||||
override fun toHtml(text: Spanned): String {
|
||||
return HtmlUtils.toHtml(text)
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ fun randomAlphanumericString(count: Int): String {
|
|||
fun String.inc(): String {
|
||||
// We assume that we will stay in the safe range for now
|
||||
val builder = this.toCharArray()
|
||||
builder.last().inc()
|
||||
builder[lastIndex] = builder[lastIndex].inc()
|
||||
return String(builder)
|
||||
}
|
||||
|
||||
|
@ -34,24 +34,25 @@ fun String.inc(): String {
|
|||
* "Decrement" string so that during sorting it's smaller than [this].
|
||||
*/
|
||||
fun String.dec(): String {
|
||||
if (this.isEmpty()) return this
|
||||
|
||||
val builder = this.toCharArray()
|
||||
var i = builder.lastIndex
|
||||
while (i > 0) {
|
||||
if (builder[i] > '0') {
|
||||
builder[i] = builder[i].dec()
|
||||
break
|
||||
return String(builder)
|
||||
} else {
|
||||
builder[i] = 'z'
|
||||
}
|
||||
i--
|
||||
}
|
||||
// All characters were '0'
|
||||
if (i == 0 && this.isNotEmpty()) {
|
||||
// Remove one character
|
||||
return String(builder.copyOfRange(1, builder.size))
|
||||
return if (builder[0] > '1') {
|
||||
builder[0] = builder[0].dec()
|
||||
String(builder)
|
||||
} else {
|
||||
String(builder.copyOfRange(1, builder.size))
|
||||
}
|
||||
|
||||
return String(builder)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue