Skip to content

Commit 4f8d412

Browse files
author
David Gräff
committed
improve add device dialog; lint fixes
1 parent 739e893 commit 4f8d412

38 files changed

+932
-580
lines changed

.idea/misc.xml

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

.idea/workspace.xml

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

app/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ android {
55
buildToolsVersion '20'
66

77
productFlavors {
8+
//noinspection GroovyMissingReturnStatement
89
vanilla {
910

1011
}
@@ -17,8 +18,8 @@ android {
1718
defaultConfig {
1819
minSdkVersion 14
1920
targetSdkVersion 20
20-
versionCode 80
21-
versionName "5.6.5"
21+
versionCode 81
22+
versionName "5.7"
2223
}
2324

2425
lintOptions {

app/proguard-rules.txt

+2-11
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,13 @@
3535
}
3636

3737
# keep this otherwise it is removed by ProGuard
38-
-keep public class org.acra.ErrorReporter
39-
{
38+
-keep public class org.acra.ErrorReporter {
4039
public void addCustomData(java.lang.String,java.lang.String);
4140
public void putCustomData(java.lang.String,java.lang.String);
4241
public void removeCustomData(java.lang.String);
4342
}
4443

4544
# keep this otherwise it is removed by ProGuard
46-
-keep public class org.acra.ErrorReporter
47-
{
45+
-keep public class org.acra.ErrorReporter {
4846
public void handleSilentException(java.lang.Throwable);
4947
}
50-
51-
-keepnames class oly.netpowerctrl.shortcut.SceneEditFragmentReady {
52-
*;
53-
}
54-
-keepnames class oly.netpowerctrl.main.SceneEditFragment {
55-
*;
56-
}

app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
android:name=".application_state.NetpowerctrlApplication"
3535
android:allowBackup="true"
3636
android:icon="@drawable/netpowerctrl"
37-
android:label="@string/app_name">
37+
android:label="@string/app_name"
38+
android:supportsRtl="true">
3839

3940
<!--android:permission="android.permission.MANAGE_DOCUMENTS"-->
4041
<provider

app/src/main/java/oly/netpowerctrl/anel/AnelCreateDevice.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package oly.netpowerctrl.anel;
22

3-
import android.content.Context;
43
import android.os.Handler;
54

65
import java.util.List;
@@ -17,13 +16,11 @@
1716
*/
1817
public class AnelCreateDevice implements DeviceObserverResult, DeviceUpdate {
1918
public final Device device;
20-
private final Context context;
2119
public AnelCreateDeviceResult listener = null;
2220
TestStates test_state = TestStates.TEST_INIT;
2321
private DeviceQuery deviceQuery;
2422

25-
public AnelCreateDevice(Device di, Context context) {
26-
this.context = context;
23+
public AnelCreateDevice(Device di) {
2724
if (di == null) {
2825
device = Device.createNewDevice(AnelUDPDeviceDiscoveryThread.anelPlugin.getPluginID());
2926
device.setPluginInterface(AnelUDPDeviceDiscoveryThread.anelPlugin);
@@ -54,6 +51,12 @@ public void onDeviceUpdated(Device updated_device, boolean willBeRemoved) {
5451
if (!updated_device.equalsByUniqueID(device))
5552
return;
5653

54+
if (!updated_device.isReachable()) {
55+
test_state = TestStates.TEST_INIT;
56+
if (listener != null)
57+
listener.testFinished(false);
58+
}
59+
5760
if (test_state == TestStates.TEST_REACHABLE) {
5861
// Update stored device with received values
5962
device.UniqueDeviceID = updated_device.UniqueDeviceID;
@@ -106,6 +109,7 @@ public void onObserverJobFinished(List<Device> timeout_devices) {
106109
}
107110
}
108111

112+
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
109113
public boolean startTest() {
110114
test_state = TestStates.TEST_REACHABLE;
111115

app/src/main/java/oly/netpowerctrl/anel/AnelPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public void configureDeviceScreenClose() {
432432

433433
@Override
434434
public void showConfigureDeviceScreen(Device device) {
435-
anelCreateDevice = new AnelCreateDevice(device, NetpowerctrlApplication.instance);
435+
anelCreateDevice = new AnelCreateDevice(device);
436436
MainActivity.getNavigationController().changeToDialog(MainActivity.instance, AnelDevicePreferences.class.getName());
437437
}
438438

app/src/main/java/oly/netpowerctrl/application_state/LoadStoreData.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class LoadStoreData {
3030
public void scenesSave(SceneCollection scenes) {
3131
Context context = NetpowerctrlApplication.instance;
3232
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
33-
prefs.edit().putString("scenes", scenes.toJSON()).commit();
33+
prefs.edit().putString("scenes", scenes.toJSON()).apply();
3434
}
3535
};
3636

@@ -39,7 +39,7 @@ public void scenesSave(SceneCollection scenes) {
3939
public void groupsSave(GroupCollection groups) {
4040
Context context = NetpowerctrlApplication.instance;
4141
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
42-
prefs.edit().putString("groups", groups.toJSON()).commit();
42+
prefs.edit().putString("groups", groups.toJSON()).apply();
4343
}
4444
};
4545

@@ -48,7 +48,7 @@ public void groupsSave(GroupCollection groups) {
4848
public void devicesSave(DeviceCollection devices) {
4949
Context context = NetpowerctrlApplication.instance;
5050
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
51-
prefs.edit().putString("devices", devices.toJSON()).commit();
51+
prefs.edit().putString("devices", devices.toJSON()).apply();
5252
}
5353
};
5454

@@ -57,7 +57,7 @@ public void devicesSave(DeviceCollection devices) {
5757
public void alarmsSave(TimerController alarms) {
5858
Context context = NetpowerctrlApplication.instance;
5959
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
60-
prefs.edit().putString("alarms", alarms.toJSON()).commit();
60+
prefs.edit().putString("alarms", alarms.toJSON()).apply();
6161
}
6262
};
6363

app/src/main/java/oly/netpowerctrl/device_ports/DevicePortsBaseAdapter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public boolean isShowingHidden() {
114114
return mShowHidden;
115115
}
116116

117-
public void setRemoveAnimation(AnimationController animationController) {
117+
public void setAnimationController(AnimationController animationController) {
118118
mAnimationWeakReference = new WeakReference<>(animationController);
119119
}
120120

@@ -471,9 +471,9 @@ private boolean addItemToGroup(DevicePort devicePort, int command_value, int sta
471471
// If the same DevicePort already exists in this adapter, we will update that instead
472472
if (l.port.uuid.equals(devicePort.uuid)) {
473473
// Animate if value has changed
474-
if (l.command_value != command_value && a != null) {
475-
a.addSmallHighlight(l.id);
476-
}
474+
// if (l.command_value != command_value && a != null) {
475+
// a.addSmallHighlight(l.id);
476+
// }
477477
// Apply new values to existing item
478478
l.command_value = command_value;
479479
l.setPort(devicePort);

app/src/main/java/oly/netpowerctrl/devices/Device.java

+46-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import android.util.JsonWriter;
55

66
import java.io.IOException;
7+
import java.net.InetAddress;
78
import java.util.ArrayList;
9+
import java.util.Collections;
810
import java.util.Iterator;
911
import java.util.List;
1012
import java.util.Map;
@@ -179,11 +181,6 @@ public DeviceConnection getFirstReachableConnection(String protocol) {
179181
return null;
180182
}
181183

182-
public void setReachable(int index) {
183-
DeviceConnections.get(index).setReachable();
184-
compute_first_reachable();
185-
}
186-
187184
/**
188185
* Set all device connections to not reachable, which match the given protocol.
189186
*
@@ -487,12 +484,31 @@ public String getFeatureString() {
487484
return f;
488485
}
489486

487+
public boolean isReachable() {
488+
if (!enabled)
489+
return false;
490+
for (DeviceConnection connection : DeviceConnections) {
491+
if (connection.isReachable())
492+
return true;
493+
}
494+
return false;
495+
}
496+
497+
public void setReachable(int index) {
498+
DeviceConnections.get(index).setReachable();
499+
compute_first_reachable();
500+
}
501+
490502
public String getNotReachableReasons() {
491503
if (!enabled)
492504
return NetpowerctrlApplication.instance.getString(R.string.error_device_disabled);
493505
String f = "";
494-
for (DeviceConnection connection : DeviceConnections)
495-
f += connection.getNotReachableReason() + " ";
506+
for (DeviceConnection connection : DeviceConnections) {
507+
String a = connection.getNotReachableReason();
508+
if (a != null) {
509+
f += a + " ";
510+
}
511+
}
496512
return f;
497513
}
498514

@@ -524,4 +540,27 @@ public void addConnection(DeviceConnection newConnection) {
524540
setReachable(DeviceConnections.size() - 1);
525541
}
526542
}
543+
544+
public InetAddress[] getHostnameIPs() {
545+
List<InetAddress> addresses = new ArrayList<>();
546+
for (DeviceConnection connection : DeviceConnections) {
547+
Collections.addAll(addresses, connection.getHostnameIPs());
548+
}
549+
550+
InetAddress[] a = new InetAddress[addresses.size()];
551+
addresses.toArray(a);
552+
return a;
553+
}
554+
555+
public boolean hasAddress(InetAddress[] hostnameIPs) {
556+
if (hostnameIPs == null || hostnameIPs.length == 0)
557+
return false;
558+
559+
for (DeviceConnection connection : DeviceConnections) {
560+
if (connection.hasAddress(hostnameIPs))
561+
return true;
562+
}
563+
564+
return false;
565+
}
527566
}

app/src/main/java/oly/netpowerctrl/devices/DeviceFeatureFabric.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static DeviceFeature fromJSON(JsonReader reader)
2626

2727
name = reader.nextString();
2828

29-
DeviceFeature deviceFeature = null;
29+
DeviceFeature deviceFeature;
3030

3131
switch (name) {
3232
case DeviceFeatureTemperature.ID: {

app/src/main/java/oly/netpowerctrl/devices/DevicesAutomaticFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void takeNext() {
5353
++current;
5454
textView.append("Check " + device.DeviceName + "...\n");
5555

56-
anelCreateDevice = new AnelCreateDevice(device, getActivity());
56+
anelCreateDevice = new AnelCreateDevice(device);
5757
anelCreateDevice.listener = this;
5858
if (!anelCreateDevice.startTest()) {
5959
textView.append("\tPlugin failed\n");

0 commit comments

Comments
 (0)