90 lines
3.3 KiB
Kotlin
90 lines
3.3 KiB
Kotlin
|
|
package com.aerotoss.ui.screens
|
||
|
|
|
||
|
|
import androidx.compose.foundation.layout.*
|
||
|
|
import androidx.compose.material.icons.Icons
|
||
|
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||
|
|
import androidx.compose.material3.*
|
||
|
|
import androidx.compose.runtime.*
|
||
|
|
import androidx.compose.ui.Alignment
|
||
|
|
import androidx.compose.ui.Modifier
|
||
|
|
import androidx.compose.ui.unit.dp
|
||
|
|
import com.aerotoss.core.AeroTossManager
|
||
|
|
import com.aerotoss.model.TransferState
|
||
|
|
import com.aerotoss.ui.components.TransferProgressBar
|
||
|
|
|
||
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
||
|
|
@Composable
|
||
|
|
fun ReceiveScreen(
|
||
|
|
manager: AeroTossManager,
|
||
|
|
onBack: () -> Unit
|
||
|
|
) {
|
||
|
|
val incomingTransfer by manager.incomingTransfers.collectAsState(initial = null)
|
||
|
|
|
||
|
|
Scaffold(
|
||
|
|
topBar = {
|
||
|
|
TopAppBar(
|
||
|
|
title = { Text("Получение файла") },
|
||
|
|
navigationIcon = {
|
||
|
|
IconButton(onClick = onBack) {
|
||
|
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Назад")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
) { padding ->
|
||
|
|
Column(
|
||
|
|
modifier = Modifier
|
||
|
|
.fillMaxSize()
|
||
|
|
.padding(padding)
|
||
|
|
.padding(16.dp),
|
||
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||
|
|
verticalArrangement = Arrangement.Center
|
||
|
|
) {
|
||
|
|
if (incomingTransfer == null) {
|
||
|
|
Text(
|
||
|
|
"Ожидание входящих файлов...",
|
||
|
|
style = MaterialTheme.typography.bodyLarge
|
||
|
|
)
|
||
|
|
Spacer(modifier = Modifier.height(16.dp))
|
||
|
|
CircularProgressIndicator()
|
||
|
|
Spacer(modifier = Modifier.height(8.dp))
|
||
|
|
Text(
|
||
|
|
"Убедитесь, что другое устройство\nотправляет файл на это устройство",
|
||
|
|
style = MaterialTheme.typography.bodySmall,
|
||
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||
|
|
)
|
||
|
|
} else {
|
||
|
|
val transfer = incomingTransfer!!
|
||
|
|
TransferProgressBar(transfer)
|
||
|
|
|
||
|
|
Spacer(modifier = Modifier.height(16.dp))
|
||
|
|
|
||
|
|
when (transfer.state) {
|
||
|
|
TransferState.COMPLETED -> {
|
||
|
|
Text(
|
||
|
|
"Файл получен!",
|
||
|
|
style = MaterialTheme.typography.bodyLarge,
|
||
|
|
color = MaterialTheme.colorScheme.primary
|
||
|
|
)
|
||
|
|
}
|
||
|
|
TransferState.FAILED -> {
|
||
|
|
Text(
|
||
|
|
"Ошибка: ${transfer.error}",
|
||
|
|
style = MaterialTheme.typography.bodyLarge,
|
||
|
|
color = MaterialTheme.colorScheme.error
|
||
|
|
)
|
||
|
|
}
|
||
|
|
TransferState.CANCELLED -> {
|
||
|
|
Text(
|
||
|
|
"Передача отменена",
|
||
|
|
style = MaterialTheme.typography.bodyLarge,
|
||
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||
|
|
)
|
||
|
|
}
|
||
|
|
else -> { }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|