From 097fb251cb71b3f4b38f7596fe416fc096528847 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 5 Feb 2019 15:07:56 +0100 Subject: [PATCH] Add getCurrentlyRecording to recorder This method returns the models, which are currently recorded. It is implemented as default method, so that LocalRecorder and RemoteRecorder don't have to implement the same logic. --- .../java/ctbrec/ui/CamrecApplication.java | 4 ++-- .../main/java/ctbrec/recorder/Recorder.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 0dd0be64..0ef5eb61 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -254,8 +254,8 @@ public class CamrecApplication extends Application { public void handleEvent(Event evt) { if(evt.getType() == Event.Type.MODEL_ONLINE || evt.getType() == Event.Type.MODEL_STATUS_CHANGED || evt.getType() == Event.Type.RECORDING_STATUS_CHANGED) { try { - List models = recorder.getOnlineModels(); - long count = models.stream().filter(m -> !recorder.isSuspended(m)).count(); + List models = recorder.getCurrentlyRecording(); + long count = models.size(); String _title = count > 0 ? "(" + count + ") " + title : title; Platform.runLater(() -> primaryStage.setTitle(_title)); } catch (Exception e) { diff --git a/common/src/main/java/ctbrec/recorder/Recorder.java b/common/src/main/java/ctbrec/recorder/Recorder.java index 48a1d400..2eee050f 100644 --- a/common/src/main/java/ctbrec/recorder/Recorder.java +++ b/common/src/main/java/ctbrec/recorder/Recorder.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.stream.Collectors; import ctbrec.Model; import ctbrec.Recording; @@ -41,11 +42,31 @@ public interface Recorder { public boolean isSuspended(Model model); /** - * Returns only the models from getModelsRecording(), which are online + * Returns only the models from getModels(), which are online * @return */ public List getOnlineModels(); + /** + * Returns only the models from getModels(), which are actually recorded right now + * @return + * @throws IOException + * @throws IllegalStateException + * @throws NoSuchAlgorithmException + * @throws InvalidKeyException + */ + public default List getCurrentlyRecording() throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, IOException { + List recordings = getRecordings(); + return getModels().stream().filter(m -> { + for (Recording recording : recordings) { + if (recording.getStatus() == Recording.State.RECORDING && recording.getModelName().equals(m.getName())) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + } + public HttpClient getHttpClient(); /** @@ -72,4 +93,5 @@ public interface Recorder { * @throws IOException */ public void regeneratePlaylist(Recording recording) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException; + }