Skip to content

Commit

Permalink
Merge pull request #136 from galadril/development-branch
Browse files Browse the repository at this point in the history
v0.1.201
  • Loading branch information
galadril committed Dec 28, 2015
2 parents 0791d5d + 4c451b7 commit e6856c3
Show file tree
Hide file tree
Showing 23 changed files with 730 additions and 387 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 45
versionName '0.1.200'
versionCode 46
versionName '0.1.201'
multiDexEnabled true
}

Expand All @@ -23,13 +23,15 @@ android {
productFlavors {
free {
applicationId 'nl.hnogames.domoticz'
resValue "string", "analiticsapikey", "$System.env.GOOGLE_ANALITICS_ID"
resValue "string", "googleapikey", "$System.env.GOOGLE_API_KEY"
resValue "string", "app_name_domoticz", 'Domoticz Lite'
buildConfigField "boolean", "LITE_VERSION", "true"
}

paid {
applicationId 'nl.hnogames.domoticz.premium'
resValue "string", "analiticsapikey", "$System.env.GOOGLE_ANALITICS_ID"
resValue "string", "googleapikey", "$System.env.GOOGLE_API_KEY"
resValue "string", "app_name_domoticz", 'Domoticz'
buildConfigField "boolean", "LITE_VERSION", "false"
Expand Down Expand Up @@ -93,5 +95,7 @@ dependencies {
compile 'com.larswerkman:lobsterpicker:1.0.0'
compile 'com.github.dexafree:materiallist:3.1.2'

compile 'com.github.hotchemi:android-rate:0.5.6'

paidWearApp project(path: ':wear', configuration: 'paidRelease')
}
243 changes: 121 additions & 122 deletions app/src/main/java/nl/hnogames/domoticz/Adapters/SwitchesAdapter.java

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions app/src/main/java/nl/hnogames/domoticz/Containers/SwitchInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public class SwitchInfo {

private static final String UNKNOWN = "Unknown";
private final String TAG = SwitchInfo.class.getSimpleName();
JSONObject jsonObject;
String IsDimmer;
String Name;
String SubType;
String type;
String TypeImg;
int idx;
String Timers;

int switchTypeVal;
String switchType;
private JSONObject jsonObject;
private String IsDimmer;
private String Name;
private String SubType;
private String type;
private String TypeImg;
private int idx;
private String Timers;

private int switchTypeVal;
private String switchType;


public SwitchInfo(JSONObject row) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,12 @@ public void getWeathers(WeatherReceiver receiver) {
url);
}

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

if(filter!=null && filter.length()>0)
url = url.replace("filter=all", "filter="+filter);
if (plan > 0)
url += "&plan=" + plan;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import android.widget.AdapterView;
import android.widget.ListView;

import com.google.android.gms.analytics.Tracker;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -45,6 +47,7 @@
import nl.hnogames.domoticz.R;
import nl.hnogames.domoticz.UI.DeviceInfoDialog;
import nl.hnogames.domoticz.Utils.WidgetUtils;
import nl.hnogames.domoticz.app.AppController;
import nl.hnogames.domoticz.app.DomoticzFragment;

public class Dashboard extends DomoticzFragment implements DomoticzFragmentListener,
Expand Down Expand Up @@ -107,6 +110,7 @@ public void onConnectionOk() {
getActionBar().setTitle(planName + "");

processDashboard();

}

private void processDashboard() {
Expand All @@ -131,7 +135,7 @@ public void onReceiveDevice(DevicesInfo mDevicesInfo) {
public void onError(Exception error) {
errorHandling(error);
}
}, planID);
}, planID,null);
}

