This commit is contained in:
ElEgEv 2023-12-24 22:27:25 +04:00
parent 0db26bb7a2
commit e0575621c4
11 changed files with 165 additions and 52 deletions

Binary file not shown.

View File

@ -52,7 +52,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun remoteKeysDao(): RemoteKeysDao
companion object {
private const val DB_NAME: String = "24-db"
private const val DB_NAME: String = "25-db"
@Volatile
private var INSTANCE: AppDatabase? = null

View File

@ -1,19 +1,26 @@
package ru.ulstu.`is`.pmu.tanks.composeui
import android.widget.TableRow
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
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.defaultMinSize
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.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DisplayMode
import androidx.compose.material3.ExperimentalMaterial3Api
@ -27,10 +34,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.application.ui.toBitmap
@ -40,7 +49,9 @@ import ru.ulstu.`is`.pmu.tank.composeui.ApiStatus
import ru.ulstu.`is`.pmu.tank.composeui.edit.ReportViewModel
import ru.ulstu.`is`.pmu.tank.model.Report
import ru.ulstu.`is`.pmu.tanks.composeui.image.CuteImage
import ru.ulstu.`is`.pmu.tanks.composeui.image.RoundedCorderImage
import ru.ulstu.`is`.pmu.ui.AppViewModelProvider
import ru.ulstu.`is`.pmu.ui.theme.CustomDark
import ru.ulstu.`is`.pmu.ui.theme.CustomRed
import ru.ulstu.`is`.pmu.ui.theme.CustomYellow
import java.util.Date
@ -56,6 +67,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
val coroutineScope = rememberCoroutineScope()
val reportResultPageState = viewModel.reportResultPageUiState
Column(
modifier = Modifier.background(CustomYellow),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
)
@ -67,6 +79,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
DatePicker(
state = dateStateStart,
)
val selectedDateStart = dateStateStart.selectedDateMillis
if (selectedDateStart != null) {
val resultDate= Date(selectedDateStart)
@ -76,6 +89,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
{
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(startDate = Date(0)))
}
Text(
text = "Конец периода",
style = MaterialTheme.typography.headlineLarge
@ -83,6 +97,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
DatePicker(
state = dateStateEnd,
)
val selectedDateEnd = dateStateEnd.selectedDateMillis
if (selectedDateEnd != null) {
val resultDate = Date(selectedDateEnd)
@ -92,6 +107,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
{
viewModel.onUpdate(viewModel.reportPageUiState.reportDetails.copy(endDate = Date(0)))
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {coroutineScope.launch { viewModel.getReport() } },
@ -112,6 +128,7 @@ fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel
text = "Результат",
style = MaterialTheme.typography.headlineLarge
)
if(reportResultPageState.resReport != null){
TableScreen(reportData = reportResultPageState.resReport!!)
}
@ -172,60 +189,156 @@ fun ErrorPlaceholder(message: String, onBack: () -> Unit) {
}
}
@Composable
fun RowScope.TableCell(
text: String,
weight: Float
) {
Text(
text = text,
Modifier
.border(1.dp, Color.Black)
.weight(weight)
.padding(8.dp)
)
}
@Composable
fun TableScreen(reportData: Report) {
val column1Weight = .3f // 30%
Column(
Modifier
.padding(16.dp)) {
Row(Modifier.background(Color.Gray)) {
TableCell(text = "Название танка:", weight = column1Weight)
TableCell(text = "Стоимость танка:", weight = column1Weight)
//TableCell(text = "Изображение:", weight = column1Weight)
TableCell(text = "Уровень:", weight = column1Weight)
TableCell(text = "Нация:", weight = column1Weight)
TableCell(text = "Кол-во покупок:", weight = column1Weight)
TableCell(text = "Самый популярный уровень:", weight = column1Weight)
TableCell(text = "Кол-во покупок:", weight = column1Weight)
TableCell(text = "Самая популярная нация:", weight = column1Weight)
TableCell(text = "Кол-во покупок:", weight = column1Weight)
Row(
Modifier
.background(CustomDark)
.padding(10.dp, 10.dp, 10.dp, 10.dp)) {
Card(
colors = CardDefaults.cardColors(
containerColor = CustomYellow,
),
modifier = Modifier
.padding(10.dp, 10.dp, 10.dp, 10.dp),
) {
Column {
Text(
text = "Самый популярный танк:",
fontSize = 30.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
RoundedCorderImage(
imageBitmap = reportData.miniature.asImageBitmap(),
modifier = Modifier.fillMaxWidth().fillMaxHeight()
)
Spacer(modifier = Modifier.height(10.dp))
Text(
text = reportData.tankName,
fontSize = 30.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
text = "Нация: " + reportData.tankNation,
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
text = "Уровень: " + reportData.tankLevel.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
text = "Стоимость: " + reportData.price.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
text = "Покупок за период: " + reportData.countTankPurchase.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
}
}
}
Spacer(modifier = Modifier.height(10.dp))
Row(
Modifier
.background(CustomDark)
.padding(10.dp, 10.dp, 10.dp, 10.dp),
verticalAlignment = Alignment.CenterVertically
)
{
Card(
colors = CardDefaults.cardColors(
containerColor = CustomYellow,
),
modifier = Modifier
.fillMaxSize()
.padding(10.dp, 10.dp, 10.dp, 10.dp),
) {
Column(
modifier = Modifier.fillMaxHeight()
.padding(10.dp, 10.dp, 10.dp, 10.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Самый популярный уровень: " + reportData.level.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center
)
Text(
text = "Покупок за период: " + reportData.countLevelPurchase.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center
)
}
}
}
Spacer(modifier = Modifier.height(10.dp))
Row(
Modifier
.background(CustomDark)
.padding(10.dp, 10.dp, 10.dp, 10.dp),
) {
Card(
colors = CardDefaults.cardColors(
containerColor = CustomYellow,
),
modifier = Modifier
.fillMaxSize()
.padding(10.dp, 10.dp, 10.dp, 10.dp),
// Here are all the lines of your table.
Row(Modifier.fillMaxWidth()) {
TableCell(text = reportData.tankName, weight = column1Weight)
TableCell(text = reportData.price.toString(), weight = column1Weight)
CuteImage(
imageBitmap = reportData.miniature.asImageBitmap(),
modifier = Modifier.fillMaxWidth()
)
TableCell(text = reportData.tankLevel.toString(), weight = column1Weight)
TableCell(text = reportData.tankNation, weight = column1Weight)
TableCell(text = reportData.countTankPurchase.toString(), weight = column1Weight)
TableCell(text = reportData.level.toString(), weight = column1Weight)
TableCell(text = reportData.countLevelPurchase.toString(), weight = column1Weight)
TableCell(text = reportData.nationName, weight = column1Weight)
TableCell(text = reportData.countNationPurchase.toString(), weight = column1Weight)
) {
Column(
modifier = Modifier.fillMaxHeight()
.padding(10.dp, 10.dp, 10.dp, 10.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = "Самая популярная нация: " + reportData.nationName,
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center
)
Text(
text = "Покупок за период: " + reportData.countNationPurchase.toString(),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Black,
textAlign = TextAlign.Center
)
}
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -37,7 +37,7 @@ module.exports = (req, res, next) => {
//нашли самый популярный танк
const supportTank = data.tanks.find(tank => tank.id === tankList[0].tankId);
const supportLevel = data.levels.find(level => level.id === supportTank.levelId).level;
const supportNation = data.nations.find(nation => nation.id === supportTank.levelId).nationName;
const supportNation = data.nations.find(nation => nation.id === supportTank.nationId).nationName;
const popularTank = {
id: supportTank.id,