Browse Source

DI the NMA plugin.

Change-Id: If70b7f3232c5cb29887b6e9c75d02e7eb0e4ec4b
Reviewed-on: http://gerrit.dmdirc.com/3199
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Greg Holmes 10 years ago
parent
commit
fdb867405e

+ 8
- 5
src/com/dmdirc/addons/nma/NotifyMyAndroidCommand.java View File

@@ -29,9 +29,12 @@ import com.dmdirc.commandparser.CommandType;
29 29
 import com.dmdirc.commandparser.commands.Command;
30 30
 import com.dmdirc.commandparser.commands.context.CommandContext;
31 31
 import com.dmdirc.interfaces.CommandController;
32
+import com.dmdirc.plugins.PluginDomain;
32 33
 
33 34
 import java.io.IOException;
34 35
 
36
+import javax.inject.Inject;
37
+
35 38
 import org.slf4j.LoggerFactory;
36 39
 
37 40
 /**
@@ -48,18 +51,18 @@ public class NotifyMyAndroidCommand extends Command {
48 51
             + " - Sends notification to NotifyMyAndroid",
49 52
             CommandType.TYPE_GLOBAL);
50 53
     /** The configuration domain to retrieve settings from. */
51
-    private String configDomain;
54
+    private final String configDomain;
52 55
 
53 56
     /**
54 57
      * Creates a new instance of this command.
55 58
      *
56 59
      * @param controller The controller to use for command information.
60
+     * @param configDomain This plugin's settings domain
57 61
      */
58
-    public NotifyMyAndroidCommand(final CommandController controller) {
62
+    @Inject
63
+    public NotifyMyAndroidCommand(final CommandController controller,
64
+            @PluginDomain(NotifyMyAndroidPlugin.class) final String configDomain) {
59 65
         super(controller);
60
-    }
61
-
62
-    public void setConfigDomain(final String configDomain) {
63 66
         this.configDomain = configDomain;
64 67
     }
65 68
 

+ 47
- 0
src/com/dmdirc/addons/nma/NotifyMyAndroidModule.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.nma;
24
+
25
+import com.dmdirc.ClientModule;
26
+import com.dmdirc.plugins.PluginDomain;
27
+import com.dmdirc.plugins.PluginInfo;
28
+
29
+import dagger.Module;
30
+import dagger.Provides;
31
+
32
+@Module(injects = NotifyMyAndroidCommand.class, addsTo = ClientModule.class)
33
+public class NotifyMyAndroidModule {
34
+
35
+    private final PluginInfo pluginInfo;
36
+
37
+    public NotifyMyAndroidModule(final PluginInfo pluginInfo) {
38
+        this.pluginInfo = pluginInfo;
39
+    }
40
+
41
+    @Provides
42
+    @PluginDomain(NotifyMyAndroidPlugin.class)
43
+    public String getSettingsDomain() {
44
+        return pluginInfo.getDomain();
45
+    }
46
+
47
+}

+ 7
- 17
src/com/dmdirc/addons/nma/NotifyMyAndroidPlugin.java View File

@@ -27,44 +27,34 @@ import com.dmdirc.config.prefs.PreferencesCategory;
27 27
 import com.dmdirc.config.prefs.PreferencesDialogModel;
28 28
 import com.dmdirc.config.prefs.PreferencesSetting;
29 29
 import com.dmdirc.config.prefs.PreferencesType;
30
-import com.dmdirc.interfaces.CommandController;
31 30
 import com.dmdirc.plugins.PluginInfo;
32 31
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
33 32
 
33
+import dagger.ObjectGraph;
34
+
34 35
 /**
35 36
  * Plugin to allow pushing notifications to NotifyMyAndroid.
36 37
  */
37 38
 public class NotifyMyAndroidPlugin extends BaseCommandPlugin {
38 39
 
39
-    /** The command to register. */
40
-    private final NotifyMyAndroidCommand command;
41 40
     /** Our info object. */
42 41
     private final PluginInfo pluginInfo;
43 42
 
44 43
     /**
45 44
      * Creates a new instance of the {@link NotifyMyAndroidPlugin}.
46 45
      *
47
-     * @param pluginInfo        The plugin info object for this plugin.
48
-     * @param commandController Command controller to register commands
46
+     * @param pluginInfo The plugin info object for this plugin.
49 47
      */
50
-    public NotifyMyAndroidPlugin(final PluginInfo pluginInfo,
51
-            final CommandController commandController) {
52
-        super(commandController);
53
-
54
-        command = new NotifyMyAndroidCommand(commandController);
55
-        registerCommand(command, NotifyMyAndroidCommand.INFO);
56
-
48
+    public NotifyMyAndroidPlugin(final PluginInfo pluginInfo) {
57 49
         this.pluginInfo = pluginInfo;
58 50
     }
59 51
 
60
-    /** {@inheritDoc} */
61 52
     @Override
62
-    public void setDomain(final String newDomain) {
63
-        super.setDomain(newDomain);
64
-        command.setConfigDomain(newDomain);
53
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
54
+        super.load(pluginInfo, graph);
55
+        setObjectGraph(graph.plus(new NotifyMyAndroidModule(pluginInfo)));
65 56
     }
66 57
 
67
-    /** {@inheritDoc} */
68 58
     @Override
69 59
     public void showConfig(final PreferencesDialogModel manager) {
70 60
         final PreferencesCategory category = new PluginPreferencesCategory(

Loading…
Cancel
Save