nextNoteVault #23
@ -24,5 +24,6 @@ public interface SongDao {
 | 
			
		||||
    @Delete
 | 
			
		||||
    void deleteNoteSheets(List<NoteSheet> noteSheets);
 | 
			
		||||
 | 
			
		||||
    @Query("SELECT * FROM NoteSheet WHERE songID = :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.Song;
 | 
			
		||||
import com.stormtales.notevault.data.sync.SyncStatus;
 | 
			
		||||
import com.stormtales.notevault.utils.NoteSheetsUtil;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.concurrent.ExecutorService;
 | 
			
		||||
import java.util.concurrent.Executors;
 | 
			
		||||
@ -59,7 +61,19 @@ public class SongRepository {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteSong(Song song) {
 | 
			
		||||
        song.setSyncStatus(SyncStatus.DELETED);
 | 
			
		||||
        songDao.update(song);
 | 
			
		||||
        Executors.newSingleThreadExecutor().execute(() -> {
 | 
			
		||||
            song.setSyncStatus(SyncStatus.DELETED);
 | 
			
		||||
            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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void deleteNoteSheet(String filePath) throws IOException {
 | 
			
		||||
        Files.delete(new File(filePath).toPath());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user