It's working!!!
This commit is contained in:
parent
8f116e2005
commit
b0fbd2704f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -40,6 +40,10 @@ class TankEditViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun getTankId(): Long{
|
||||
return tankUid;
|
||||
}
|
||||
|
||||
fun updateUiState(tankDetails: TankDetails) {
|
||||
tankUiState = TankUiState(
|
||||
tankDetails = tankDetails,
|
||||
@ -58,6 +62,14 @@ class TankEditViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteTank() {
|
||||
if (validateInput()) {
|
||||
if (tankUid > 0) {
|
||||
tankRepository.deleteTank(tankUiState.tankDetails.toTank(tankUid))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateInput(uiState: TankDetails = tankUiState.tankDetails): Boolean {
|
||||
return with(uiState) {
|
||||
name.isNotBlank()
|
||||
|
@ -34,7 +34,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun tankImageDao() : TankImageDao
|
||||
|
||||
companion object {
|
||||
private const val DB_NAME: String = "18-db"
|
||||
private const val DB_NAME: String = "19-db"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
|
@ -42,6 +42,7 @@ 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.getEmptyBitmap
|
||||
import com.application.ui.miniatureBound
|
||||
import com.application.ui.resize
|
||||
import com.application.ui.tankImageBound
|
||||
@ -76,10 +77,13 @@ fun Constructor(
|
||||
){
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val tankId = tankEditViewModel.getTankId()
|
||||
|
||||
levelDropDownViewModel.setCurrentLevel(tankEditViewModel.tankUiState.tankDetails.levelId ?: 1)
|
||||
nationDropDownViewModel.setCurrentNation(tankEditViewModel.tankUiState.tankDetails.nationId ?: 1)
|
||||
|
||||
Constructor(
|
||||
tankId = tankId,
|
||||
tankViewModel = tankEditViewModel,
|
||||
tankUiState = tankEditViewModel.tankUiState,
|
||||
levelUiState = levelDropDownViewModel.levelUiState,
|
||||
@ -88,12 +92,18 @@ fun Constructor(
|
||||
nationUiState = nationDropDownViewModel.nationUiState,
|
||||
nationsListUiState = nationDropDownViewModel.nationsListUiState,
|
||||
onNationUpdate = nationDropDownViewModel::updateUiState,
|
||||
onClick = {
|
||||
onClickSave = {
|
||||
coroutineScope.launch {
|
||||
tankEditViewModel.saveTank()
|
||||
navController.popBackStack()
|
||||
}
|
||||
},
|
||||
onClickDelete = {
|
||||
coroutineScope.launch {
|
||||
tankEditViewModel.deleteTank()
|
||||
navController.popBackStack()
|
||||
}
|
||||
},
|
||||
onUpdate = tankEditViewModel::updateUiState
|
||||
)
|
||||
}
|
||||
@ -200,6 +210,7 @@ private fun NationDropDown(
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun Constructor(
|
||||
tankId: Long,
|
||||
tankViewModel: TankEditViewModel,
|
||||
tankUiState: TankUiState,
|
||||
levelUiState: LevelUiState,
|
||||
@ -208,7 +219,8 @@ private fun Constructor(
|
||||
nationUiState: NationUiState,
|
||||
nationsListUiState: NationsListUiState,
|
||||
onNationUpdate: (Nation) -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onClickSave: () -> Unit,
|
||||
onClickDelete: () -> Unit,
|
||||
onUpdate: (TankDetails) -> Unit
|
||||
) {
|
||||
fun handleImageUpload(bitmap: Bitmap) {
|
||||
@ -344,7 +356,7 @@ private fun Constructor(
|
||||
}
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp, 10.dp)
|
||||
@ -358,11 +370,27 @@ private fun Constructor(
|
||||
contentColor = Color.Black
|
||||
),
|
||||
enabled = tankUiState.isEntryValid,
|
||||
onClick = onClick
|
||||
onClick = onClickSave
|
||||
) {
|
||||
//"${student.firstName} ${student.lastName}"
|
||||
Text(text = stringResource(id = R.string.save_account_button), fontSize = 20.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
if(tankId != 0L){
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.width(200.dp)
|
||||
.height(50.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = CustomOrange,
|
||||
contentColor = Color.Black
|
||||
),
|
||||
enabled = tankUiState.isEntryValid,
|
||||
onClick = onClickDelete
|
||||
) {
|
||||
//"${student.firstName} ${student.lastName}"
|
||||
Text(text = stringResource(id = R.string.delete_account_button), fontSize = 20.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -467,7 +495,7 @@ private fun Constructor(
|
||||
containerColor = CustomOrange,
|
||||
contentColor = Color.Black
|
||||
),
|
||||
onClick = onClick
|
||||
onClick = onClickSave
|
||||
) {
|
||||
//"${student.firstName} ${student.lastName}"
|
||||
Text(text = stringResource(id = R.string.create_account_button), fontSize = 20.sp, fontWeight = FontWeight.Bold)
|
||||
@ -488,6 +516,7 @@ fun ConstructorEditPreview() {
|
||||
color = CustomDark
|
||||
) {
|
||||
Constructor(
|
||||
tankId = 0L,
|
||||
tankViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
||||
tankUiState = Tank.getTank().toUiState(true),
|
||||
levelUiState = Level.DEMO_LEVEL.toUiState(),
|
||||
@ -496,7 +525,8 @@ fun ConstructorEditPreview() {
|
||||
nationUiState = Nation.DEMO_NATION.toUiState(),
|
||||
nationsListUiState = NationsListUiState(listOf()),
|
||||
onNationUpdate = { },
|
||||
onClick = { },
|
||||
onClickSave = { },
|
||||
onClickDelete = { },
|
||||
onUpdate = { },
|
||||
)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="login_button">Войти</string>
|
||||
<string name="create_account_button">Создать</string>
|
||||
<string name="save_account_button">Сохранить</string>
|
||||
<string name="delete_account_button">Удалить</string>
|
||||
<string name="register_button">Регистрация</string>
|
||||
<string name="student_firstname">Имя</string>
|
||||
<string name="student_lastname">Фамилия</string>
|
||||
|
Loading…
Reference in New Issue
Block a user