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 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);
// Methode für das batchweise Update der Konzert-ServerUUIDs
@Query("DELETE FROM concerts WHERE serverSpecificConcertID IN (:serverSpecificIDs)")
void deleteConcerts(List<String> serverSpecificIDs);
@Insert
@Transaction
void insertSyncResponses(List<SyncResponse> syncResponses);
@Query("SELECT MAX(lastModified) FROM concerts")
LocalDateTime getLatestSyncTimestamp();
default void storeSongSyncResponses(List<SongCreationResponse> songCreationResponses) {
for (SongCreationResponse response : songCreationResponses) {
storeSongSyncResponse(response.getLocalID(), SyncStatus.SYNCED, response.getServerID());
}
}
@Query("UPDATE music_notes SET syncStatus = :status, serverID = :serverID WHERE musicNoteId = :localID")
void storeSongSyncResponse(long localID, SyncStatus status, String serverID);
}

View File

@ -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<SongCreationBatchResponse> call, Response<SongCreationBatchResponse> 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();
}

Binary file not shown.