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 f051267..0000000 Binary files a/music_database and /dev/null differ