From 7f44143e08ee4ed5d9c89efe5e0592d2c5b39dd8 Mon Sep 17 00:00:00 2001
From: undisclosed
Date: Sun, 29 Jan 2023 17:04:48 +0000
Subject: [PATCH] Titel entfernen bei spielender Abspielliste berichtigt

---
 src/de/uhilger/tango/api/ListHandler.java |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/src/de/uhilger/tango/api/ListHandler.java b/src/de/uhilger/tango/api/ListHandler.java
index 490fd4c..341456c 100644
--- a/src/de/uhilger/tango/api/ListHandler.java
+++ b/src/de/uhilger/tango/api/ListHandler.java
@@ -20,12 +20,15 @@
 import com.google.gson.Gson;
 import com.sun.net.httpserver.Headers;
 import com.sun.net.httpserver.HttpExchange;
+import de.uhilger.tango.PlaylistListener;
 import de.uhilger.tango.Server;
 import de.uhilger.tango.entity.Abspielliste;
 import de.uhilger.tango.entity.Entity;
 import de.uhilger.tango.entity.Titel;
 import de.uhilger.tango.store.FileStorage;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Logger;
 
@@ -58,8 +61,11 @@
   
   private String conf;
   
+  private List<PlaylistListener> listeners;
+  
   public ListHandler(String conf) {
     this.conf = conf;
+    listeners = new ArrayList();
   }
 
   @Override
@@ -242,7 +248,9 @@
       if(titelStr.equalsIgnoreCase(ALLE_TITEL)) {
         liste.getTitel().clear();
       } else {
-        liste.getTitel().remove(Integer.parseInt(elems[elems.length-1]));
+        int idx = Integer.parseInt(elems[elems.length-1]);
+        liste.getTitel().remove(idx);
+        sendRemovalInfo(liste.getName(), idx);
       }
       fs.write(liste, true);
       return true;
@@ -251,4 +259,19 @@
     }
   }
   
+  private void sendRemovalInfo(String listName, int titleIndex) {
+    Iterator<PlaylistListener> i = listeners.iterator();
+    while(i.hasNext()) {
+      PlaylistListener l = i.next();
+      l.titleRemoved(listName, titleIndex);
+    }
+  }
+  
+  public void addPlaylistListener(PlaylistListener listener) {
+    this.listeners.add(listener);
+  }
+  
+  public void removePlaylistListener(PlaylistListener listener) {
+    this.listeners.remove(listener);
+  }
 }

--
Gitblit v1.9.3