Причина синхронизации и временная метка в логах
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
package com.github.nullptroma.wallenc.ui.resources
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.tasks.StorageSyncTriggerReason
|
||||
import com.github.nullptroma.wallenc.domain.tasks.TaskLogKey
|
||||
import com.github.nullptroma.wallenc.ui.R
|
||||
|
||||
fun TaskLogKey.resolve(resolver: UiStringResolver): String = when (this) {
|
||||
TaskLogKey.SyncStarted -> resolver(R.string.task_log_sync_started)
|
||||
TaskLogKey.SyncFinished -> resolver(R.string.task_log_sync_finished)
|
||||
is TaskLogKey.SyncStarted -> resolver(
|
||||
R.string.task_log_sync_started,
|
||||
resolver.resolveSyncTriggerReason(reason),
|
||||
)
|
||||
is TaskLogKey.SyncFinished -> resolver(
|
||||
R.string.task_log_sync_finished,
|
||||
resolver.resolveSyncTriggerReason(reason),
|
||||
)
|
||||
is TaskLogKey.SyncFailed -> {
|
||||
val notification = error.toUserNotification().resolve(resolver)
|
||||
resolver(R.string.task_log_sync_failed, notification)
|
||||
resolver(
|
||||
R.string.task_log_sync_failed,
|
||||
resolver.resolveSyncTriggerReason(reason),
|
||||
notification,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun UiStringResolver.resolveSyncTriggerReason(reason: StorageSyncTriggerReason): String =
|
||||
when (reason) {
|
||||
StorageSyncTriggerReason.Debounce -> this(R.string.task_sync_trigger_debounce)
|
||||
StorageSyncTriggerReason.SyncTab -> this(R.string.task_sync_trigger_sync_tab)
|
||||
StorageSyncTriggerReason.Background -> this(R.string.task_sync_trigger_background)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.nullptroma.wallenc.ui.resources
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
private val pipelineTimeFormatter: DateTimeFormatter =
|
||||
DateTimeFormatter.ofPattern("HH:mm:ss")
|
||||
|
||||
fun formatTaskPipelineTime(timestampMs: Long): String =
|
||||
Instant.ofEpochMilli(timestampMs)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.format(pipelineTimeFormatter)
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.AlertDialog
|
||||
@@ -36,7 +37,9 @@ import com.github.nullptroma.wallenc.domain.tasks.PipelineTask
|
||||
import com.github.nullptroma.wallenc.domain.tasks.TaskLogLevel
|
||||
import com.github.nullptroma.wallenc.domain.tasks.TaskRunState
|
||||
import com.github.nullptroma.wallenc.ui.R
|
||||
import com.github.nullptroma.wallenc.domain.tasks.TaskLogLine
|
||||
import com.github.nullptroma.wallenc.ui.resources.displayText
|
||||
import com.github.nullptroma.wallenc.ui.resources.formatTaskPipelineTime
|
||||
import com.github.nullptroma.wallenc.ui.resources.resolveText
|
||||
import com.github.nullptroma.wallenc.ui.resources.toUserNotification
|
||||
|
||||
@@ -91,18 +94,7 @@ fun TaskPipelineScreen(
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
items(logs.size) { i ->
|
||||
val line = logs[i]
|
||||
val prefix = when (line.level) {
|
||||
TaskLogLevel.Debug -> "D"
|
||||
TaskLogLevel.Info -> "I"
|
||||
TaskLogLevel.Warn -> "W"
|
||||
TaskLogLevel.Error -> "E"
|
||||
}
|
||||
Text(
|
||||
"[$prefix] ${line.displayText()}",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
PipelineLogRow(line = logs[i])
|
||||
}
|
||||
}
|
||||
Button(
|
||||
@@ -178,14 +170,59 @@ fun TaskPipelineScreen(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PipelineLogRow(line: TaskLogLine) {
|
||||
val prefix = when (line.level) {
|
||||
TaskLogLevel.Debug -> "D"
|
||||
TaskLogLevel.Info -> "I"
|
||||
TaskLogLevel.Warn -> "W"
|
||||
TaskLogLevel.Error -> "E"
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.Top,
|
||||
) {
|
||||
Text(
|
||||
text = "[$prefix] ${line.displayText()}",
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 8.dp),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Text(
|
||||
text = formatTaskPipelineTime(line.timestampMs),
|
||||
modifier = Modifier.widthIn(min = 56.dp),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TaskRow(task: PipelineTask, isRunning: Boolean) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
task.title,
|
||||
style = if (isRunning) MaterialTheme.typography.titleSmall
|
||||
else MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = task.title,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 8.dp),
|
||||
style = if (isRunning) MaterialTheme.typography.titleSmall
|
||||
else MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
Text(
|
||||
text = formatTaskPipelineTime(task.enqueuedAtMs),
|
||||
modifier = Modifier.widthIn(min = 56.dp),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
val runningProgress = (task.state as? TaskRunState.Running)?.progress
|
||||
val progressLabel = runningProgress?.label?.resolveText()
|
||||
val stateLabel = when (val s = task.state) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.github.nullptroma.wallenc.ui.resources.resolve
|
||||
import com.github.nullptroma.wallenc.ui.resources.UserNotification
|
||||
import com.github.nullptroma.wallenc.usecases.AddStorageToSyncGroupResult
|
||||
import com.github.nullptroma.wallenc.usecases.ManageStorageSyncGroupsUseCase
|
||||
import com.github.nullptroma.wallenc.domain.tasks.StorageSyncTriggerReason
|
||||
import com.github.nullptroma.wallenc.usecases.RunStorageSyncUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.StorageSyncCompatibilityInput
|
||||
import com.github.nullptroma.wallenc.usecases.isStorageCompatibleWithGroup
|
||||
@@ -209,7 +210,7 @@ class StorageSyncViewModel @Inject constructor(
|
||||
fun runSyncNow() {
|
||||
val started = runStorageSyncUseCase.enqueue(
|
||||
displayTitle = uiStrings(R.string.task_title_storage_sync),
|
||||
logReason = "sync-tab",
|
||||
reason = StorageSyncTriggerReason.SyncTab,
|
||||
)
|
||||
if (!started) {
|
||||
updateState(
|
||||
|
||||
@@ -289,9 +289,12 @@
|
||||
<string name="sync_progress_group_renewing_locks">Синхронизация: группа «%1$s» — продление блокировок</string>
|
||||
<string name="sync_progress_group_lock_renewal_failed">Синхронизация: группа «%1$s» — не удалось продлить блокировку</string>
|
||||
<string name="task_progress_clear_content">%1$d / %2$d</string>
|
||||
<string name="task_log_sync_started">Синхронизация хранилищ запущена</string>
|
||||
<string name="task_log_sync_finished">Синхронизация хранилищ завершена</string>
|
||||
<string name="task_log_sync_failed">Синхронизация не удалась: %1$s</string>
|
||||
<string name="task_log_sync_started">Синхронизация хранилищ запущена (%1$s)</string>
|
||||
<string name="task_log_sync_finished">Синхронизация хранилищ завершена (%1$s)</string>
|
||||
<string name="task_log_sync_failed">Синхронизация не удалась (%1$s): %2$s</string>
|
||||
<string name="task_sync_trigger_debounce">debounce</string>
|
||||
<string name="task_sync_trigger_sync_tab">sync-tab</string>
|
||||
<string name="task_sync_trigger_background">background</string>
|
||||
<string name="task_log_enumerating">Перечисление файлов и папок…</string>
|
||||
<string name="task_log_creating_storage">Создание хранилища…</string>
|
||||
<string name="task_log_storage_created">Хранилище создано</string>
|
||||
|
||||
@@ -289,9 +289,12 @@
|
||||
<string name="sync_progress_group_renewing_locks">Storage sync: group "%1$s" renewing locks</string>
|
||||
<string name="sync_progress_group_lock_renewal_failed">Storage sync: group "%1$s" lock renewal failed</string>
|
||||
<string name="task_progress_clear_content">%1$d / %2$d</string>
|
||||
<string name="task_log_sync_started">Storage sync started</string>
|
||||
<string name="task_log_sync_finished">Storage sync finished</string>
|
||||
<string name="task_log_sync_failed">Storage sync failed: %1$s</string>
|
||||
<string name="task_log_sync_started">Storage sync started (%1$s)</string>
|
||||
<string name="task_log_sync_finished">Storage sync finished (%1$s)</string>
|
||||
<string name="task_log_sync_failed">Storage sync failed (%1$s): %2$s</string>
|
||||
<string name="task_sync_trigger_debounce">debounce</string>
|
||||
<string name="task_sync_trigger_sync_tab">sync-tab</string>
|
||||
<string name="task_sync_trigger_background">background</string>
|
||||
<string name="task_log_enumerating">Enumerating files and directories…</string>
|
||||
<string name="task_log_creating_storage">Creating storage…</string>
|
||||
<string name="task_log_storage_created">Storage created</string>
|
||||
|
||||
Reference in New Issue
Block a user