Skip to content

Commit 0cb46eb

Browse files
author
David Gräff
committed
Improve reaction to network connected/disconnected states. Resend handler.
* Widgets work now as expected when network state changes. * AfterSendHandler removed, SendJobRepeater introduced. Works for single outlets, scenes and widgets.
1 parent 6b24fb4 commit 0cb46eb

39 files changed

+1141
-806
lines changed

.idea/workspace.xml

+413-287
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="oly.netpowerctrl"
4-
android:versionCode="22"
5-
android:versionName="2.2b">
4+
android:versionCode="25"
5+
android:versionName="2.3b">
66

7-
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
7+
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
88
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
99
<!--<uses-sdk
1010
android:minSdkVersion="14"
@@ -32,6 +32,7 @@
3232
android:name="oly.netpowerctrl.main.NetpowerctrlActivity"
3333
android:label="@string/app_name"
3434
android:launchMode="singleTask"
35+
android:theme="@style/Theme.StartTheme"
3536
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection">
3637
<intent-filter>
3738
<action android:name="android.intent.action.MAIN" />
@@ -70,11 +71,12 @@
7071
</activity>
7172

7273
<activity
74+
android:name="oly.netpowerctrl.shortcut.ShortcutCreatorActivity"
7375
android:icon="@drawable/netpowerctrl"
7476
android:label="@string/app_name_shortcut"
7577
android:description="@string/app_name_shortcut_desc"
76-
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection"
77-
android:name="oly.netpowerctrl.shortcut.ShortcutCreatorActivity">
78+
android:theme="@style/Theme.StartTheme"
79+
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection">
7880
<intent-filter>
7981
<action android:name="android.intent.action.CREATE_SHORTCUT" />
8082
<category android:name="android.intent.category.DEFAULT" />

app/src/main/java/oly/netpowerctrl/anelservice/DeviceQuery.java

+27-22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.ArrayList;
66
import java.util.Collection;
77
import java.util.Iterator;
8+
import java.util.List;
89

910
import oly.netpowerctrl.datastructure.DeviceInfo;
1011
import oly.netpowerctrl.main.NetpowerctrlApplication;
@@ -16,10 +17,9 @@
1617
* all scenes to query.
1718
*/
1819
public class DeviceQuery {
19-
private Collection<DeviceInfo> devices_to_observe;
20+
private List<DeviceInfo> devices_to_observe;
2021
private DeviceUpdateStateOrTimeout target;
2122
private Handler timeoutHandler = new Handler();
22-
private boolean foundBroudcastQueries = false;
2323

2424
private Runnable timeoutRunnable = new Runnable() {
2525
@Override
@@ -29,26 +29,17 @@ public void run() {
2929
return;
3030

3131
if (devices_to_observe.isEmpty()) {
32-
target.onDeviceQueryFinished(devices_to_observe.size());
32+
target.onDeviceQueryFinished(devices_to_observe);
33+
NetpowerctrlApplication.instance.removeUpdateDeviceState(DeviceQuery.this);
3334
return;
3435
}
3536

36-
// Special case: We are able to send broadcasts, but nevertheless not all
37-
// configured devices responded, we will send specific queries now
38-
if (foundBroudcastQueries) {
39-
foundBroudcastQueries = false;
40-
for (DeviceInfo di : devices_to_observe) {
41-
DeviceSend.instance().sendQuery(di.HostName, di.SendPort);
42-
}
43-
// New timeout
44-
timeoutHandler.postDelayed(timeoutRunnable, 1200);
45-
} else {
46-
for (DeviceInfo di : devices_to_observe) {
47-
di.reachable = false;
48-
target.onDeviceTimeout(di);
49-
}
50-
target.onDeviceQueryFinished(devices_to_observe.size());
37+
for (DeviceInfo di : devices_to_observe) {
38+
di.reachable = false;
39+
target.onDeviceTimeout(di);
5140
}
41+
NetpowerctrlApplication.instance.removeUpdateDeviceState(DeviceQuery.this);
42+
target.onDeviceQueryFinished(devices_to_observe);
5243
}
5344
};
5445

@@ -60,7 +51,7 @@ public DeviceQuery(DeviceUpdateStateOrTimeout target, DeviceInfo device_to_obser
6051
// Register on main application object to receive device updates
6152
NetpowerctrlApplication.instance.addUpdateDeviceState(this);
6253

63-
DeviceSend.instance().sendQuery(device_to_observe.HostName, device_to_observe.SendPort);
54+
DeviceSend.instance().sendQuery(device_to_observe);
6455
timeoutHandler.postDelayed(timeoutRunnable, 1200);
6556
}
6657

@@ -75,7 +66,7 @@ public DeviceQuery(DeviceUpdateStateOrTimeout target, Collection<DeviceInfo> dev
7566

7667
// Send out broadcast
7768
for (DeviceInfo di : devices_to_observe)
78-
DeviceSend.instance().sendQuery(di.HostName, di.SendPort);
69+
DeviceSend.instance().sendQuery(di);
7970
}
8071

8172
/**
@@ -92,7 +83,7 @@ public DeviceQuery(DeviceUpdateStateOrTimeout target) {
9283
NetpowerctrlApplication.instance.addUpdateDeviceState(this);
9384

9485
timeoutHandler.postDelayed(timeoutRunnable, 1200);
95-
foundBroudcastQueries = DeviceSend.instance().sendBroadcastQuery();
86+
DeviceSend.instance().sendBroadcastQuery();
9687
}
9788

9889
/**
@@ -114,9 +105,23 @@ public boolean notifyObservers(DeviceInfo received_data) {
114105
if (devices_to_observe.isEmpty()) {
115106
timeoutHandler.removeCallbacks(timeoutRunnable);
116107
if (target != null)
117-
target.onDeviceQueryFinished(devices_to_observe.size());
108+
target.onDeviceQueryFinished(devices_to_observe);
118109
return true;
119110
}
120111
return false;
121112
}
113+
114+
/**
115+
* Called right before this object is removed from the Application list
116+
* of DeviceQueries because the listener service has been shutdown. All
117+
* remaining device queries of this object have to timeout now.
118+
*/
119+
public void finishWithTimeouts() {
120+
timeoutHandler.removeCallbacks(timeoutRunnable);
121+
for (DeviceInfo di : devices_to_observe) {
122+
di.reachable = false;
123+
target.onDeviceTimeout(di);
124+
}
125+
target.onDeviceQueryFinished(devices_to_observe);
126+
}
122127
}

0 commit comments

Comments
 (0)