Bladeren bron

Get rid of Main reference from Twitter Plugin.

Change-Id: I81128804d899e524eb18d221b202e9fef80a194a
Reviewed-on: http://gerrit.dmdirc.com/2713
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Chris Smith 10 jaren geleden
bovenliggende
commit
3b59adb06a

+ 15
- 3
src/com/dmdirc/addons/parser_twitter/TwitterPlugin.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.parser_twitter;
24 24
 
25
+import com.dmdirc.ServerManager;
25 26
 import com.dmdirc.actions.ActionManager;
26 27
 import com.dmdirc.addons.parser_twitter.actions.TwitterActionComponents;
27 28
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
@@ -29,6 +30,7 @@ import com.dmdirc.config.prefs.PreferencesCategory;
29 30
 import com.dmdirc.config.prefs.PreferencesDialogModel;
30 31
 import com.dmdirc.config.prefs.PreferencesSetting;
31 32
 import com.dmdirc.config.prefs.PreferencesType;
33
+import com.dmdirc.interfaces.actions.ActionComponent;
32 34
 import com.dmdirc.parser.common.MyInfo;
33 35
 import com.dmdirc.parser.interfaces.Parser;
34 36
 import com.dmdirc.parser.interfaces.ProtocolDescription;
@@ -47,29 +49,39 @@ public class TwitterPlugin extends BasePlugin {
47 49
     private volatile boolean unloading = false;
48 50
     /** This plugin's plugin info. */
49 51
     private final PluginInfo pluginInfo;
52
+    /** The server manager to use. */
53
+    private final ServerManager serverManager;
50 54
 
51 55
     /**
52 56
      * Creates a new instance of this plugin.
53 57
      *
54 58
      * @param pluginInfo This plugin's plugin info
59
+     * @param serverManager The server manager to use.
55 60
      */
56
-    public TwitterPlugin(final PluginInfo pluginInfo) {
61
+    public TwitterPlugin(
62
+            final PluginInfo pluginInfo,
63
+            final ServerManager serverManager) {
57 64
         super();
58 65
         this.pluginInfo = pluginInfo;
66
+        this.serverManager = serverManager;
59 67
     }
60 68
 
61 69
     /** {@inheritDoc} */
62 70
     @Override
63 71
     public void onLoad() {
64 72
         ActionManager.getActionManager().registerComponents(
65
-                TwitterActionComponents.values());
73
+                new ActionComponent[] {
74
+                    new TwitterActionComponents.ChannelNameStatus(serverManager),
75
+                    new TwitterActionComponents.StatusUser(),
76
+                    new TwitterActionComponents.UserScreenName(),
77
+                });
66 78
     }
67 79
 
68 80
     /** {@inheritDoc} */
69 81
     @Override
70 82
     public void onUnload() {
71 83
         unloading = true;
72
-        for (final Twitter parser : new ArrayList<Twitter>(Twitter.PARSERS)) {
84
+        for (final Twitter parser : new ArrayList<>(Twitter.PARSERS)) {
73 85
             parser.disconnect("");
74 86
         }
75 87
     }

+ 38
- 9
src/com/dmdirc/addons/parser_twitter/actions/TwitterActionComponents.java Bestand weergeven

@@ -22,8 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.parser_twitter.actions;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.Server;
26
+import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.interfaces.actions.ActionComponent;
28 28
 import com.dmdirc.addons.parser_twitter.Twitter;
29 29
 import com.dmdirc.addons.parser_twitter.api.TwitterStatus;
@@ -34,19 +34,30 @@ import com.dmdirc.parser.interfaces.Parser;
34 34
  * Action components which expose Twitter functionality.
35 35
  *
36 36
  * @since 0.6.4
37
- * @author chris
38 37
  */
39
-public enum TwitterActionComponents implements ActionComponent {
38
+public class TwitterActionComponents {
40 39
 
41 40
     /** Takes a twitter channel name (&12345) and returns the status. */
42
-    TWITTER_CHANNEL_NAME_STATUS {
41
+    public static class ChannelNameStatus implements ActionComponent {
42
+
43
+        /** Server manager to use to get servers. */
44
+        private final ServerManager serverManager;
45
+
46
+        /**
47
+         * Creates a new instance of {@link ChannelNameStatus}.
48
+         *
49
+         * @param serverManager The server manager to use to get servers.
50
+         */
51
+        public ChannelNameStatus(final ServerManager serverManager) {
52
+            this.serverManager = serverManager;
53
+        }
43 54
 
44 55
         /** {@inheritDoc} */
45 56
         @Override
46 57
         public Object get(final Object arg) {
47 58
             final long id = Long.parseLong(((String) arg).substring(1));
48 59
 
49
-            for (Server server : Main.mainInstance.getServerManager().getServers()) {
60
+            for (Server server : serverManager.getServers()) {
50 61
                 final Parser parser = server.getParser();
51 62
 
52 63
                 if (parser instanceof Twitter) {
@@ -79,10 +90,16 @@ public enum TwitterActionComponents implements ActionComponent {
79 90
             return "twitter status (if a Twitter channel link)";
80 91
         }
81 92
 
82
-    },
93
+        /** {@inheritDoc} */
94
+        @Override
95
+        public String name() {
96
+            return "TWITTER_CHANNEL_NAME_STATUS";
97
+        }
98
+
99
+    };
83 100
 
84 101
     /** Returns the user who created a tweet. */
85
-    TWITTER_STATUS_USER {
102
+    public static class StatusUser implements ActionComponent {
86 103
 
87 104
         /** {@inheritDoc} */
88 105
         @Override
@@ -108,10 +125,16 @@ public enum TwitterActionComponents implements ActionComponent {
108 125
             return "user";
109 126
         }
110 127
 
111
-    },
128
+        /** {@inheritDoc} */
129
+        @Override
130
+        public String name() {
131
+            return "TWITTER_STATUS_USER";
132
+        }
133
+
134
+    };
112 135
 
113 136
     /** Returns the screen name of a twitter user. */
114
-    TWITTER_USER_SCREENNAME {
137
+    public static class UserScreenName implements ActionComponent {
115 138
 
116 139
         /** {@inheritDoc} */
117 140
         @Override
@@ -137,6 +160,12 @@ public enum TwitterActionComponents implements ActionComponent {
137 160
             return "screen name";
138 161
         }
139 162
 
163
+        /** {@inheritDoc} */
164
+        @Override
165
+        public String name() {
166
+            return "TWITTER_USER_SCREENNAME";
167
+        }
168
+
140 169
     };
141 170
 
142 171
 }

Laden…
Annuleren
Opslaan