From 147d8510d51a7abe713ccd76d236520407d32e4c Mon Sep 17 00:00:00 2001 From: Matthijs Tijink Date: Thu, 7 Dec 2017 17:52:18 +0100 Subject: [PATCH] Simplify MPRIS callback code Summary: Makes sure the MPRIS data is always up-to-date, so requesting updates separately is never necessary. Also provides a way to remove callbacks. Test Plan: All information still appears in the MPRIS activity and the controls still work. Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Differential Revision: https://phabricator.kde.org/D9084 --- .../Plugins/MprisPlugin/MprisPlugin.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index 23403a82..9faa0510 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -198,6 +198,10 @@ public class MprisPlugin extends Plugin { @Override public boolean onCreate() { requestPlayerList(); + + //Always request the player list so the data is up-to-date + requestPlayerList(); + return true; } @@ -312,22 +316,20 @@ public class MprisPlugin extends Plugin { playerStatusUpdated.put(id, h); h.dispatchMessage(new Message()); + } - //Get the status if this is the first handler we have - if (playerListUpdated.size() == 1 && !players.isEmpty()) { - requestPlayerStatus(getPlayerList().get(0)); - } + public void removePlayerStatusUpdatedHandler(String id) { + playerStatusUpdated.remove(id); } public void setPlayerListUpdatedHandler(String id, Handler h) { playerListUpdated.put(id,h); h.dispatchMessage(new Message()); + } - //Get the status if this is the first handler we have - if (playerListUpdated.size() == 1) { - requestPlayerList(); - } + public void removePlayerListUpdatedHandler(String id) { + playerListUpdated.remove(id); } public List getPlayerList() {