Implement Marking as Deletion
This commit is contained in:
parent
a550ff0ac8
commit
c23f188921
@ -17,7 +17,7 @@ public interface MusicNoteDAO {
|
||||
@Insert
|
||||
void insertNoteSheet(NoteSheet noteSheet);
|
||||
|
||||
@Query("SELECT * FROM music_notes")
|
||||
@Query("SELECT * FROM music_notes WHERE syncStatus != 'DELETED'")
|
||||
List<MusicNote> getAllNotes();
|
||||
|
||||
@Query("SELECT * FROM note_sheets WHERE musicNoteId = :musicNoteId")
|
||||
@ -68,4 +68,9 @@ public interface MusicNoteDAO {
|
||||
|
||||
@Update
|
||||
void updateSong(MusicNote musicNote);
|
||||
|
||||
@Query("DELETE FROM music_notes WHERE serverID IN (:serverIDs)")
|
||||
void deleteSongs(List<String> serverIDs);
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public class SyncWorker extends Worker{
|
||||
try {
|
||||
songSyncWorker.syncSongCreations();
|
||||
songSyncWorker.syncSongModifications();
|
||||
songSyncWorker.syncSongDeletions();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.failure();
|
||||
|
@ -3,6 +3,8 @@ package core.notevault.sync.synchronisation;
|
||||
import core.notevault.data.sync.SyncResponse;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.deletion.SongDeletionBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.deletion.SongDeletionBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchResponse;
|
||||
import retrofit2.Call;
|
||||
@ -16,4 +18,7 @@ public interface SyncService {
|
||||
|
||||
@POST("/sync/songs/modify")
|
||||
Call<SongModificationBatchResponse> performSongModification(@Body SongModificationBatchRequest syncRequest);
|
||||
|
||||
@POST("/sync/songs/delete")
|
||||
Call<SongDeletionBatchResponse> performSongDeletion(@Body SongDeletionBatchRequest syncRequest);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import core.notevault.sync.synchronisation.SyncService;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationRequest;
|
||||
import core.notevault.sync.synchronisation.songs.deletion.SongDeletionBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.deletion.SongDeletionBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationRequest;
|
||||
@ -22,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SongSyncWorker {
|
||||
private SyncService syncService;
|
||||
@ -90,4 +93,29 @@ public class SongSyncWorker {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private SongDeletionBatchRequest buildDeletionBatchRequest() {
|
||||
List<MusicNote> deleted_songs = database.getSongsWithSyncStatus(SyncStatus.DELETED);
|
||||
List<String> deleted_song_ids = deleted_songs.stream().map(MusicNote::getServerID).collect(Collectors.toList());
|
||||
return new SongDeletionBatchRequest(deleted_song_ids);
|
||||
}
|
||||
|
||||
public void syncSongDeletions() {
|
||||
SongDeletionBatchRequest request = buildDeletionBatchRequest();
|
||||
syncService.performSongDeletion(request).enqueue(new Callback<SongDeletionBatchResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SongDeletionBatchResponse> call, Response<SongDeletionBatchResponse> response) {
|
||||
if(response.isSuccessful() && response.body() != null) {
|
||||
executorService.execute(() -> {
|
||||
database.deleteSongs(response.body().getDeletedSongs());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SongDeletionBatchResponse> call, Throwable throwable) {
|
||||
Toast.makeText(context, "Sync of Deleted Songs failed", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package core.notevault.sync.synchronisation.songs.deletion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongDeletionBatchRequest {
|
||||
private List<String> songs;
|
||||
|
||||
public SongDeletionBatchRequest(List<String> songs) {
|
||||
this.songs = songs;
|
||||
}
|
||||
|
||||
public List<String> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
|
||||
public void setSongs(List<String> songs) {
|
||||
this.songs = songs;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package core.notevault.sync.synchronisation.songs.deletion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongDeletionBatchResponse {
|
||||
private List<String> deletedSongs;
|
||||
|
||||
public SongDeletionBatchResponse(List<String> deletedSongs) {
|
||||
this.deletedSongs = deletedSongs;
|
||||
}
|
||||
|
||||
public List<String> getDeletedSongs() {
|
||||
return deletedSongs;
|
||||
}
|
||||
|
||||
public void setDeletedSongs(List<String> deletedSongs) {
|
||||
this.deletedSongs = deletedSongs;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import core.notevault.R;
|
||||
import core.notevault.data.MusicDatabase;
|
||||
import core.notevault.data.MusicNote;
|
||||
import core.notevault.data.MusicNoteDAO;
|
||||
import core.notevault.data.sync.SyncStatus;
|
||||
import core.notevault.databinding.FragmentHomeBinding;
|
||||
import core.notevault.ui.metadatadialog.MetaDataDialog;
|
||||
import core.notevault.ui.metadatadialog.SongEditDialog;
|
||||
@ -78,7 +79,8 @@ public class HomeFragment extends Fragment {
|
||||
new Thread(() -> {
|
||||
MusicDatabase musicDatabase = MusicDatabase.getDatabase(getContext());
|
||||
MusicNoteDAO musicNoteDAO = musicDatabase.musicNoteDao();
|
||||
musicNoteDAO.deleteSong(musicNote);
|
||||
musicNote.setSyncStatus(SyncStatus.DELETED);
|
||||
musicNoteDAO.updateSong(musicNote);
|
||||
Log.d("HomeFragment", "Delete Song: " + musicNote.getTitle());
|
||||
new Handler(Looper.getMainLooper()).post(()-> {
|
||||
homeViewModel.deleteSong(musicNote);
|
||||
|
Loading…
Reference in New Issue
Block a user