diff --git a/app/src/main/java/com/example/myapplication/api/item/RestItemRepository.kt b/app/src/main/java/com/example/myapplication/api/item/RestItemRepository.kt index 73b8075..96d7301 100644 --- a/app/src/main/java/com/example/myapplication/api/item/RestItemRepository.kt +++ b/app/src/main/java/com/example/myapplication/api/item/RestItemRepository.kt @@ -21,6 +21,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.IOException import java.io.OutputStream +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale class RestItemRepository( private val service: MyServerService, @@ -71,8 +74,9 @@ class RestItemRepository( suspend fun createPdfFile(context: Context, fileName: String, reportData: List) { withContext(Dispatchers.IO) { + val currentDate = SimpleDateFormat("dd.MM.yyyy", Locale.getDefault()).format(Date()) val contentValues = ContentValues().apply { - put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) + put(MediaStore.MediaColumns.DISPLAY_NAME, "$fileName от $currentDate") put(MediaStore.MediaColumns.MIME_TYPE, "application/pdf") put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS) } @@ -96,6 +100,7 @@ class RestItemRepository( } private fun createPdfContent(outputStream: OutputStream, reportData: List) { + val currentDate = SimpleDateFormat("dd.MM.yyyy", Locale.getDefault()).format(Date()) val pdfDocument = PdfDocument() val pageInfo = PdfDocument.PageInfo.Builder(595, 842, 1).create() @@ -107,17 +112,18 @@ class RestItemRepository( paint.isAntiAlias = true // Отображаем заголовок - val title = "Отчет" + val title = "Отчет от ${currentDate}" val xTitle = (pageInfo.pageWidth - paint.measureText(title)) / 2 val yTitle = 40f canvas.drawText(title, xTitle, yTitle, paint) + // Отображаем данные в виде таблицы - val tableStartY = yTitle + 80f + val tableStartY = yTitle + 60f val columnWidths = floatArrayOf(0.5f, 1f, 0.6f, 0.5f, 1f, 1f, 1f) // Увеличиваем ширину столбцов val rowHeight = 30f // Увеличиваем высоту строки - drawTableRow(canvas, arrayOf("ID", "Дата", "Вес", "R", "Цвет", "Кол-во", "ID велосипеда"), columnWidths, tableStartY, paint) + drawTableRow(canvas, arrayOf("ID", "Дата", "Вес", "R", "Цвет", "Кол-во", "Имя"), columnWidths, tableStartY, paint) for ((index, report) in reportData.withIndex()) { val row = arrayOf( @@ -127,7 +133,7 @@ class RestItemRepository( report.radius.toString(), report.colorbike.toString(), report.maxCount.toString(), - report.bikeId.toString() + report.bikeName.toString() ) drawTableRow(canvas, row, columnWidths, tableStartY + (index + 1) * rowHeight, paint) } diff --git a/app/src/main/java/com/example/myapplication/api/report/ReportRemote.kt b/app/src/main/java/com/example/myapplication/api/report/ReportRemote.kt index a7e2abe..f0285f8 100644 --- a/app/src/main/java/com/example/myapplication/api/report/ReportRemote.kt +++ b/app/src/main/java/com/example/myapplication/api/report/ReportRemote.kt @@ -10,5 +10,5 @@ data class ReportRemote( val radius: Double = 0.0, val colorbike: String = "", val maxCount: Int = 0, - val bikeId: Int = 0 + val bikeName: String = "" ) \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/ReportPage.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/ReportPage.kt index 35a87ea..cbb088e 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/ReportPage.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/ReportPage.kt @@ -236,7 +236,7 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view coroutineScope.launch { viewModel.generatePdfFile( context = context, - fileName = "Отчет по велосипедам.pdf", + fileName = "Отчет по велосипедам", reportData = reportResultPageState.resReport ) } @@ -294,13 +294,13 @@ fun TableScreen(reportData: List) { Text("Вес", Modifier.weight(0.7f), color = MaterialTheme.colorScheme.background) Text("R", Modifier.weight(0.6f), color = MaterialTheme.colorScheme.background) Text("Цвет", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) - Text("Кол-во", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) - Text("ID вел", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background) + Text("Кол-во", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background) + Text("Имя", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) } // Here are all the lines of your table. reportData.forEach { - val (id, dateTime, weight, radius,colorbike, maxCount, bikeId) = it + val (id, dateTime, weight, radius,colorbike, maxCount, bikeName) = it Card( modifier = Modifier .fillMaxWidth() @@ -314,8 +314,8 @@ fun TableScreen(reportData: List) { Text(weight.toString(), Modifier.weight(0.7f)) Text(radius.toString(), Modifier.weight(0.6f)) Text(colorbike.toString(), Modifier.weight(1.0f)) - Text(maxCount.toString(), Modifier.weight(1.0f)) - Text(bikeId.toString(), Modifier.weight(0.5f)) + Text(maxCount.toString(), Modifier.weight(0.5f)) + Text(bikeName.toString(), Modifier.weight(1.0f)) } } }