Определённые продвижения

This commit is contained in:
ElEgEv 2023-11-28 10:17:11 +04:00
parent ba4be87c09
commit 0f2db13184
8 changed files with 49 additions and 22 deletions

View File

@ -142,7 +142,10 @@ fun Navhost(
startDestination = Screen.TankList.route,
) {
composable(Screen.TankList.route) { TankList(navController) }
composable(Screen.Constructor.route) { Constructor(navController) }
composable(
Screen.Constructor.route,
arguments = listOf(navArgument("id") { type = NavType.LongType })
) { Constructor(navController) }
composable(Screen.Hangar.route) { Hangar(navController) }
composable(Screen.Account.route) { Account(navController) }
composable(

View File

@ -26,7 +26,7 @@ enum class Screen(
"register", R.string.register, showInBottomBar = false
),
Constructor(
"constructor", R.string.constructor, Icons.Filled.Add
"constructor/{id}", R.string.constructor, Icons.Filled.Add
),
Hangar(
"hangar", R.string.hangar, Icons.Filled.List

View File

@ -4,6 +4,7 @@ import android.content.res.Configuration
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -37,6 +38,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import ru.ulstu.`is`.pmu.R
import ru.ulstu.`is`.pmu.composeui.navigation.Screen
import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel
@ -64,13 +66,23 @@ fun TankList(
val tankListUiState by viewModel.tankListUiState.collectAsState()
// Lazy Column, Pass the numbers array
TankList(numbers = listIds, listTanks = tankListUiState.tankList)
if (navController != null) {
TankList(
numbers = listIds,
listTanks = tankListUiState.tankList,
onClick = { uid: Long ->
val route = Screen.Constructor.route.replace("{id}", uid.toString())
navController.navigate(route)
}
)
}
}
@Composable
fun ColumnItem(
number: Int,
tanks: List<Tank>
tanks: List<Tank>,
onClick: (uid: Long) -> Unit
) {
Column(
modifier = Modifier.padding(0.dp, 10.dp)
@ -110,6 +122,7 @@ fun ColumnItem(
modifier = Modifier
.size(width = 200.dp, height = 250.dp)
.padding(all = 5.dp)
.clickable { onClick(tank.tankId!!) }
) {
Image(
painter = painterResource(id = tank.image),
@ -133,7 +146,8 @@ fun ColumnItem(
colors = ButtonDefaults.buttonColors(
containerColor = CustomRed,
contentColor = CustomDark),
onClick = { }) {
onClick = { }
) {
//navController?.navigate(Screen.Hangar.route)
//navController?.navigate(studentId)
//"${student.firstName} ${student.lastName}"
@ -151,7 +165,8 @@ fun ColumnItem(
@Composable
private fun TankList(
numbers: List<Int>,
listTanks: List<Tank>
listTanks: List<Tank>,
onClick: (uid: Long) -> Unit,
) {
LazyColumn(
@ -174,7 +189,7 @@ private fun TankList(
// current list/array item in the lazyItemScope
// тут как раз и выводим 3 раза все танки по нациям
items(numbers) {arrayItem->
ColumnItem(number = arrayItem, tanks = listTanks)
ColumnItem(number = arrayItem, tanks = listTanks, onClick = onClick)
}
// items(list/array) places number of
@ -197,7 +212,8 @@ fun TankListPreview() {
) {
TankList(
numbers = listOf(1, 2, 3),
listTanks = listOf()
listTanks = (1..20).map { i -> Tank.getTank(i.toLong()) },
onClick = { }
)
}
}
@ -213,7 +229,8 @@ fun TankEmptyListPreview() {
) {
TankList(
numbers = listOf(1, 2, 3),
listTanks = listOf()
listTanks = listOf(),
onClick = { }
)
}
}

View File

@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import ru.ulstu.`is`.pmu.tank.model.Tank
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
import kotlin.math.tan
class TankEditViewModel(
savedStateHandle: SavedStateHandle,

View File

@ -15,12 +15,12 @@ import ru.ulstu.`is`.pmu.tank.model.User
@Dao
interface LevelDao {
@Query("select * from levels")
fun getAll(): List<Level>
suspend fun getAll(): List<Level>
//получить уровни с танками
@Transaction
@Query("SELECT * FROM levels")
fun getLevelsWithTanks(): List<LevelWithTanks>
suspend fun getLevelsWithTanks(): List<LevelWithTanks>
//получить конкретный уровень
@Query("select * from levels where levels.uid = :uid")

View File

@ -14,12 +14,12 @@ import ru.ulstu.`is`.pmu.tank.model.NationWithTanks
@Dao
interface NationDao {
@Query("select * from nations")
fun getAll(): List<Nation>
suspend fun getAll(): List<Nation>
//получить нации с танками
@Transaction
@Query("SELECT * FROM nations")
fun getNationsWithTanks(): List<NationWithTanks>
suspend fun getNationsWithTanks(): List<NationWithTanks>
//получить конкретную нацию
@Query("select * from nations where nations.uid = :uid")

View File

@ -21,6 +21,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -106,16 +107,16 @@ private fun Constructor(
onClick: () -> Unit,
onUpdate: (TankDetails) -> Unit
) {
var nationName by remember { mutableStateOf("") }
var price by remember { mutableStateOf("") }
var tankName by remember { mutableStateOf(tankUiState.tankDetails.name) }
var price by remember { mutableStateOf(tankUiState.tankDetails.price.toString()) }
//для работы выпадающего списка уровней
var expandedLevels by remember { mutableStateOf(false) }
var selectedLevel by remember { mutableStateOf(getLevels()[0].level) }
var selectedLevel by remember { mutableIntStateOf(1) }
//для работы выпадающего списка наций
var expandedNation by remember { mutableStateOf(false) }
var selectedNation by remember { mutableStateOf(getNations()[0].nationName) }
var selectedNation by remember { mutableStateOf("СССР") }
Column(
verticalArrangement = Arrangement.spacedBy(35.dp),
@ -152,7 +153,7 @@ private fun Constructor(
}
Column {
TextField(
value = nationName,
value = tankName,
placeholder = { Text(text = "Название", color = CustomDark) },
onValueChange = { onUpdate(tankUiState.tankDetails.copy(name = it)) },
modifier = Modifier
@ -187,7 +188,7 @@ private fun Constructor(
},
) {
// menu items
getLevels().forEach { selectionOption ->
levelsListUiState.levelList.forEach { selectionOption ->
DropdownMenuItem(
text = { Text(selectionOption.level.toString()) },
onClick = {
@ -229,7 +230,7 @@ private fun Constructor(
},
) {
// menu items
getNations().forEach { selectionOption ->
nationsListUiState.nationList.forEach { selectionOption ->
DropdownMenuItem(
text = { Text(selectionOption.nationName) },
onClick = {
@ -393,7 +394,6 @@ fun ConstructorEditPreview() {
Surface(
color = CustomDark
) {
val navController = rememberNavController()
Constructor(
tankUiState = Tank.getTank().toUiState(true),
levelUiState = Level.DEMO_LEVEL.toUiState(),

View File

@ -8,6 +8,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory
import ru.ulstu.`is`.pmu.TankApplication
import ru.ulstu.`is`.pmu.tank.composeui.edit.LevelDropDownViewModel
import ru.ulstu.`is`.pmu.tank.composeui.edit.NationDropDownViewModel
import ru.ulstu.`is`.pmu.tank.composeui.edit.TankEditViewModel
import ru.ulstu.`is`.pmu.tank.composeui.edit.UserEditViewModel
import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel
@ -16,7 +17,12 @@ object AppViewModelProvider {
initializer {
TankListViewModel(tankApplication().container.tankRepository)
}
initializer {
TankEditViewModel(
this.createSavedStateHandle(),
tankApplication().container.tankRepository
)
}
initializer {
UserEditViewModel(
this.createSavedStateHandle(),