Наизменял я дезигн конечно....
Эх, что то я так устал, вот бы много деняг просто...
This commit is contained in:
parent
c785a76e03
commit
3b1dfec3bd
@ -11,6 +11,8 @@ import android.net.Uri
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
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.Row
|
||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.Spacer
|
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.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
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.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.DatePicker
|
import androidx.compose.material3.DatePicker
|
||||||
import androidx.compose.material3.DisplayMode
|
import androidx.compose.material3.DisplayMode
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.material3.TextFieldDefaults
|
||||||
import androidx.compose.material3.rememberDatePickerState
|
import androidx.compose.material3.rememberDatePickerState
|
||||||
import androidx.compose.runtime.Composable
|
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.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
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.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.example.myapplication.R
|
import com.example.myapplication.R
|
||||||
import com.example.myapplication.api.report.ReportRemote
|
import com.example.myapplication.api.report.ReportRemote
|
||||||
|
import com.example.myapplication.composeui.navigation.Screen
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@ -57,61 +78,101 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
|
|||||||
{
|
{
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
//viewModel.getReport()
|
|
||||||
|
|
||||||
val dateStateStart = rememberDatePickerState(initialDisplayMode = DisplayMode.Input)
|
|
||||||
val dateStateEnd = rememberDatePickerState(initialDisplayMode = DisplayMode.Input)
|
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val reportResultPageState = viewModel.reportResultPageUiState
|
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(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.verticalScroll(rememberScrollState()),
|
.verticalScroll(rememberScrollState())
|
||||||
verticalArrangement = Arrangement.Center,
|
.padding(16.dp)
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
) {
|
||||||
)
|
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(
|
||||||
text = stringResource(id = R.string.startDate),
|
text = stringResource(id = R.string.startDate),
|
||||||
style = MaterialTheme.typography.headlineLarge
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
DatePicker(
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
state = dateStateStart,
|
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),
|
||||||
)
|
)
|
||||||
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)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(180.dp) // Adjust the width as needed
|
||||||
|
.fillMaxHeight()
|
||||||
|
.padding(8.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.endDate),
|
text = stringResource(id = R.string.endDate),
|
||||||
style = MaterialTheme.typography.headlineLarge
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
DatePicker(
|
BasicTextField(
|
||||||
state = dateStateEnd,
|
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),
|
||||||
)
|
)
|
||||||
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)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {coroutineScope.launch {
|
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()
|
viewModel.getReport()
|
||||||
//createPdfFile(context = context, fileName = "отчет.pdf",reportData = reportResultPageState.resReport)
|
// Show the Card with animation
|
||||||
} },
|
cardVisible = true
|
||||||
enabled = viewModel.reportPageUiState.isEntryValid,
|
} else {
|
||||||
|
// Handle parsing errors here if necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 10.dp)
|
.padding(all = 10.dp)
|
||||||
@ -121,19 +182,50 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
|
|||||||
) {
|
) {
|
||||||
Text("Сформировать отчет")
|
Text("Сформировать отчет")
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(32.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(
|
||||||
text = "Результат",
|
text = "Результат",
|
||||||
style = MaterialTheme.typography.headlineLarge
|
textAlign = TextAlign.Center,
|
||||||
|
style = TextStyle(
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
fontSize = 24.sp
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
TableScreen(reportData = reportResultPageState.resReport)
|
TableScreen(reportData = reportResultPageState.resReport)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
if (viewModel.reportPageUiState.isEntryValid) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {coroutineScope.launch {
|
onClick = {
|
||||||
//viewModel.getReport()
|
coroutineScope.launch {
|
||||||
viewModel.generatePdfFile(context = context, fileName = "отчет.pdf",reportData = reportResultPageState.resReport)
|
viewModel.generatePdfFile(
|
||||||
} },
|
context = context,
|
||||||
enabled = viewModel.reportPageUiState.isEntryValid,
|
fileName = "отчет.pdf",
|
||||||
|
reportData = reportResultPageState.resReport
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 10.dp)
|
.padding(all = 10.dp)
|
||||||
@ -144,6 +236,37 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
|
|||||||
Text("Сформировать отчет PDF")
|
Text("Сформировать отчет PDF")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
navController?.navigate(Screen.BikeList.route)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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("Выйти")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@Composable
|
||||||
@ -173,11 +296,11 @@ fun TableScreen(reportData: List<ReportRemote>) {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
Row(Modifier.background(Color.White)) {
|
Row(Modifier.background(Color.White)) {
|
||||||
TableCell(text = "ID", weight = column1Weight)
|
TableCell(text = "ID\n", weight = column1Weight)
|
||||||
TableCell(text = "Дата и время", weight = column1Weight)
|
TableCell(text = "Дата\n", weight = column1Weight)
|
||||||
TableCell(text = "Вес", weight = column1Weight)
|
TableCell(text = "Вес\n", weight = column1Weight)
|
||||||
TableCell(text = "Макс. количество", weight = column1Weight)
|
TableCell(text = "Кол-во", weight = column1Weight)
|
||||||
TableCell(text = "ID велосипеда", weight = column1Weight)
|
TableCell(text = "ID вел.", weight = column1Weight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here are all the lines of your table.
|
// Here are all the lines of your table.
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<string name="Bike_name">Название</string>
|
<string name="Bike_name">Название</string>
|
||||||
<string name="Bike_description">Описание</string>
|
<string name="Bike_description">Описание</string>
|
||||||
<string name="report">Отчет</string>
|
<string name="report">Отчет</string>
|
||||||
<string name="startDate">Дата начала</string>
|
<string name="startDate">Дата начала отчета</string>
|
||||||
<string name="endDate">Дата конца</string>
|
<string name="endDate">Дата конца отчета</string>
|
||||||
<string name="Bike_image">Изображение</string>
|
<string name="Bike_image">Изображение</string>
|
||||||
<string name="Cart_title">Подтверждение</string>
|
<string name="Cart_title">Подтверждение</string>
|
||||||
<string name="Rent_title">Аренда</string>
|
<string name="Rent_title">Аренда</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user