Remove NoteSheets when Deleting Song
This commit is contained in:
parent
c04dbe565a
commit
7e04b7c9f3
@ -24,5 +24,6 @@ public interface SongDao {
|
|||||||
@Delete
|
@Delete
|
||||||
void deleteNoteSheets(List<NoteSheet> noteSheets);
|
void deleteNoteSheets(List<NoteSheet> noteSheets);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM NoteSheet WHERE songID = :songID")
|
||||||
List<NoteSheet> getNoteSheetsBySong(int songID);
|
List<NoteSheet> getNoteSheetsBySong(int songID);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ import com.stormtales.notevault.data.dao.SongDao;
|
|||||||
import com.stormtales.notevault.data.entities.NoteSheet;
|
import com.stormtales.notevault.data.entities.NoteSheet;
|
||||||
import com.stormtales.notevault.data.entities.Song;
|
import com.stormtales.notevault.data.entities.Song;
|
||||||
import com.stormtales.notevault.data.sync.SyncStatus;
|
import com.stormtales.notevault.data.sync.SyncStatus;
|
||||||
|
import com.stormtales.notevault.utils.NoteSheetsUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -59,7 +61,19 @@ public class SongRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteSong(Song song) {
|
public void deleteSong(Song song) {
|
||||||
|
Executors.newSingleThreadExecutor().execute(() -> {
|
||||||
song.setSyncStatus(SyncStatus.DELETED);
|
song.setSyncStatus(SyncStatus.DELETED);
|
||||||
songDao.update(song);
|
songDao.update(song);
|
||||||
|
|
||||||
|
List<NoteSheet> noteSheets = songDao.getNoteSheetsBySong(song.getLocalID());
|
||||||
|
for(NoteSheet noteSheet : noteSheets) {
|
||||||
|
try {
|
||||||
|
NoteSheetsUtil.deleteNoteSheet(noteSheet.getLocalFileName());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
songDao.deleteNoteSheets(noteSheets);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,4 +84,8 @@ public class NoteSheetsUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteNoteSheet(String filePath) throws IOException {
|
||||||
|
Files.delete(new File(filePath).toPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user