fix ellipsize

This commit is contained in:
tom5079
2024-04-11 08:44:45 -07:00
parent 19450f66a0
commit a5d4cbfaec
3 changed files with 28 additions and 7 deletions

View File

@@ -226,7 +226,6 @@ class DownloadService : Service() {
} }
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
Log.d("PUPILD", "ONRESPONSE ${call.request().tag()}")
val (galleryID, index, startId) = call.request().tag() as Tag val (galleryID, index, startId) = call.request().tag() as Tag
val ext = call.request().url().encodedPath().split('.').last() val ext = call.request().url().encodedPath().split('.').last()

View File

@@ -28,7 +28,10 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import okhttp3.Call import okhttp3.Call
import xyz.quaver.io.FileX 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.client
import xyz.quaver.pupil.services.DownloadService import xyz.quaver.pupil.services.DownloadService
import xyz.quaver.pupil.util.Preferences import xyz.quaver.pupil.util.Preferences

View File

@@ -125,11 +125,30 @@ suspend fun GalleryInfo.getRequestBuilders(): List<Request.Builder> {
} }
} }
fun String.ellipsize(n: Int): String = fun byteCount(codePoint: Int): Int = when (codePoint) {
if (this.length > n) in 0 ..< 0x80 -> 1
this.slice(0 until n) + "" in 0x80 ..< 0x800 -> 2
else in 0x800 ..< 0x10000 -> 3
this 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) = operator fun JsonElement.get(index: Int) =
this.jsonArray[index] this.jsonArray[index]