File tree Expand file tree Collapse file tree
src/main/java/com/mouton/openwinemer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ android {
1919 minSdk = 26
2020 targetSdk = 36
2121 versionCode = 1
22- versionName = " 1.0"
22+ versionName = " 1.0.5 "
2323
2424 testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
2525 }
Original file line number Diff line number Diff line change @@ -51,10 +51,13 @@ interface WineDao {
5151 @Query(" DELETE FROM wines" )
5252 suspend fun clearAll ()
5353
54- @Insert(onConflict = OnConflictStrategy .REPLACE )
54+ @Insert(onConflict = OnConflictStrategy .IGNORE )
5555 suspend fun insertAll (wines : List <WineEntity >)
5656
5757 @Insert(onConflict = OnConflictStrategy .REPLACE )
5858 suspend fun insertOrUpdate (wines : List <WineEntity >)
5959
60+ @Query(" SELECT MAX(id) FROM wines" )
61+ suspend fun getLastId (): Long?
62+
6063}
Original file line number Diff line number Diff line change @@ -101,10 +101,19 @@ class BackupUseCase(
101101
102102 // 4) Remplacer ou fusionner
103103 if (replace) {
104+ // 🔥 MODE REMPLACER : on efface tout et on laisse Room recréer les IDs
104105 wineDao.clearAll()
105- wineDao.insertAll(wines)
106+ val winesWithoutId = wines.map { it.copy(id = 0 ) }
107+ wineDao.insertAll(winesWithoutId)
106108 } else {
107- wineDao.insertOrUpdate(wines)
109+ // 🔥 MODE FUSIONNER : on récupère le dernier ID existant
110+ val lastId = wineDao.getLastId() ? : 0L
111+ // On renumérote les vins importés pour éviter les collisions
112+ var nextId = lastId + 1
113+ val winesWithNewIds = wines.map { wine ->
114+ wine.copy(id = nextId++ )
115+ }
116+ wineDao.insertOrUpdate(winesWithNewIds)
108117 }
109118 }
110119
You can’t perform that action at this time.
0 commit comments