Skip to content

Commit

Permalink
Merge pull request #80 from galadril/dev-branch
Browse files Browse the repository at this point in the history
v0.1.151
  • Loading branch information
galadril committed Dec 11, 2015
2 parents 4d6d06f + da86a48 commit 232c65b
Show file tree
Hide file tree
Showing 91 changed files with 1,333 additions and 56 deletions.
44 changes: 44 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,50 @@
android:theme="@style/AppTheme"
tools:replace="android:icon, android:label, android:theme, android:name">

<receiver android:name=".Service.WidgetProviderLarge" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidgetprovider" />
</receiver>

<receiver
android:name=".Service.WidgetIntentReceiver" >
<intent-filter>
<action android:name="nl.hnogames.domoticz.Service.WIDGET_TOGGLE_ACTION" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidgetprovider" />
</receiver>

<receiver
android:name=".Service.BootUpReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidgetprovider" />
</receiver>

<activity android:name=".WidgetConfigurationActivity"
android:label="Domoticz Widget Config">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<activity android:name=".WidgetActionActivity"
android:label="Domoticz Widget Action">
</activity>

<service android:name=".Service.WidgetProviderLarge$UpdateWidgetService"/>

<activity
android:name=".MainActivity"
android:label="@string/app_name_domoticz"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,16 @@ private void setDefaultRowData(DevicesInfo mExtendedStatusInfo,
String.valueOf(mExtendedStatusInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);

if(mExtendedStatusInfo.getUsage()!=null && mExtendedStatusInfo.getUsage().length()>0)
holder.switch_battery_level.setText("Usage: " + mExtendedStatusInfo.getUsage());
if (mExtendedStatusInfo.getCounterToday() != null && mExtendedStatusInfo.getCounterToday().length() > 0)
holder.switch_battery_level.append(" Today: " + mExtendedStatusInfo.getCounterToday());
if (mExtendedStatusInfo.getCounter() != null && mExtendedStatusInfo.getCounter().length() > 0 &&
!mExtendedStatusInfo.getCounter().equals(mExtendedStatusInfo.getData()))
holder.switch_battery_level.append(" Total: " + mExtendedStatusInfo.getCounter());

Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow);
Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow);
holder.iconRow.setAlpha(1f);
if (!mExtendedStatusInfo.getStatusBoolean())
holder.iconRow.setAlpha(0.5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ public void onClick(View view) {
holder.data.append(": " + mUtilitiesInfo.getData());
holder.hardware.append(": " + mUtilitiesInfo.getHardwareName());

if(mUtilitiesInfo.getUsage()!=null && mUtilitiesInfo.getUsage().length()>0)
holder.data.setText("Usage: " + mUtilitiesInfo.getUsage());
if (mUtilitiesInfo.getCounterToday() != null && mUtilitiesInfo.getCounterToday().length() > 0)
holder.data.append(" Today: " + mUtilitiesInfo.getCounterToday());
if (mUtilitiesInfo.getCounter() != null && mUtilitiesInfo.getCounter().length() > 0 &&
!mUtilitiesInfo.getCounter().equals(mUtilitiesInfo.getData()))
holder.data.append(" Total: " + mUtilitiesInfo.getCounter());

holder.dayButton.setId(mUtilitiesInfo.getIdx());
holder.dayButton.setOnClickListener(new View.OnClickListener() {
Expand Down
83 changes: 49 additions & 34 deletions app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,39 @@
import org.json.JSONException;
import org.json.JSONObject;

public class DevicesInfo {
public class DevicesInfo implements Comparable {

private final String UNKNOWN = "Unknown";
private final String TAG = DevicesInfo.class.getSimpleName();
JSONObject jsonObject;
boolean timers;
int idx;
String Name;
String LastUpdate;
long setPoint;
String Type;
String SubType;
int Favorite;
int HardwareID;
String HardwareName;
String TypeImg;
String PlanID;
int batteryLevel;
int maxDimLevel;
int signalLevel;
String status;
int level;
int switchTypeVal;
String switchType;
String CounterToday;
String Data;
String Timers;
boolean statusBoolean;
boolean isProtected;

public DevicesInfo(JSONObject row) throws JSONException {
private JSONObject jsonObject;
private boolean timers;
private int idx;
private String Name;
private String LastUpdate;
private long setPoint;
private String Type;
private String SubType;
private int Favorite;
private int HardwareID;
private String HardwareName;
private String TypeImg;
private String PlanID;
private int batteryLevel;
private int maxDimLevel;
private int signalLevel;
private String status;
private int level;
private int switchTypeVal;
private String switchType;
private String CounterToday;
private String Counter;
private String Usage;
private String Data;
private String Timers;
private boolean statusBoolean;
private boolean isProtected;

public DevicesInfo(JSONObject row) throws JSONException {
this.jsonObject = row;
try {
if (row.has("LevelInt"))
Expand All @@ -72,12 +74,12 @@ public DevicesInfo(JSONObject row) throws JSONException {
maxDimLevel = 1;
}

try {
if (row.has("CounterToday"))
CounterToday = row.getString("CounterToday");
} catch (Exception e) {
CounterToday = "";
}
if (row.has("Counter"))
Counter = row.getString("Counter");
if (row.has("CounterToday"))
CounterToday = row.getString("CounterToday");
if (row.has("Usage"))
Usage = row.getString("Usage");

try {
if (row.has("Status"))
Expand Down Expand Up @@ -171,6 +173,14 @@ public void setFavoriteBoolean(boolean favorite) {
else this.Favorite = 0;
}

public String getCounter() {
return Counter;
}

public String getUsage() {
return Usage;
}

public String getTimers() {
return Timers;
}
Expand Down Expand Up @@ -333,4 +343,9 @@ public int getSwitchTypeVal() {
public String getSwitchType() {
return switchType;
}

@Override
public int compareTo(Object another) {
return this.getName().compareTo(((DevicesInfo)another).getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public LatLng getLocation() {
* @return A Geofence object.
*/
public Geofence toGeofence() {
if(radius<=0)
radius=400;//default

// Build a new Geofence object.
return new Geofence.Builder()
.setRequestId(String.valueOf(id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class UtilitiesInfo {
String HardwareName;
String TypeImg;
String CounterToday;
String Counter;
String Usage;
int signalLevel;

public UtilitiesInfo(JSONObject row) throws JSONException {
Expand All @@ -68,8 +70,12 @@ public UtilitiesInfo(JSONObject row) throws JSONException {
Data = row.getString("Data");
if (row.has("Type"))
Type = row.getString("Type");
if (row.has("Counter"))
Counter = row.getString("Counter");
if (row.has("CounterToday"))
CounterToday = row.getString("CounterToday");
if (row.has("Usage"))
Usage = row.getString("Usage");
if (row.has("SubType"))
SubType = row.getString("SubType");
idx = row.getInt("idx");
Expand Down Expand Up @@ -114,6 +120,14 @@ public String getName() {
return Name;
}

public String getCounter() {
return Counter;
}

public String getUsage() {
return Usage;
}

public void setName(String name) {
Name = name;
}
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/nl/hnogames/domoticz/Domoticz/DevicesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,26 @@ public class DevicesParser implements JSONParserInterface {

private static final String TAG = DevicesParser.class.getSimpleName();
private DevicesReceiver receiver;
private int idx = 999999;

public DevicesParser(DevicesReceiver receiver) {
this.receiver = receiver;
}

public DevicesParser(DevicesReceiver receiver, int idx) {
this.receiver = receiver;
this.idx=idx;
}

private DevicesInfo getDevice(int idx, ArrayList<DevicesInfo> mDevicesInfo) {
for (DevicesInfo s : mDevicesInfo) {
if (s.getIdx() == idx) {
return s;
}
}
return null;
}

@Override
public void parseResult(String result) {

Expand All @@ -58,8 +73,11 @@ public void parseResult(String result) {
}
}

receiver.onReceiveDevices(mDevices);

if(idx == 999999)
receiver.onReceiveDevices(mDevices);
else{
receiver.onReceiveDevice(getDevice(idx, mDevices));
}
} catch (JSONException e) {
Log.e(TAG, "DevicesParser JSON exception");
e.printStackTrace();
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public class Domoticz {
private final PhoneConnectionUtil mPhoneConnectionUtil;
Context mContext;

public void Disconnect(){
if(mPhoneConnectionUtil!=null)
mPhoneConnectionUtil.stopReceiver();
}

public Domoticz(Context mContext) {
this.mContext = mContext;
mSharedPrefUtil = new SharedPrefUtil(mContext);
Expand Down Expand Up @@ -732,6 +737,17 @@ public void getDevices(DevicesReceiver receiver, int plan) {
url);
}

public void getDevice(DevicesReceiver receiver, int idx) {
DevicesParser parser = new DevicesParser(receiver, idx);
String url = constructGetUrl(Json.Url.Request.DEVICES);

RequestUtil.makeJsonGetResultRequest(parser,
getUserCredentials(Authentication.USERNAME),
getUserCredentials(Authentication.PASSWORD),
url);
}


public void getLogs(LogsReceiver receiver) {
LogsParser parser = new LogsParser(receiver);
String url = constructGetUrl(Json.Url.Request.LOG);
Expand Down Expand Up @@ -837,7 +853,10 @@ public int getDrawableIcon(String type, String subtype, boolean state) {
else
return R.drawable.cooling;
case "counter":
return R.drawable.up;
if (subtype != null && subtype.length() > 0 && subtype.equals("P1 Smart Meter"))
return R.drawable.wall;
else
return R.drawable.up;
case "override_mini":
return R.drawable.defaultimage;
case "visibility":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public void onReceiveDevices(ArrayList<DevicesInfo> switches) {
processDevices(switches);
}

@Override
public void onReceiveDevice(DevicesInfo mDevicesInfo) {
}

@Override
public void onError(Exception error) {
errorHandling(error);
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private void updateThermostatSetPointValue(int idx, double newSetPoint) {
break;
}
}

notifyDataSetChanged();
}

Expand All @@ -215,9 +216,16 @@ private void updateThermostatSetPointValue(int idx, double newSetPoint) {
*/
private void notifyDataSetChanged() {
addDebugText("notifyDataSetChanged");
// adapter.notifyDataSetChanged();

// save index and top position
int index = listView.getFirstVisiblePosition();
View v = listView.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();

adapter.notifyDataSetChanged();
listView.setAdapter(adapter);

listView.setSelectionFromTop(index, top);
}

/**
Expand Down Expand Up @@ -292,7 +300,6 @@ public void onThermostatClick(final int idx, int action, double newSetPoint) {
addDebugText("Set idx " + idx + " to " + String.valueOf(newSetPoint));

thermostatSetPointValue = newSetPoint;

int jsonUrl = Domoticz.Json.Url.Set.TEMP;

mDomoticz.setAction(idx, jsonUrl, action, newSetPoint, new setCommandReceiver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import nl.hnogames.domoticz.Containers.DevicesInfo;

public interface DevicesReceiver {

void onReceiveDevices(ArrayList<DevicesInfo> mDevicesInfo);

void onReceiveDevice(DevicesInfo mDevicesInfo);
void onError(Exception error);
}
Loading

0 comments on commit 232c65b

Please sign in to comment.