2
2
3
3
import android .app .Activity ;
4
4
import android .app .AlertDialog ;
5
- import android .app .Fragment ;
6
5
import android .app .FragmentTransaction ;
7
6
import android .content .DialogInterface ;
8
7
import android .os .Bundle ;
22
21
23
22
import oly .netpowerctrl .R ;
24
23
import oly .netpowerctrl .application_state .NetpowerctrlApplication ;
25
- import oly .netpowerctrl .application_state .NetpowerctrlService ;
26
24
import oly .netpowerctrl .application_state .PluginInterface ;
27
25
import oly .netpowerctrl .device_ports .DevicePort ;
28
26
import oly .netpowerctrl .devices .Device ;
33
31
import oly .netpowerctrl .network .DeviceObserverResult ;
34
32
import oly .netpowerctrl .network .DeviceQuery ;
35
33
import oly .netpowerctrl .network .DeviceUpdate ;
34
+ import oly .netpowerctrl .preferences .SharedPrefs ;
36
35
import oly .netpowerctrl .utils .DoneCancelFragmentHelper ;
37
36
38
37
public class AnelDevicePreferences extends PreferenceFragment implements DeviceObserverResult , DeviceUpdate {
@@ -137,7 +136,44 @@ public boolean onPreferenceChange(Preference preference, Object o) {
137
136
}
138
137
});
139
138
140
- // update_connections();
139
+ p = m .findPreference ("connections_http_new" );
140
+ p .setOnPreferenceClickListener (new Preference .OnPreferenceClickListener () {
141
+ @ Override
142
+ public boolean onPreferenceClick (Preference preference ) {
143
+ String host = "" ;
144
+
145
+ if (device .DeviceConnections .size () > 0 )
146
+ host = device .DeviceConnections .get (0 ).getDestinationHost ();
147
+ DeviceConnection deviceConnection = new DeviceConnectionHTTP (device , host , 80 );
148
+ DeviceConnectionPreferences fragment = new DeviceConnectionPreferences ();
149
+ fragment .setDeviceConnection (deviceConnection , device , true );
150
+
151
+ //noinspection ConstantConditions
152
+ getFragmentManager ().beginTransaction ().addToBackStack (null ).
153
+ setTransitionStyle (FragmentTransaction .TRANSIT_FRAGMENT_OPEN ).
154
+ replace (R .id .content_frame , fragment ).commit ();
155
+ return true ;
156
+ }
157
+ });
158
+ p = m .findPreference ("connections_udp_new" );
159
+ p .setOnPreferenceClickListener (new Preference .OnPreferenceClickListener () {
160
+ @ Override
161
+ public boolean onPreferenceClick (Preference preference ) {
162
+ String host = "" ;
163
+ if (device .DeviceConnections .size () > 0 )
164
+ host = device .DeviceConnections .get (0 ).getDestinationHost ();
165
+ DeviceConnection deviceConnection = new DeviceConnectionUDP (device , host ,
166
+ SharedPrefs .getDefaultReceivePort (), SharedPrefs .getDefaultSendPort ());
167
+ DeviceConnectionPreferences fragment = new DeviceConnectionPreferences ();
168
+ fragment .setDeviceConnection (deviceConnection , device , true );
169
+
170
+ //noinspection ConstantConditions
171
+ getFragmentManager ().beginTransaction ().addToBackStack (null ).
172
+ setTransitionStyle (FragmentTransaction .TRANSIT_FRAGMENT_OPEN ).
173
+ replace (R .id .content_frame , fragment ).commit ();
174
+ return true ;
175
+ }
176
+ });
141
177
}
142
178
143
179
@ Override
@@ -154,13 +190,13 @@ private void update_connections() {
154
190
155
191
for (int i = pc_http .getPreferenceCount () - 1 ; i >= 0 ; --i ) {
156
192
Preference s = pc_http .getPreference (i );
157
- if (s instanceof PreferenceScreen ) {
193
+ if (! s . getKey (). equals ( "connections_http_new" ) ) {
158
194
pc_http .removePreference (s );
159
195
}
160
196
}
161
197
for (int i = pc_udp .getPreferenceCount () - 1 ; i >= 0 ; --i ) {
162
198
Preference s = pc_udp .getPreference (i );
163
- if (s instanceof PreferenceScreen ) {
199
+ if (! s . getKey (). equals ( "connections_udp_new" ) ) {
164
200
pc_udp .removePreference (s );
165
201
}
166
202
}
@@ -184,9 +220,13 @@ private void update_connections() {
184
220
s .setOnPreferenceClickListener (new Preference .OnPreferenceClickListener () {
185
221
@ Override
186
222
public boolean onPreferenceClick (Preference preference ) {
187
- Fragment fragment = Fragment .instantiate (getActivity (),
188
- DeviceConnectionPreferences .class .getName ());
189
- ((DeviceConnectionPreferences ) fragment ).setDeviceConnection (deviceConnection );
223
+ // Fragment fragment = Fragment.instantiate(getActivity(),
224
+ // DeviceConnectionPreferences.class.getName());
225
+ // ((DeviceConnectionPreferences) fragment).setDeviceConnection(deviceConnection);
226
+
227
+ DeviceConnectionPreferences fragment = new DeviceConnectionPreferences ();
228
+ fragment .setDeviceConnection (deviceConnection , device , false );
229
+
190
230
//noinspection ConstantConditions
191
231
getFragmentManager ().beginTransaction ().addToBackStack (null ).
192
232
setTransitionStyle (FragmentTransaction .TRANSIT_FRAGMENT_OPEN ).
@@ -223,9 +263,12 @@ private void testDevice() {
223
263
224
264
test_state = TestStates .TEST_REACHABLE ;
225
265
226
- PluginInterface pi = device .getPluginInterface (NetpowerctrlService .getService ());
227
- assert pi != null ;
228
- pi .enterFullNetworkState (device );
266
+ PluginInterface pluginInterface = device .getPluginInterface ();
267
+ if (pluginInterface == null ) {
268
+ Toast .makeText (getActivity (), R .string .error_plugin_not_installed , Toast .LENGTH_SHORT ).show ();
269
+ return ;
270
+ }
271
+ pluginInterface .enterFullNetworkState (device );
229
272
230
273
deviceQuery = new DeviceQuery (this , device );
231
274
}
@@ -260,9 +303,10 @@ public void onClick(DialogInterface dialog, int whichButton) {
260
303
}
261
304
262
305
private void saveAndFinish () {
263
- PluginInterface pi = device .getPluginInterface (NetpowerctrlService .getService ());
264
- assert pi != null ;
265
- pi .enterFullNetworkState (device );
306
+ PluginInterface pluginInterface = device .getPluginInterface ();
307
+ if (pluginInterface != null ) {
308
+ pluginInterface .enterFullNetworkState (device );
309
+ }
266
310
267
311
NetpowerctrlApplication .getDataController ().addToConfiguredDevices (device );
268
312
//noinspection ConstantConditions
@@ -288,7 +332,7 @@ public void onDeviceUpdated(Device updated_device, boolean willBeRemoved) {
288
332
test_state = TestStates .TEST_ACCESS ;
289
333
// Just send the current value of the first device port as target value.
290
334
// Should change nothing but we will get a feedback if the credentials are working.
291
- PluginInterface pi = device .getPluginInterface (NetpowerctrlService . getService () );
335
+ PluginInterface pi = device .getPluginInterface ();
292
336
assert pi != null ;
293
337
if (deviceQuery != null ) {
294
338
deviceQuery .addDevice (device , false );
0 commit comments