From fc57befd73c539ee430e5864a1d6273b962a90e5 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Mon, 19 Apr 2021 15:00:21 +0200 Subject: [PATCH] Removed unused methods from queue repository --- .../play/database/dao/QueueDao.java | 6 - .../play/repository/QueueRepository.java | 284 ++++++++---------- 2 files changed, 120 insertions(+), 170 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java index 9ccb23d6..5805cceb 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/QueueDao.java @@ -20,15 +20,9 @@ public interface QueueDao { @Query("SELECT * FROM song JOIN queue ON song.id = queue.id") List getAllSimple(); - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(Queue songQueueObject); - @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List songQueueObject); - @Delete - void delete(Queue songQueueObject); - @Query("DELETE FROM queue WHERE queue.track_order = :position") void deleteByPosition(int position); diff --git a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java index 9e6be29f..1eb474bc 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java @@ -50,10 +50,22 @@ public class QueueRepository { return songs; } - public void insert(Song song, int position) { - InsertThreadSafe insert = new InsertThreadSafe(queueDao, song, position); - Thread thread = new Thread(insert); - thread.start(); + private static class GetSongsThreadSafe implements Runnable { + private QueueDao queueDao; + private List songs; + + public GetSongsThreadSafe(QueueDao queueDao) { + this.queueDao = queueDao; + } + + @Override + public void run() { + songs = queueDao.getAllSimple(); + } + + public List getSongs() { + return songs; + } } public void insertAll(List songs) { @@ -82,166 +94,6 @@ public class QueueRepository { return mix; } - public void insertAllAndStartNew(List songs) { - try { - final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao)); - final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs)); - - delete.start(); - delete.join(); - insertAll.start(); - insertAll.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public void delete(Queue queueElement) { - DeleteThreadSafe delete = new DeleteThreadSafe(queueDao, queueElement); - Thread thread = new Thread(delete); - thread.start(); - } - - public void deleteByPosition(int position) { - DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position); - Thread thread = new Thread(delete); - thread.start(); - } - - public void deleteAll() { - DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao); - Thread thread = new Thread(delete); - thread.start(); - } - - public int count() { - int count = 0; - - CountThreadSafe countThread = new CountThreadSafe(queueDao); - Thread thread = new Thread(countThread); - thread.start(); - - try { - thread.join(); - count = countThread.getCount(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return count; - } - - private static class InsertThreadSafe implements Runnable { - private QueueDao queueDao; - private Song song; - private int position; - - public InsertThreadSafe(QueueDao queueDao, Song song, int position) { - this.queueDao = queueDao; - this.song = song; - this.position = position; - } - - @Override - public void run() { - queueDao.insert(QueueUtil.getQueueElementFromSong(song, position)); - } - } - - private static class InsertAllThreadSafe implements Runnable { - private QueueDao queueDao; - private List songs; - - public InsertAllThreadSafe(QueueDao queueDao, List songs) { - this.queueDao = queueDao; - this.songs = songs; - } - - @Override - public void run() { - queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs)); - } - } - - private static class DeleteThreadSafe implements Runnable { - private QueueDao queueDao; - private Queue queueElement; - - public DeleteThreadSafe(QueueDao queueDao, Queue queueElement) { - this.queueDao = queueDao; - this.queueElement = queueElement; - } - - @Override - public void run() { - queueDao.delete(queueElement); - } - } - - private static class DeleteAllThreadSafe implements Runnable { - private QueueDao queueDao; - - public DeleteAllThreadSafe(QueueDao queueDao) { - this.queueDao = queueDao; - } - - @Override - public void run() { - queueDao.deleteAll(); - } - } - - private static class DeleteByPositionThreadSafe implements Runnable { - private QueueDao queueDao; - private int position; - - public DeleteByPositionThreadSafe(QueueDao queueDao,int position) { - this.queueDao = queueDao; - this.position = position; - } - - @Override - public void run() { - queueDao.deleteByPosition(position); - } - } - - private static class CountThreadSafe implements Runnable { - private QueueDao queueDao; - private int count = 0; - - public CountThreadSafe(QueueDao queueDao) { - this.queueDao = queueDao; - } - - @Override - public void run() { - count = queueDao.count(); - } - - public int getCount() { - return count; - } - } - - private static class GetSongsThreadSafe implements Runnable { - private QueueDao queueDao; - private List songs; - - public GetSongsThreadSafe(QueueDao queueDao) { - this.queueDao = queueDao; - } - - @Override - public void run() { - songs = queueDao.getAllSimple(); - } - - public List getSongs() { - return songs; - } - } - private static class GetSongsByIDThreadSafe implements Runnable { private SongDao songDao; private List IDs; @@ -261,4 +113,108 @@ public class QueueRepository { return songs; } } + + public void insertAllAndStartNew(List songs) { + try { + final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao)); + final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs)); + + delete.start(); + delete.join(); + insertAll.start(); + insertAll.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static class InsertAllThreadSafe implements Runnable { + private QueueDao queueDao; + private List songs; + + public InsertAllThreadSafe(QueueDao queueDao, List songs) { + this.queueDao = queueDao; + this.songs = songs; + } + + @Override + public void run() { + queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs)); + } + } + + public void deleteByPosition(int position) { + DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position); + Thread thread = new Thread(delete); + thread.start(); + } + + private static class DeleteByPositionThreadSafe implements Runnable { + private QueueDao queueDao; + private int position; + + public DeleteByPositionThreadSafe(QueueDao queueDao,int position) { + this.queueDao = queueDao; + this.position = position; + } + + @Override + public void run() { + queueDao.deleteByPosition(position); + } + } + + public void deleteAll() { + DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao); + Thread thread = new Thread(delete); + thread.start(); + } + + private static class DeleteAllThreadSafe implements Runnable { + private QueueDao queueDao; + + public DeleteAllThreadSafe(QueueDao queueDao) { + this.queueDao = queueDao; + } + + @Override + public void run() { + queueDao.deleteAll(); + } + } + + public int count() { + int count = 0; + + CountThreadSafe countThread = new CountThreadSafe(queueDao); + Thread thread = new Thread(countThread); + thread.start(); + + try { + thread.join(); + count = countThread.getCount(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return count; + } + + private static class CountThreadSafe implements Runnable { + private QueueDao queueDao; + private int count = 0; + + public CountThreadSafe(QueueDao queueDao) { + this.queueDao = queueDao; + } + + @Override + public void run() { + count = queueDao.count(); + } + + public int getCount() { + return count; + } + } }