From a98ef2209e9b9f8c72cd0ff2f8e70489bdeddbc1 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Mon, 5 Dec 2016 14:51:16 +0000 Subject: [PATCH] Simplified playback engine selection. --- src/main/java/musicplayer/SwingUIModule.java | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/musicplayer/SwingUIModule.java b/src/main/java/musicplayer/SwingUIModule.java index 5ee6d50..0379555 100644 --- a/src/main/java/musicplayer/SwingUIModule.java +++ b/src/main/java/musicplayer/SwingUIModule.java @@ -25,20 +25,15 @@ class SwingUIModule extends AbstractModule { bind(IPlaylist.class).to(TabbedJTablePlaylist.class).in(Singleton.class); bind(ILibrary.class).to(JTreeLibrary.class).in(Singleton.class); bind(PlayerCallbackInterface.class).to(PlayerGUI.class).in(Singleton.class); - String engineName = ConfigManager.getPlayerEngine(); - boolean engineSet = false; - for(Engine engine : Engine.values()){ - if(engineName.equals(engine.getEngineName()) && engine.isAvailable()){ - bind(IPlayer.class).to(engine.getEngineImplementation()).in(Singleton.class); - ConfigManager.setPlayerEngine(engine.getEngineName()); - engineSet = true; - } - } - if(!engineSet){ // If the user has set an invalid engine, try and set a usable one. - for(Engine engine : Engine.values()){ - if(engine.isAvailable()){ - bind(IPlayer.class).to(engine.getEngineImplementation()).in(Singleton.class); - ConfigManager.setPlayerEngine(engine.getEngineName()); + Engine engine = Engine.valueOf(ConfigManager.getPlayerEngine()); + if (engine.isAvailable()) { + bind(IPlayer.class).to(engine.getEngineImplementation()).in(Singleton.class); + ConfigManager.setPlayerEngine(engine.getEngineName()); + } else { // If the user has set an invalid engine, try and set a usable one. + for (Engine potentialEngine : Engine.values()) { + if (potentialEngine.isAvailable()) { + bind(IPlayer.class).to(potentialEngine.getEngineImplementation()).in(Singleton.class); + ConfigManager.setPlayerEngine(potentialEngine.getEngineName()); break; } }