ajout de la fonction suppression
This commit is contained in:
8
.idea/deploymentTargetSelector.xml
generated
8
.idea/deploymentTargetSelector.xml
generated
@@ -4,6 +4,14 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DropdownSelection timestamp="2025-12-16T19:37:03.719661700Z">
|
||||||
|
<Target type="DEFAULT_BOOT">
|
||||||
|
<handle>
|
||||||
|
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\lalor\.android\avd\Pixel_9_Pro_XL.avd" />
|
||||||
|
</handle>
|
||||||
|
</Target>
|
||||||
|
</DropdownSelection>
|
||||||
|
<DialogSelection />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
57
.idea/inspectionProfiles/Project_Default.xml
generated
57
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,61 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="UsePropertyAccessSyntax" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.screen.AjoutDvdActivity"/>
|
<activity android:name=".ui.screen.AjoutDvdActivity"/>
|
||||||
<activity android:name=".ui.screen.ListDvdActivity"/>
|
<activity android:name=".ui.screen.ListDvdActivity"/>
|
||||||
|
<activity android:name=".ui.screen.SupprDvdActivity"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -21,6 +21,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.dev.collectiondvd.ui.screen.AjoutDvdActivity
|
import com.dev.collectiondvd.ui.screen.AjoutDvdActivity
|
||||||
import com.dev.collectiondvd.ui.screen.ListDvdActivity
|
import com.dev.collectiondvd.ui.screen.ListDvdActivity
|
||||||
|
import com.dev.collectiondvd.ui.screen.SupprDvdActivity
|
||||||
import com.dev.collectiondvd.ui.theme.CollectionDvdTheme
|
import com.dev.collectiondvd.ui.theme.CollectionDvdTheme
|
||||||
import com.dev.collectiondvd.ui.theme.MyButton
|
import com.dev.collectiondvd.ui.theme.MyButton
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
@@ -47,11 +48,12 @@ fun MenuScreen() {
|
|||||||
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
Text("Gestion de clients", fontSize = 28.sp)
|
Text("Gestion la collection de DVD", fontSize = 28.sp)
|
||||||
MyButton("Liste des clients") { context.startActivity(Intent(context, ListDvdActivity::class.java)) }
|
MyButton("Liste des DVDs") { context.startActivity(Intent(context, ListDvdActivity::class.java)) }
|
||||||
|
|
||||||
MyButton("Ajouter un client") { context.startActivity(Intent(context, AjoutDvdActivity::class.java)) }
|
MyButton("Ajouter un DVD") { context.startActivity(Intent(context, AjoutDvdActivity::class.java)) }
|
||||||
|
|
||||||
|
MyButton("Supprimer un DVD") { context.startActivity((Intent(context, SupprDvdActivity::class.java)))}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,4 +16,11 @@ interface DvdDao{
|
|||||||
@Query("SELECT * FROM dvds")
|
@Query("SELECT * FROM dvds")
|
||||||
fun getAllDvdsFlow(): Flow<List<Dvd>>
|
fun getAllDvdsFlow(): Flow<List<Dvd>>
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun delete(dvd: Dvd)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM dvds WHERE id = :numero")
|
||||||
|
fun getDvdById(numero: Long): Flow<Dvd?>
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,4 +10,9 @@ class LocalDvdRepository(private val dvdDao: DvdDao) {
|
|||||||
fun getAllDvds(): Flow<List<Dvd>> = dvdDao.getAllDvdsFlow()
|
fun getAllDvds(): Flow<List<Dvd>> = dvdDao.getAllDvdsFlow()
|
||||||
|
|
||||||
suspend fun addDvd(dvd: Dvd) = dvdDao.insert(dvd)
|
suspend fun addDvd(dvd: Dvd) = dvdDao.insert(dvd)
|
||||||
|
|
||||||
|
suspend fun deleteDvd(dvd: Dvd) = dvdDao.delete(dvd)
|
||||||
|
|
||||||
|
fun searchDvd(numero: Long): Flow<Dvd?> = dvdDao.getDvdById(numero)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package com.dev.collectiondvd.ui.screen
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.dev.collectiondvd.data.local.AppDatabase
|
||||||
|
import com.dev.collectiondvd.data.repository.LocalDvdRepository
|
||||||
|
import com.dev.collectiondvd.ui.theme.CollectionDvdTheme
|
||||||
|
import com.dev.collectiondvd.ui.theme.MyButton
|
||||||
|
import com.dev.collectiondvd.viewmodel.LocalDvdViewModel
|
||||||
|
import com.dev.collectiondvd.viewmodel.factory.LocalDvdViewModelFactory
|
||||||
|
|
||||||
|
class SupprDvdActivity : ComponentActivity(){
|
||||||
|
|
||||||
|
private lateinit var viewModel: LocalDvdViewModel
|
||||||
|
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val dvdDao = AppDatabase.getDatabase(this).dvdDao()
|
||||||
|
val factory = LocalDvdViewModelFactory (LocalDvdRepository (dvdDao))
|
||||||
|
viewModel = ViewModelProvider(this, factory).get(LocalDvdViewModel::class.java)
|
||||||
|
setContent {
|
||||||
|
CollectionDvdTheme {
|
||||||
|
SupprDvdScreen({ finish() }, viewModel = viewModel)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SupprDvdScreen(onQuit: () -> Unit, viewModel: LocalDvdViewModel){
|
||||||
|
val dvds by viewModel.dvds.collectAsState(initial = emptyList())
|
||||||
|
val selectDvd by viewModel.selectedDvd.collectAsState()
|
||||||
|
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
var selectedId by remember { mutableStateOf<Long?>(null) }
|
||||||
|
|
||||||
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
|
Text("TEST", modifier = Modifier.padding(8.dp))
|
||||||
|
Text("DVD count = ${dvds.size}")
|
||||||
|
|
||||||
|
|
||||||
|
TextButton(onClick = { expanded = true }) {
|
||||||
|
Text(
|
||||||
|
text = dvds.find { it.id == selectedId }?.titre ?: "Choisir un DVD"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Menu deroulant
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false }
|
||||||
|
) {
|
||||||
|
dvds.forEach { dvd ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(dvd.titre) },
|
||||||
|
onClick = {
|
||||||
|
selectedId = dvd.id
|
||||||
|
expanded = false
|
||||||
|
viewModel.selectDvd(dvd.id)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
//Affichage info dvd
|
||||||
|
selectDvd?.let { dvd ->
|
||||||
|
Text("Titre: ${dvd.titre}")
|
||||||
|
Text("Réalisateur: ${dvd.realisateur}")
|
||||||
|
Text("Année: ${dvd.annee}")
|
||||||
|
Text("Genre: ${dvd.genre}")
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
MyButton("Supprimer le Dvd")
|
||||||
|
{
|
||||||
|
viewModel.deleteDvd()
|
||||||
|
selectedId = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MyButton("Quitter") { onQuit() }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,16 +4,47 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.dev.collectiondvd.data.local.entities.Dvd
|
import com.dev.collectiondvd.data.local.entities.Dvd
|
||||||
import com.dev.collectiondvd.data.repository.LocalDvdRepository
|
import com.dev.collectiondvd.data.repository.LocalDvdRepository
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class LocalDvdViewModel (
|
class LocalDvdViewModel (
|
||||||
private val repository: LocalDvdRepository
|
private val repository: LocalDvdRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
val dvds = repository.getAllDvds()
|
val dvds: StateFlow<List<Dvd>> =
|
||||||
|
repository.getAllDvds()
|
||||||
|
.stateIn(
|
||||||
|
viewModelScope,
|
||||||
|
SharingStarted.WhileSubscribed(5_000),
|
||||||
|
emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
fun addDvd(dvd: Dvd){
|
fun addDvd(dvd: Dvd){
|
||||||
viewModelScope.launch{
|
viewModelScope.launch{
|
||||||
repository.addDvd(dvd)
|
repository.addDvd(dvd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val _selectedDvd = MutableStateFlow<Dvd?>(null)
|
||||||
|
val selectedDvd: StateFlow<Dvd?> = _selectedDvd
|
||||||
|
|
||||||
|
fun selectDvd(numero: Long) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.searchDvd(numero).collect { dvd ->
|
||||||
|
_selectedDvd.value = dvd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteDvd() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_selectedDvd.value?.let { dvd ->
|
||||||
|
repository.deleteDvd(dvd)
|
||||||
|
_selectedDvd.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user