private void processDevices(ArrayList<DevicesInfo> devicesInfos) {
Expand Down Expand Up @@ -489,7 +493,7 @@ public void onDimmerChange(int idx, int value) {
@Override
public void onReceiveResult(String result) {
successHandling(result, false);
processDashboard();
//processDashboard();
}

@Override
Expand Down
98 changes: 37 additions & 61 deletions app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@
import java.util.List;

import nl.hnogames.domoticz.Adapters.SwitchesAdapter;
import nl.hnogames.domoticz.Containers.ExtendedStatusInfo;
import nl.hnogames.domoticz.Containers.SwitchInfo;
import nl.hnogames.domoticz.Containers.DevicesInfo;
import nl.hnogames.domoticz.Containers.SwitchLogInfo;
import nl.hnogames.domoticz.Containers.SwitchTimerInfo;
import nl.hnogames.domoticz.Domoticz.Domoticz;
import nl.hnogames.domoticz.Interfaces.DevicesReceiver;
import nl.hnogames.domoticz.Interfaces.DomoticzFragmentListener;
import nl.hnogames.domoticz.Interfaces.StatusReceiver;
import nl.hnogames.domoticz.Interfaces.SwitchLogReceiver;
import nl.hnogames.domoticz.Interfaces.SwitchTimerReceiver;
import nl.hnogames.domoticz.Interfaces.SwitchesReceiver;
import nl.hnogames.domoticz.Interfaces.setCommandReceiver;
import nl.hnogames.domoticz.Interfaces.switchesClickListener;
import nl.hnogames.domoticz.R;
Expand All @@ -71,7 +69,7 @@ public class Switches extends DomoticzFragment implements DomoticzFragmentListen
private SwitchesAdapter adapter;

private CoordinatorLayout coordinatorLayout;
private ArrayList<ExtendedStatusInfo> extendedStatusSwitches;
private ArrayList<DevicesInfo> extendedStatusSwitches;
private SwipeRefreshLayout mSwipeRefreshLayout;

private Parcelable state;
Expand Down Expand Up @@ -118,77 +116,55 @@ private void getSwitchesData() {
WidgetUtils.RefreshWidgets(mContext);
}

mDomoticz.getSwitches(new SwitchesReceiver() {
mDomoticz.getDevices(new DevicesReceiver() {
@Override
public void onReceiveSwitches(ArrayList<SwitchInfo> switches) {
processSwitches(switches);
public void onReceiveDevices(ArrayList<DevicesInfo> mDevicesInfo) {
extendedStatusSwitches=mDevicesInfo;
createListView(mDevicesInfo);
}

@Override
public void onReceiveDevice(DevicesInfo mDevicesInfo) {}

@Override
public void onError(Exception error) {
errorHandling(error);
}
});
}

private void processSwitches(ArrayList<SwitchInfo> switchInfos) {
currentSwitch = 1;//reset values
extendedStatusSwitches = new ArrayList<>();
final int totalNumberOfSwitches = switchInfos.size();

for (SwitchInfo switchInfo : switchInfos) {
successHandling(switchInfo.toString(), false);
int idx = switchInfo.getIdx();

mDomoticz.getStatus(idx, new StatusReceiver() {
@Override
public void onReceiveStatus(ExtendedStatusInfo extendedStatusInfo) {
extendedStatusSwitches.add(extendedStatusInfo); // Add to array
if (currentSwitch == totalNumberOfSwitches) {
createListView(extendedStatusSwitches); // All extended info is in
} else currentSwitch++; // Not there yet
}

@Override
public void onError(Exception error) {
errorHandling(error);
}
});
}
}, 0,"light");
}

// add dynamic list view
// https://github.com/nhaarman/ListViewAnimations
private void createListView(ArrayList<ExtendedStatusInfo> switches) {
private void createListView(ArrayList<DevicesInfo> switches) {
try {
coordinatorLayout = (CoordinatorLayout) getView().findViewById(R.id.coordinatorLayout);

mSwipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh_layout);

ArrayList<ExtendedStatusInfo> supportedSwitches = new ArrayList<>();
ArrayList<DevicesInfo> supportedSwitches = new ArrayList<>();
final List<Integer> appSupportedSwitchesValues = mDomoticz.getSupportedSwitchesValues();
final List<String> appSupportedSwitchesNames = mDomoticz.getSupportedSwitchesNames();

for (ExtendedStatusInfo mExtendedStatusInfo : switches) {
String name = mExtendedStatusInfo.getName();
int switchTypeVal = mExtendedStatusInfo.getSwitchTypeVal();
String switchType = mExtendedStatusInfo.getSwitchType();
for (DevicesInfo mDevicesInfo : switches) {
String name = mDevicesInfo.getName();
int switchTypeVal = mDevicesInfo.getSwitchTypeVal();
String switchType = mDevicesInfo.getSwitchType();

if (!name.startsWith(Domoticz.HIDDEN_CHARACTER) &&
appSupportedSwitchesValues.contains(switchTypeVal) &&
appSupportedSwitchesNames.contains(switchType)) {
if (super.getSort().equals(null) || super.getSort().length() <= 0 || super.getSort().equals(getContext().getString(R.string.sort_all))) {
supportedSwitches.add(mExtendedStatusInfo);
supportedSwitches.add(mDevicesInfo);
} else {
Snackbar.make(coordinatorLayout, "Filter on :" + super.getSort(), Snackbar.LENGTH_SHORT).show();
if ((super.getSort().equals(getContext().getString(R.string.sort_on)) && mExtendedStatusInfo.getStatusBoolean()) && isOnOffSwitch(mExtendedStatusInfo)) {
supportedSwitches.add(mExtendedStatusInfo);
if ((super.getSort().equals(getContext().getString(R.string.sort_on)) && mDevicesInfo.getStatusBoolean()) && isOnOffSwitch(mDevicesInfo)) {
supportedSwitches.add(mDevicesInfo);
}
if ((super.getSort().equals(getContext().getString(R.string.sort_off)) && !mExtendedStatusInfo.getStatusBoolean()) && isOnOffSwitch(mExtendedStatusInfo)) {
supportedSwitches.add(mExtendedStatusInfo);
if ((super.getSort().equals(getContext().getString(R.string.sort_off)) && !mDevicesInfo.getStatusBoolean()) && isOnOffSwitch(mDevicesInfo)) {
supportedSwitches.add(mDevicesInfo);
}
if ((super.getSort().equals(getContext().getString(R.string.sort_static)) ) && !isOnOffSwitch(mExtendedStatusInfo)) {
supportedSwitches.add(mExtendedStatusInfo);
if ((super.getSort().equals(getContext().getString(R.string.sort_static)) ) && !isOnOffSwitch(mDevicesInfo)) {
supportedSwitches.add(mDevicesInfo);
}
}
}
Expand Down Expand Up @@ -224,7 +200,7 @@ public void onRefresh() {
hideProgressDialog();
}

private boolean isOnOffSwitch(ExtendedStatusInfo testSwitch)
private boolean isOnOffSwitch(DevicesInfo testSwitch)
{
switch (testSwitch.getSwitchTypeVal()) {
case Domoticz.Device.Type.Value.ON_OFF:
Expand All @@ -246,7 +222,7 @@ private boolean isOnOffSwitch(ExtendedStatusInfo testSwitch)

return false;
}
private void showInfoDialog(final ExtendedStatusInfo mSwitch) {
private void showInfoDialog(final DevicesInfo mSwitch) {

SwitchInfoDialog infoDialog = new SwitchInfoDialog(
getActivity(),
Expand Down Expand Up @@ -290,7 +266,7 @@ private void showTimerDialog(ArrayList<SwitchTimerInfo> switchLogs) {
}
}

private void changeFavorite(final ExtendedStatusInfo mSwitch, final boolean isFavorite) {
private void changeFavorite(final DevicesInfo mSwitch, final boolean isFavorite) {
addDebugText("changeFavorite");
addDebugText("Set idx " + mSwitch.getIdx() + " favorite to " + isFavorite);

Expand Down Expand Up @@ -387,11 +363,11 @@ public void onError(Exception error) {
@Override
public void onThermostatClick(int idx, int action, double newSetPoint) {}

private ExtendedStatusInfo getSwitch(int idx) {
ExtendedStatusInfo clickedSwitch = null;
for (ExtendedStatusInfo mExtendedStatusInfo : extendedStatusSwitches) {
if (mExtendedStatusInfo.getIdx() == idx) {
clickedSwitch = mExtendedStatusInfo;
private DevicesInfo getSwitch(int idx) {
DevicesInfo clickedSwitch = null;
for (DevicesInfo mDevicesInfo : extendedStatusSwitches) {
if (mDevicesInfo.getIdx() == idx) {
clickedSwitch = mDevicesInfo;
}
}
return clickedSwitch;
Expand All @@ -401,7 +377,7 @@ private ExtendedStatusInfo getSwitch(int idx) {
public void onSwitchClick(int idx, boolean checked) {
addDebugText("onSwitchClick");
addDebugText("Set idx " + idx + " to " + checked);
ExtendedStatusInfo clickedSwitch = getSwitch(idx);
DevicesInfo clickedSwitch = getSwitch(idx);

if (checked)
Snackbar.make(coordinatorLayout, getActivity().getString(R.string.switch_on) + ": " + clickedSwitch.getName(), Snackbar.LENGTH_SHORT).show();
Expand Down Expand Up @@ -440,7 +416,7 @@ public void onError(Exception error) {
public void onButtonClick(int idx, boolean checked) {
addDebugText("onButtonClick");
addDebugText("Set idx " + idx + " to ON");
ExtendedStatusInfo clickedSwitch = getSwitch(idx);
DevicesInfo clickedSwitch = getSwitch(idx);

if (checked)
Snackbar.make(coordinatorLayout, getActivity().getString(R.string.switch_on) + ": " + clickedSwitch.getName(), Snackbar.LENGTH_SHORT).show();
Expand Down Expand Up @@ -473,7 +449,7 @@ public void onError(Exception error) {
public void onBlindClick(int idx, int jsonAction) {
addDebugText("onBlindClick");
addDebugText("Set idx " + idx + " to " + String.valueOf(jsonAction));
ExtendedStatusInfo clickedSwitch = getSwitch(idx);
DevicesInfo clickedSwitch = getSwitch(idx);

if ((jsonAction == Domoticz.Device.Blind.Action.UP || jsonAction == Domoticz.Device.Blind.Action.OFF) && (clickedSwitch.getSwitchTypeVal() != Domoticz.Device.Type.Value.BLINDINVERTED))
Snackbar.make(coordinatorLayout, getActivity().getString(R.string.blind_up) + ": " + clickedSwitch.getName(), Snackbar.LENGTH_SHORT).show();
Expand Down Expand Up @@ -504,7 +480,7 @@ public void onError(Exception error) {
@Override
public void onDimmerChange(int idx, int value) {
addDebugText("onDimmerChange");
ExtendedStatusInfo clickedSwitch = getSwitch(idx);
DevicesInfo clickedSwitch = getSwitch(idx);

Snackbar.make(coordinatorLayout, getContext().getString(R.string.error_level)+": " + clickedSwitch.getName() + " to " + value, Snackbar.LENGTH_SHORT).show();

Expand All @@ -514,7 +490,7 @@ public void onDimmerChange(int idx, int value) {
@Override
public void onReceiveResult(String result) {
successHandling(result, false);
getSwitchesData();
//getSwitchesData();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class GeoSettingsActivity extends AppCompatActivity
private Location currentLocation;
private LocationRequest mLocationRequest;


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
Expand Down Expand Up @@ -128,10 +129,8 @@ protected void onCreate(Bundle savedInstanceState) {
}

mSharedPrefs = new SharedPrefUtil(this);
createLocationRequest();
initSwitches();
createListView();
initSwitches();
}

private void initSwitches() {
Expand Down Expand Up @@ -302,6 +301,7 @@ public void getLocation() {
}

protected void startLocationUpdates() {
createLocationRequest();
LocationServices.FusedLocationApi.requestLocationUpdates(
mApiClient, mLocationRequest, new com.google.android.gms.location.LocationListener() {
@Override
Expand Down Expand Up @@ -401,6 +401,7 @@ private boolean isGooglePlayServicesAvailable() {
@Override
public void onConnected(Bundle bundle) {
setGeoFenceService();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!PermissionsUtil.canAccessLocation(this)) {
requestPermissions(PermissionsUtil.INITIAL_ACCESS_PERMS, PermissionsUtil.INITIAL_ACCESS_REQUEST);
Expand Down
Loading

0 comments on commit e6856c3

Please sign in to comment.