feat: Enhance background color animation on theme change in SwipeableDialogItem
This commit is contained in:
@@ -64,7 +64,6 @@ object TransportManager {
|
||||
*/
|
||||
private suspend fun getActiveServer(): String {
|
||||
transportServer?.let { return it }
|
||||
|
||||
requestTransportServer()
|
||||
repeat(40) { // 10s total
|
||||
val server = transportServer
|
||||
@@ -73,7 +72,6 @@ object TransportManager {
|
||||
}
|
||||
delay(250)
|
||||
}
|
||||
|
||||
throw IOException("Transport server is not set")
|
||||
}
|
||||
|
||||
@@ -111,17 +109,16 @@ object TransportManager {
|
||||
*/
|
||||
suspend fun uploadFile(id: String, content: String): String = withContext(Dispatchers.IO) {
|
||||
val server = getActiveServer()
|
||||
ProtocolManager.addLog("📤 Upload start: id=${id.take(8)}, server=$server")
|
||||
|
||||
// Добавляем в список загрузок
|
||||
_uploading.value = _uploading.value + TransportState(id, 0)
|
||||
|
||||
try {
|
||||
withRetry {
|
||||
// 🔥 КРИТИЧНО: Преобразуем строку в байты (как desktop делает new Blob([content]))
|
||||
val contentBytes = content.toByteArray(Charsets.UTF_8)
|
||||
val totalSize = contentBytes.size.toLong()
|
||||
|
||||
// 🔥 RequestBody с отслеживанием прогресса загрузки
|
||||
val progressRequestBody = object : RequestBody() {
|
||||
override fun contentType() = "application/octet-stream".toMediaType()
|
||||
override fun contentLength() = totalSize
|
||||
@@ -129,7 +126,7 @@ object TransportManager {
|
||||
override fun writeTo(sink: okio.BufferedSink) {
|
||||
val source = okio.Buffer().write(contentBytes)
|
||||
var uploaded = 0L
|
||||
val bufferSize = 8 * 1024L // 8 KB chunks
|
||||
val bufferSize = 8 * 1024L
|
||||
|
||||
while (true) {
|
||||
val read = source.read(sink.buffer, bufferSize)
|
||||
@@ -138,7 +135,6 @@ object TransportManager {
|
||||
uploaded += read
|
||||
sink.flush()
|
||||
|
||||
// Обновляем прогресс
|
||||
val progress = ((uploaded * 100) / totalSize).toInt()
|
||||
_uploading.value = _uploading.value.map {
|
||||
if (it.id == id) it.copy(progress = progress) else it
|
||||
@@ -175,8 +171,6 @@ object TransportManager {
|
||||
|
||||
val responseBody = response.body?.string()
|
||||
?: throw IOException("Empty response")
|
||||
|
||||
// Parse JSON response to get tag
|
||||
val tag = org.json.JSONObject(responseBody).getString("t")
|
||||
|
||||
// Обновляем прогресс до 100%
|
||||
@@ -184,8 +178,15 @@ object TransportManager {
|
||||
if (it.id == id) it.copy(progress = 100) else it
|
||||
}
|
||||
|
||||
ProtocolManager.addLog("✅ Upload success: id=${id.take(8)}, tag=${tag.take(10)}")
|
||||
|
||||
tag
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ProtocolManager.addLog(
|
||||
"❌ Upload failed: id=${id.take(8)}, reason=${e.javaClass.simpleName}: ${e.message ?: "unknown"}"
|
||||
)
|
||||
throw e
|
||||
} finally {
|
||||
// Удаляем из списка загрузок
|
||||
_uploading.value = _uploading.value.filter { it.id != id }
|
||||
|
||||
Reference in New Issue
Block a user