Store Song Creation Response

This commit is contained in:
Fawkes100 2025-01-06 21:11:09 +01:00
parent 3428e0ce1b
commit 7a7b483ac2
3 changed files with 15 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package core.notevault.data;
import androidx.room.*; import androidx.room.*;
import core.notevault.data.sync.SyncResponse; import core.notevault.data.sync.SyncResponse;
import core.notevault.data.sync.SyncStatus; import core.notevault.data.sync.SyncStatus;
import core.notevault.sync.synchronisation.songs.creation.SongCreationResponse;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -52,18 +53,13 @@ public interface MusicNoteDAO {
@Query("DELETE FROM concert_songs WHERE concertID = :concertID AND musicNoteID = :songID") @Query("DELETE FROM concert_songs WHERE concertID = :concertID AND musicNoteID = :songID")
void deleteConcertSong(long songID, int concertID); void deleteConcertSong(long songID, int concertID);
@Query("UPDATE concerts SET serverSpecificConcertID = :serverUUID WHERE id = :concertID")
@Transaction @Transaction
void updateConcertServerUUID(String serverUUID, int concertID); default void storeSongSyncResponses(List<SongCreationResponse> songCreationResponses) {
for (SongCreationResponse response : songCreationResponses) {
// Methode für das batchweise Update der Konzert-ServerUUIDs storeSongSyncResponse(response.getLocalID(), SyncStatus.SYNCED, response.getServerID());
@Query("DELETE FROM concerts WHERE serverSpecificConcertID IN (:serverSpecificIDs)") }
void deleteConcerts(List<String> serverSpecificIDs); }
@Insert @Query("UPDATE music_notes SET syncStatus = :status, serverID = :serverID WHERE musicNoteId = :localID")
@Transaction void storeSongSyncResponse(long localID, SyncStatus status, String serverID);
void insertSyncResponses(List<SyncResponse> syncResponses);
@Query("SELECT MAX(lastModified) FROM concerts")
LocalDateTime getLatestSyncTimestamp();
} }

View File

@ -1,6 +1,7 @@
package core.notevault.sync.synchronisation.songs; package core.notevault.sync.synchronisation.songs;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast; import android.widget.Toast;
import core.notevault.data.MusicNote; import core.notevault.data.MusicNote;
import core.notevault.data.MusicNoteDAO; import core.notevault.data.MusicNoteDAO;
@ -15,11 +16,14 @@ import retrofit2.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SongSyncWorker { public class SongSyncWorker {
private SyncService syncService; private SyncService syncService;
private MusicNoteDAO database; private MusicNoteDAO database;
private Context context; private Context context;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
public SongSyncWorker(SyncService syncService, MusicNoteDAO database, Context context) { public SongSyncWorker(SyncService syncService, MusicNoteDAO database, Context context) {
this.syncService = syncService; this.syncService = syncService;
@ -42,7 +46,9 @@ public class SongSyncWorker {
@Override @Override
public void onResponse(Call<SongCreationBatchResponse> call, Response<SongCreationBatchResponse> response) { public void onResponse(Call<SongCreationBatchResponse> call, Response<SongCreationBatchResponse> response) {
if(response.isSuccessful() && response.body() != null) { 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 { } else {
Toast.makeText(context, "Song creation failed", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Song creation failed", Toast.LENGTH_LONG).show();
} }

Binary file not shown.