Browse Source

DI the session lock plugin.

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

+ 12
- 48
src/com/dmdirc/addons/sessionlock/SessionLock.java View File

@@ -22,72 +22,36 @@
22 22
 
23 23
 package com.dmdirc.addons.sessionlock;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
25
+import com.dmdirc.plugins.PluginInfo;
26 26
 import com.dmdirc.plugins.implementations.BasePlugin;
27 27
 
28
-import com.greboid.lock.LockAdapter;
29
-import com.greboid.lock.LockListener;
28
+import dagger.ObjectGraph;
30 29
 
31 30
 /**
32 31
  * Plugin that detects Session lock/unlock events.
33 32
  */
34
-public class SessionLock extends BasePlugin implements LockListener {
33
+public class SessionLock extends BasePlugin {
35 34
 
36
-    /**
37
-     * Have we registered our actions?
38
-     */
39
-    private static boolean registered;
40
-    /**
41
-     * Lock Adapter to detect session events.
42
-     */
43
-    private LockAdapter lockAdapter;
44
-    /**
45
-     * Action manager.
46
-     */
47
-    private final ActionManager actionManager;
35
+    /** Handles session lock events and registers action types. */
36
+    private SessionLockManager manager;
48 37
 
49
-    /**
50
-     * Creates a new session lock plugin.
51
-     *
52
-     * @param actionManager Action manager
53
-     */
54
-    public SessionLock(final ActionManager actionManager) {
55
-        this.actionManager = actionManager;
38
+    @Override
39
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
40
+        super.load(pluginInfo, graph);
41
+        setObjectGraph(graph.plus(new SessionLockModule()));
42
+        manager = getObjectGraph().get(SessionLockManager.class);
56 43
     }
57 44
 
58
-    /** {@inheritDoc} */
59 45
     @Override
60 46
     public void onLoad() {
61 47
         super.onLoad();
62
-
63
-        if (!registered) {
64
-            actionManager.registerTypes(SessionLockActionType.values());
65
-            registered = true;
66
-        }
67
-
68
-        lockAdapter = new LockAdapter();
69
-        lockAdapter.addLockListener(this);
48
+        manager.load();
70 49
     }
71 50
 
72
-    /** {@inheritDoc} */
73 51
     @Override
74 52
     public void onUnload() {
75 53
         super.onUnload();
76
-
77
-        lockAdapter.removeLockListener(this);
78
-        lockAdapter = null;
79
-    }
80
-
81
-    /** {@inheritDoc} */
82
-    @Override
83
-    public void locked() {
84
-        actionManager.triggerEvent(SessionLockActionType.SESSION_LOCK, null);
85
-    }
86
-
87
-    /** {@inheritDoc} */
88
-    @Override
89
-    public void unlocked() {
90
-        actionManager.triggerEvent(SessionLockActionType.SESSION_UNLOCK, null);
54
+        manager.unload();
91 55
     }
92 56
 
93 57
 }

+ 77
- 0
src/com/dmdirc/addons/sessionlock/SessionLockManager.java View File

@@ -0,0 +1,77 @@
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.sessionlock;
24
+
25
+import com.dmdirc.actions.ActionManager;
26
+
27
+import javax.inject.Inject;
28
+
29
+import com.greboid.lock.LockAdapter;
30
+import com.greboid.lock.LockListener;
31
+
32
+public class SessionLockManager implements LockListener {
33
+
34
+    /** Action manager. */
35
+    private final ActionManager actionManager;
36
+    /** Have we registered our actions? */
37
+    private static boolean registered;
38
+    /** Lock Adapter to detect session events. */
39
+    private LockAdapter lockAdapter;
40
+
41
+    @Inject
42
+    public SessionLockManager(final ActionManager actionManager) {
43
+        this.actionManager = actionManager;
44
+    }
45
+
46
+    /**
47
+     * Loads the manager, registering action types and the lock adapter.
48
+     */
49
+    public void load() {
50
+        if (!registered) {
51
+            actionManager.registerTypes(SessionLockActionType.values());
52
+            registered = true;
53
+        }
54
+
55
+        lockAdapter = new LockAdapter();
56
+        lockAdapter.addLockListener(this);
57
+    }
58
+
59
+    /**
60
+     * Unloads the plugin, removing lock adapter, action types remain.
61
+     */
62
+    public void unload() {
63
+        lockAdapter.removeLockListener(this);
64
+        lockAdapter = null;
65
+    }
66
+
67
+    @Override
68
+    public void locked() {
69
+        actionManager.triggerEvent(SessionLockActionType.SESSION_LOCK, null);
70
+    }
71
+
72
+    @Override
73
+    public void unlocked() {
74
+        actionManager.triggerEvent(SessionLockActionType.SESSION_UNLOCK, null);
75
+    }
76
+
77
+}

+ 32
- 0
src/com/dmdirc/addons/sessionlock/SessionLockModule.java View File

@@ -0,0 +1,32 @@
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.sessionlock;
24
+
25
+import com.dmdirc.ClientModule;
26
+
27
+import dagger.Module;
28
+
29
+@Module(injects = SessionLockManager.class, addsTo = ClientModule.class)
30
+public class SessionLockModule {
31
+
32
+}

Loading…
Cancel
Save