Наизменял я дезигн конечно....

Эх, что то я так устал, вот бы много деняг просто...
This commit is contained in:
Кашин Максим 2023-12-26 01:12:04 +04:00
parent c785a76e03
commit 3b1dfec3bd
2 changed files with 189 additions and 66 deletions

View File

@ -11,6 +11,8 @@ import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
@ -18,38 +20,57 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DisplayMode
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.example.myapplication.R
import com.example.myapplication.api.report.ReportRemote
import com.example.myapplication.composeui.navigation.Screen
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.IOException
import java.io.OutputStream
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@ -57,61 +78,101 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
{
val context = LocalContext.current
//viewModel.getReport()
val dateStateStart = rememberDatePickerState(initialDisplayMode = DisplayMode.Input)
val dateStateEnd = rememberDatePickerState(initialDisplayMode = DisplayMode.Input)
val coroutineScope = rememberCoroutineScope()
val reportResultPageState = viewModel.reportResultPageUiState
val startDateText = remember { mutableStateOf("") }
val endDateText = remember { mutableStateOf("") }
// Boolean state to track the visibility of the Card
var cardVisible by remember { mutableStateOf(false) }
Column(
modifier = Modifier
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
)
{
Text(
text = stringResource(id = R.string.startDate),
style = MaterialTheme.typography.headlineLarge
)
DatePicker(
state = dateStateStart,
)
val selectedDateStart = dateStateStart.selectedDateMillis
if (selectedDateStart != null) {
val resultDate= Date(selectedDateStart)
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(startDate = resultDate))
}
else
{
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(startDate = Date(0)))
}
Text(
text = stringResource(id = R.string.endDate),
style = MaterialTheme.typography.headlineLarge
)
.verticalScroll(rememberScrollState())
.padding(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(
modifier = Modifier
.width(180.dp) // Adjust the width as needed
.fillMaxHeight()
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(id = R.string.startDate),
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(8.dp))
BasicTextField(
value = startDateText.value,
onValueChange = { startDateText.value = it },
modifier = Modifier
.fillMaxWidth()
.size(36.dp)
.background(
MaterialTheme.colorScheme.onBackground,
RoundedCornerShape(18.dp)
)
.padding(start = 13.dp, top = 8.dp),
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
)
}
DatePicker(
state = dateStateEnd,
)
val selectedDateEnd = dateStateEnd.selectedDateMillis
if (selectedDateEnd != null) {
val resultDate = Date(selectedDateEnd)
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(endDate = resultDate))
}
else
{
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(endDate = Date(0)))
Column(
modifier = Modifier
.width(180.dp) // Adjust the width as needed
.fillMaxHeight()
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(id = R.string.endDate),
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(8.dp))
BasicTextField(
value = endDateText.value,
onValueChange = { endDateText.value = it },
modifier = Modifier
.fillMaxWidth()
.size(36.dp)
.background(
MaterialTheme.colorScheme.onBackground,
RoundedCornerShape(18.dp)
)
.padding(start = 13.dp, top = 8.dp),
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
)
}
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {coroutineScope.launch {
viewModel.getReport()
//createPdfFile(context = context, fileName = "отчет.pdf",reportData = reportResultPageState.resReport)
} },
enabled = viewModel.reportPageUiState.isEntryValid,
onClick = {
coroutineScope.launch {
val startDate = parseDate(startDateText.value)
val endDate = parseDate(endDateText.value)
if (startDate != null && endDate != null) {
viewModel.onUpdate(
viewModel.reportPageUiState.reportDetails.copy(startDate = startDate, endDate = endDate)
)
viewModel.getReport()
// Show the Card with animation
cardVisible = true
} else {
// Handle parsing errors here if necessary
}
}
},
modifier = Modifier
.fillMaxWidth()
.padding(all = 10.dp)
@ -121,19 +182,70 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
) {
Text("Сформировать отчет")
}
Spacer(modifier = Modifier.height(32.dp))
Text(
text = "Результат",
style = MaterialTheme.typography.headlineLarge
)
TableScreen(reportData = reportResultPageState.resReport)
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(8.dp))
// Use AnimatedVisibility to animate the Card visibility
AnimatedVisibility(visible = cardVisible) {
Card(
border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground),
modifier = Modifier
.background(MaterialTheme.colorScheme.background)
.fillMaxWidth()
.padding(8.dp)
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.padding(8.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Результат",
textAlign = TextAlign.Center,
style = TextStyle(
color = MaterialTheme.colorScheme.onSurface,
fontSize = 24.sp
)
)
TableScreen(reportData = reportResultPageState.resReport)
Spacer(modifier = Modifier.height(16.dp))
if (viewModel.reportPageUiState.isEntryValid) {
Button(
onClick = {
coroutineScope.launch {
viewModel.generatePdfFile(
context = context,
fileName = "отчет.pdf",
reportData = reportResultPageState.resReport
)
}
},
modifier = Modifier
.fillMaxWidth()
.padding(all = 10.dp)
.border(4.dp, MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(10.dp)),
shape = RoundedCornerShape(10.dp),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary)
) {
Text("Сформировать отчет PDF")
}
}
}
}
}
Button(
onClick = {coroutineScope.launch {
//viewModel.getReport()
viewModel.generatePdfFile(context = context, fileName = "отчет.pdf",reportData = reportResultPageState.resReport)
} },
enabled = viewModel.reportPageUiState.isEntryValid,
onClick = {
coroutineScope.launch {
navController?.navigate(Screen.BikeList.route)
}
},
modifier = Modifier
.fillMaxWidth()
.padding(all = 10.dp)
@ -141,11 +253,22 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
shape = RoundedCornerShape(10.dp),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary)
) {
Text("Сформировать отчет PDF")
Text("Выйти")
}
}
}
private fun parseDate(dateString: String): Date? {
return try {
// Use SimpleDateFormat or any other method to parse the string into a Date object
// For example:
SimpleDateFormat("yyyy", Locale.getDefault()).parse(dateString)
} catch (e: ParseException) {
// Handle parsing error
null
}
}
@Composable
fun RowScope.TableCell(
text: String,
@ -173,11 +296,11 @@ fun TableScreen(reportData: List<ReportRemote>) {
) {
Row(Modifier.background(Color.White)) {
TableCell(text = "ID", weight = column1Weight)
TableCell(text = "Дата и время", weight = column1Weight)
TableCell(text = "Вес", weight = column1Weight)
TableCell(text = "Макс. количество", weight = column1Weight)
TableCell(text = "ID велосипеда", weight = column1Weight)
TableCell(text = "ID\n", weight = column1Weight)
TableCell(text = "Дата\n", weight = column1Weight)
TableCell(text = "Вес\n", weight = column1Weight)
TableCell(text = "Кол-во", weight = column1Weight)
TableCell(text = "ID вел.", weight = column1Weight)
}
// Here are all the lines of your table.

View File

@ -7,8 +7,8 @@
<string name="Bike_name">Название</string>
<string name="Bike_description">Описание</string>
<string name="report">Отчет</string>
<string name="startDate">Дата начала</string>
<string name="endDate">Дата конца</string>
<string name="startDate">Дата начала отчета</string>
<string name="endDate">Дата конца отчета</string>
<string name="Bike_image">Изображение</string>
<string name="Cart_title">Подтверждение</string>
<string name="Rent_title">Аренда</string>