Store Song Creation Response
This commit is contained in:
parent
3428e0ce1b
commit
7a7b483ac2
@ -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<SongCreationResponse> 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<String> serverSpecificIDs);
|
||||
|
||||
@Insert
|
||||
@Transaction
|
||||
void insertSyncResponses(List<SyncResponse> 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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
BIN
music_database
BIN
music_database
Binary file not shown.
Loading…
Reference in New Issue
Block a user