From 7a7b483ac289d4962fc4601b14e1d209a9dd222d Mon Sep 17 00:00:00 2001 From: Fawkes100 Date: Mon, 6 Jan 2025 21:11:09 +0100 Subject: [PATCH] Store Song Creation Response --- .../core/notevault/data/MusicNoteDAO.java | 20 +++++++----------- .../synchronisation/songs/SongSyncWorker.java | 8 ++++++- music_database | Bin 36864 -> 0 bytes 3 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 music_database diff --git a/app/src/main/java/core/notevault/data/MusicNoteDAO.java b/app/src/main/java/core/notevault/data/MusicNoteDAO.java index c58e171..470f7d8 100644 --- a/app/src/main/java/core/notevault/data/MusicNoteDAO.java +++ b/app/src/main/java/core/notevault/data/MusicNoteDAO.java @@ -3,6 +3,7 @@ package core.notevault.data; import androidx.room.*; import core.notevault.data.sync.SyncResponse; import core.notevault.data.sync.SyncStatus; +import core.notevault.sync.synchronisation.songs.creation.SongCreationResponse; import java.time.LocalDateTime; import java.util.List; @@ -52,18 +53,13 @@ public interface MusicNoteDAO { @Query("DELETE FROM concert_songs WHERE concertID = :concertID AND musicNoteID = :songID") void deleteConcertSong(long songID, int concertID); - @Query("UPDATE concerts SET serverSpecificConcertID = :serverUUID WHERE id = :concertID") @Transaction - void updateConcertServerUUID(String serverUUID, int concertID); + default void storeSongSyncResponses(List songCreationResponses) { + for (SongCreationResponse response : songCreationResponses) { + storeSongSyncResponse(response.getLocalID(), SyncStatus.SYNCED, response.getServerID()); + } + } - // Methode für das batchweise Update der Konzert-ServerUUIDs - @Query("DELETE FROM concerts WHERE serverSpecificConcertID IN (:serverSpecificIDs)") - void deleteConcerts(List serverSpecificIDs); - - @Insert - @Transaction - void insertSyncResponses(List syncResponses); - - @Query("SELECT MAX(lastModified) FROM concerts") - LocalDateTime getLatestSyncTimestamp(); + @Query("UPDATE music_notes SET syncStatus = :status, serverID = :serverID WHERE musicNoteId = :localID") + void storeSongSyncResponse(long localID, SyncStatus status, String serverID); } diff --git a/app/src/main/java/core/notevault/sync/synchronisation/songs/SongSyncWorker.java b/app/src/main/java/core/notevault/sync/synchronisation/songs/SongSyncWorker.java index 65014fc..2327a07 100644 --- a/app/src/main/java/core/notevault/sync/synchronisation/songs/SongSyncWorker.java +++ b/app/src/main/java/core/notevault/sync/synchronisation/songs/SongSyncWorker.java @@ -1,6 +1,7 @@ package core.notevault.sync.synchronisation.songs; import android.content.Context; +import android.os.AsyncTask; import android.widget.Toast; import core.notevault.data.MusicNote; import core.notevault.data.MusicNoteDAO; @@ -15,11 +16,14 @@ import retrofit2.Response; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class SongSyncWorker { private SyncService syncService; private MusicNoteDAO database; private Context context; + private ExecutorService executorService = Executors.newSingleThreadExecutor(); public SongSyncWorker(SyncService syncService, MusicNoteDAO database, Context context) { this.syncService = syncService; @@ -42,7 +46,9 @@ public class SongSyncWorker { @Override public void onResponse(Call call, Response response) { if(response.isSuccessful() && response.body() != null) { - Toast.makeText(context, "Song creation synced: " + response.body().getSongs().size(), Toast.LENGTH_LONG).show(); + executorService.execute(() -> { + database.storeSongSyncResponses(response.body().getSongs()); + }); } else { Toast.makeText(context, "Song creation failed", Toast.LENGTH_LONG).show(); } diff --git a/music_database b/music_database deleted file mode 100644 index f05126713a61eb3f42e35b87a043dab199b85c0c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 36864 zcmeI)!EW0&7zc1lcB~q0qTakq00zd8cugWZsyF*GG>wHITjFM}i!CRak!V|+WTlcE zAV>EZ_6P%Z9d_JlXrG|F_BbH-qK5%Jm9pYi_S_!223>ZW380cPJ%<$YRTjZIW{0AbXLC&r4#9uX$IJ$>z@EMRA34qe|3Ym(G`d zUVOgTz44pKB0&HG5P$##AOHafKmY=tg20)g6f{j5twikD<$>>erpLmF2j=_}`JI-r z-8N`@`|iF$|8+fGb8NcTY#X~qiypT24z^oI^jqU--Ld%~a-uV{&%!=!8$Yy5BR!`S zR#&A*pO2fe{DH-T$PE2KFPzF;n`*N&Ro0Ym;t2Xy4mwiklCNW}7zeiS5Du z{yOb=!_cvse#G}0Z|+Q$U$iiM%DQP^#p;VtPZDLQm0k9hV=nsGo#gI?Ut> zw{A&C;{d~lu9%>jA%8gJVytJf3sZs46s`@J$JfQ3rP0@N(&?RXo#S}SxL0B7FgsOO zGTzBWai{0@A@#7n{lS?X5%0tgdGLCO&Nvg9$>X0=>G44@8MW`FTw!BFN**6Jumj(* zO^-*+W)YjsXQnzbTT0hl-(oILK2Px^ems+Z`|eZtMna4bfB*y_009U<00Izz00bZa z0SLT9ApYCDr2a$14-y0*009U<00Izz00bZa0SG_<0#{2wk>rBS&4!W8|DO`|>DB5W zdIJFnKmY;|fB*y_009U<00I!W(gGV&j_fYWi@O0AFZAE%r|~N^Jftn(`iY8n0qCKB zA~Jo~8T6>~dp!Tos(%voh5EPpmpDLz00bZa0SG_<0uX=z1Rwwb2teR}CvY>HS3FQi&B|ALxvE#c ztlTcwYnwlw^cvECsYS0>^|+Sg|Nqa4dj7$>hl(Ho0SG_<0uX=z1Rwwb2tWV=5cntp zpGjG=vhvOF*m0lyGW2Mru2ss~R(b1oGXH-`)R!M6FfnN$dH2yw`;Zf ZRz*LqmAQUw>sGm|cdM+%dDqfe{S|u`x9|V}