fix ellipsize
This commit is contained in:
@@ -226,7 +226,6 @@ class DownloadService : Service() {
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
Log.d("PUPILD", "ONRESPONSE ${call.request().tag()}")
|
||||
val (galleryID, index, startId) = call.request().tag() as Tag
|
||||
val ext = call.request().url().encodedPath().split('.').last()
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.Call
|
||||
import xyz.quaver.io.FileX
|
||||
import xyz.quaver.io.util.*
|
||||
import xyz.quaver.io.util.deleteRecursively
|
||||
import xyz.quaver.io.util.getChild
|
||||
import xyz.quaver.io.util.readText
|
||||
import xyz.quaver.io.util.writeText
|
||||
import xyz.quaver.pupil.client
|
||||
import xyz.quaver.pupil.services.DownloadService
|
||||
import xyz.quaver.pupil.util.Preferences
|
||||
|
||||
@@ -125,11 +125,30 @@ suspend fun GalleryInfo.getRequestBuilders(): List<Request.Builder> {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.ellipsize(n: Int): String =
|
||||
if (this.length > n)
|
||||
this.slice(0 until n) + "…"
|
||||
else
|
||||
this
|
||||
fun byteCount(codePoint: Int): Int = when (codePoint) {
|
||||
in 0 ..< 0x80 -> 1
|
||||
in 0x80 ..< 0x800 -> 2
|
||||
in 0x800 ..< 0x10000 -> 3
|
||||
in 0x10000 ..< 0x110000 -> 4
|
||||
else -> 0
|
||||
}
|
||||
|
||||
fun String.ellipsize(n: Int): String = buildString {
|
||||
var count = 0
|
||||
var index = 0
|
||||
val codePointLength = this.codePointCount(0, this.length)
|
||||
|
||||
while (index < codePointLength) {
|
||||
val next = this.codePointAt(index)
|
||||
if (count + next > 124) {
|
||||
append("…")
|
||||
break
|
||||
}
|
||||
appendCodePoint(next)
|
||||
count += next
|
||||
index++
|
||||
}
|
||||
}
|
||||
|
||||
operator fun JsonElement.get(index: Int) =
|
||||
this.jsonArray[index]
|
||||
|
||||
Reference in New Issue
Block a user