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

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, startDestination = Screen.TankList.route,
) { ) {
composable(Screen.TankList.route) { TankList(navController) } 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.Hangar.route) { Hangar(navController) }
composable(Screen.Account.route) { Account(navController) } composable(Screen.Account.route) { Account(navController) }
composable( composable(

View File

@ -26,7 +26,7 @@ enum class Screen(
"register", R.string.register, showInBottomBar = false "register", R.string.register, showInBottomBar = false
), ),
Constructor( Constructor(
"constructor", R.string.constructor, Icons.Filled.Add "constructor/{id}", R.string.constructor, Icons.Filled.Add
), ),
Hangar( Hangar(
"hangar", R.string.hangar, Icons.Filled.List "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.Image
import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@ -37,6 +38,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp 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 androidx.navigation.compose.rememberNavController
import ru.ulstu.`is`.pmu.R import ru.ulstu.`is`.pmu.R
import ru.ulstu.`is`.pmu.composeui.navigation.Screen import ru.ulstu.`is`.pmu.composeui.navigation.Screen
import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel
@ -64,13 +66,23 @@ fun TankList(
val tankListUiState by viewModel.tankListUiState.collectAsState() val tankListUiState by viewModel.tankListUiState.collectAsState()
// Lazy Column, Pass the numbers array // 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 @Composable
fun ColumnItem( fun ColumnItem(
number: Int, number: Int,
tanks: List<Tank> tanks: List<Tank>,
onClick: (uid: Long) -> Unit
) { ) {
Column( Column(
modifier = Modifier.padding(0.dp, 10.dp) modifier = Modifier.padding(0.dp, 10.dp)
@ -110,6 +122,7 @@ fun ColumnItem(
modifier = Modifier modifier = Modifier
.size(width = 200.dp, height = 250.dp) .size(width = 200.dp, height = 250.dp)
.padding(all = 5.dp) .padding(all = 5.dp)
.clickable { onClick(tank.tankId!!) }
) { ) {
Image( Image(
painter = painterResource(id = tank.image), painter = painterResource(id = tank.image),
@ -133,7 +146,8 @@ fun ColumnItem(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
containerColor = CustomRed, containerColor = CustomRed,
contentColor = CustomDark), contentColor = CustomDark),
onClick = { }) { onClick = { }
) {
//navController?.navigate(Screen.Hangar.route) //navController?.navigate(Screen.Hangar.route)
//navController?.navigate(studentId) //navController?.navigate(studentId)
//"${student.firstName} ${student.lastName}" //"${student.firstName} ${student.lastName}"
@ -151,7 +165,8 @@ fun ColumnItem(
@Composable @Composable
private fun TankList( private fun TankList(
numbers: List<Int>, numbers: List<Int>,
listTanks: List<Tank> listTanks: List<Tank>,
onClick: (uid: Long) -> Unit,
) { ) {
LazyColumn( LazyColumn(
@ -174,7 +189,7 @@ private fun TankList(
// current list/array item in the lazyItemScope // current list/array item in the lazyItemScope
// тут как раз и выводим 3 раза все танки по нациям // тут как раз и выводим 3 раза все танки по нациям
items(numbers) {arrayItem-> items(numbers) {arrayItem->
ColumnItem(number = arrayItem, tanks = listTanks) ColumnItem(number = arrayItem, tanks = listTanks, onClick = onClick)
} }
// items(list/array) places number of // items(list/array) places number of
@ -197,7 +212,8 @@ fun TankListPreview() {
) { ) {
TankList( TankList(
numbers = listOf(1, 2, 3), numbers = listOf(1, 2, 3),
listTanks = listOf() listTanks = (1..20).map { i -> Tank.getTank(i.toLong()) },
onClick = { }
) )
} }
} }
@ -213,7 +229,8 @@ fun TankEmptyListPreview() {
) { ) {
TankList( TankList(
numbers = listOf(1, 2, 3), 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 kotlinx.coroutines.launch
import ru.ulstu.`is`.pmu.tank.model.Tank import ru.ulstu.`is`.pmu.tank.model.Tank
import ru.ulstu.`is`.pmu.tank.repository.TankRepository import ru.ulstu.`is`.pmu.tank.repository.TankRepository
import kotlin.math.tan
class TankEditViewModel( class TankEditViewModel(
savedStateHandle: SavedStateHandle, savedStateHandle: SavedStateHandle,

View File

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

View File

@ -14,12 +14,12 @@ import ru.ulstu.`is`.pmu.tank.model.NationWithTanks
@Dao @Dao
interface NationDao { interface NationDao {
@Query("select * from nations") @Query("select * from nations")
fun getAll(): List<Nation> suspend fun getAll(): List<Nation>
//получить нации с танками //получить нации с танками
@Transaction @Transaction
@Query("SELECT * FROM nations") @Query("SELECT * FROM nations")
fun getNationsWithTanks(): List<NationWithTanks> suspend fun getNationsWithTanks(): List<NationWithTanks>
//получить конкретную нацию //получить конкретную нацию
@Query("select * from nations where nations.uid = :uid") @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.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@ -106,16 +107,16 @@ private fun Constructor(
onClick: () -> Unit, onClick: () -> Unit,
onUpdate: (TankDetails) -> Unit onUpdate: (TankDetails) -> Unit
) { ) {
var nationName by remember { mutableStateOf("") } var tankName by remember { mutableStateOf(tankUiState.tankDetails.name) }
var price by remember { mutableStateOf("") } var price by remember { mutableStateOf(tankUiState.tankDetails.price.toString()) }
//для работы выпадающего списка уровней //для работы выпадающего списка уровней
var expandedLevels by remember { mutableStateOf(false) } 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 expandedNation by remember { mutableStateOf(false) }
var selectedNation by remember { mutableStateOf(getNations()[0].nationName) } var selectedNation by remember { mutableStateOf("СССР") }
Column( Column(
verticalArrangement = Arrangement.spacedBy(35.dp), verticalArrangement = Arrangement.spacedBy(35.dp),
@ -152,7 +153,7 @@ private fun Constructor(
} }
Column { Column {
TextField( TextField(
value = nationName, value = tankName,
placeholder = { Text(text = "Название", color = CustomDark) }, placeholder = { Text(text = "Название", color = CustomDark) },
onValueChange = { onUpdate(tankUiState.tankDetails.copy(name = it)) }, onValueChange = { onUpdate(tankUiState.tankDetails.copy(name = it)) },
modifier = Modifier modifier = Modifier
@ -187,7 +188,7 @@ private fun Constructor(
}, },
) { ) {
// menu items // menu items
getLevels().forEach { selectionOption -> levelsListUiState.levelList.forEach { selectionOption ->
DropdownMenuItem( DropdownMenuItem(
text = { Text(selectionOption.level.toString()) }, text = { Text(selectionOption.level.toString()) },
onClick = { onClick = {
@ -229,7 +230,7 @@ private fun Constructor(
}, },
) { ) {
// menu items // menu items
getNations().forEach { selectionOption -> nationsListUiState.nationList.forEach { selectionOption ->
DropdownMenuItem( DropdownMenuItem(
text = { Text(selectionOption.nationName) }, text = { Text(selectionOption.nationName) },
onClick = { onClick = {
@ -393,7 +394,6 @@ fun ConstructorEditPreview() {
Surface( Surface(
color = CustomDark color = CustomDark
) { ) {
val navController = rememberNavController()
Constructor( Constructor(
tankUiState = Tank.getTank().toUiState(true), tankUiState = Tank.getTank().toUiState(true),
levelUiState = Level.DEMO_LEVEL.toUiState(), 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.TankApplication
import ru.ulstu.`is`.pmu.tank.composeui.edit.LevelDropDownViewModel 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.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.edit.UserEditViewModel
import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel
@ -16,7 +17,12 @@ object AppViewModelProvider {
initializer { initializer {
TankListViewModel(tankApplication().container.tankRepository) TankListViewModel(tankApplication().container.tankRepository)
} }
initializer {
TankEditViewModel(
this.createSavedStateHandle(),
tankApplication().container.tankRepository
)
}
initializer { initializer {
UserEditViewModel( UserEditViewModel(
this.createSavedStateHandle(), this.createSavedStateHandle(),