From 909c47d75957718a24fafaca7be1d6bc97758a57 Mon Sep 17 00:00:00 2001 From: galadril Date: Tue, 24 Nov 2015 17:07:43 +0100 Subject: [PATCH] v0.1.138 - #41 App Crashes when removing GeoFence Location - #33 Check Domoticz for updates on boot (and in show in settings screen) - #17 Configure Radius for Geofences - #11 GPS not stopped when losing focus while in the Geofence screen --- .idea/gradle.xml | 9 ++++ app/build.gradle | 4 +- .../domoticz/Adapters/LocationAdapter.java | 3 ++ .../domoticz/Containers/LocationInfo.java | 2 +- .../hnogames/domoticz/Domoticz/Domoticz.java | 43 ++++++++++----- .../domoticz/Domoticz/UpdateParser.java | 42 +++++++++++++++ .../domoticz/Fragments/Preference.java | 14 +++-- .../domoticz/GeoSettingsActivity.java | 29 ---------- .../domoticz/Interfaces/UpdateReceiver.java | 8 +++ .../domoticz/Interfaces/VersionReceiver.java | 2 +- .../nl/hnogames/domoticz/MainActivity.java | 23 ++++++++ .../WearMultiSelectListPreference.java | 51 ++++++++++++++++-- .../Service/WearMessageListenerService.java | 39 +++++++------- .../hnogames/domoticz/UI/LocationDialog.java | 11 ++-- .../hnogames/domoticz/Utils/RequestUtil.java | 46 ++++++++++++++-- .../domoticz/Utils/SharedPrefUtil.java | 29 ++++++---- app/src/main/res/layout/dialog_location.xml | 9 ++++ app/src/main/res/layout/geo_row_location.xml | 11 +++- app/src/main/res/values/strings_dashboard.xml | 1 + app/src/main/res/values/strings_locations.xml | 1 + .../tmp/manifestMerger2789538005431457227.xml | 16 ++++++ .../resources/resources-debug-androidTest.ap_ | Bin 9700 -> 9700 bytes 22 files changed, 301 insertions(+), 92 deletions(-) create mode 100644 app/src/main/java/nl/hnogames/domoticz/Domoticz/UpdateParser.java create mode 100644 app/src/main/java/nl/hnogames/domoticz/Interfaces/UpdateReceiver.java create mode 100644 libs/MemorizingTrustManager/build/intermediates/manifests/tmp/manifestMerger2789538005431457227.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index e66467c..d7ddec9 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -16,6 +16,15 @@ + diff --git a/app/build.gradle b/app/build.gradle index 7defd0c..6044111 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId 'nl.hnogames.domoticz' minSdkVersion 17 targetSdkVersion 23 - versionCode 19 - versionName '0.1.136' + versionCode 21 + versionName '0.1.138' } buildTypes { release { diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java index bfeb155..898511a 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java @@ -73,6 +73,7 @@ public View getView(int position, View convertView, ViewGroup parent) { holder.enable = (CheckBox) convertView.findViewById(R.id.enableSwitch); holder.name = (TextView) convertView.findViewById(R.id.location_name); + holder.radius = (TextView) convertView.findViewById(R.id.location_radius); holder.longitude = (TextView) convertView.findViewById(R.id.location_longitude); holder.latitude = (TextView) convertView.findViewById(R.id.location_latitude); holder.connectedSwitch = (TextView) convertView.findViewById(R.id.location_connectedswitch); @@ -81,6 +82,7 @@ public View getView(int position, View convertView, ViewGroup parent) { holder.name.setText(mLocationInfo.getName()); holder.latitude.setText(context.getString(R.string.latitude) + ": " + mLocationInfo.getLocation().latitude); holder.longitude.setText(context.getString(R.string.longitude) + ": " + mLocationInfo.getLocation().longitude); + holder.radius.setText(context.getString(R.string.radius) + ": " + mLocationInfo.getRange()); if(mLocationInfo.getSwitchidx()>0) holder.connectedSwitch.setText(context.getString(R.string.connectedswitch) + ": " + mLocationInfo.getSwitchidx()); @@ -125,6 +127,7 @@ private void handleEnableChanged(LocationInfo location, boolean enabled) { static class ViewHolder { TextView name; TextView latitude; + TextView radius; TextView longitude; TextView connectedSwitch; CheckBox enable; diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java index 9d62bea..3d753f0 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java +++ b/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java @@ -13,7 +13,7 @@ public class LocationInfo { boolean enabled = false; - public LocationInfo(int i, String n, LatLng l) { + public LocationInfo(int i, String n, LatLng l, int radius) { this.Name = n; this.Location = l; this.id = i; diff --git a/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java b/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java index 416c4a9..0b54967 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java +++ b/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java @@ -28,6 +28,7 @@ import nl.hnogames.domoticz.Interfaces.SwitchTimerReceiver; import nl.hnogames.domoticz.Interfaces.SwitchesReceiver; import nl.hnogames.domoticz.Interfaces.TemperatureReceiver; +import nl.hnogames.domoticz.Interfaces.UpdateReceiver; import nl.hnogames.domoticz.Interfaces.UtilitiesReceiver; import nl.hnogames.domoticz.Interfaces.VersionReceiver; import nl.hnogames.domoticz.Interfaces.WeatherReceiver; @@ -301,6 +302,10 @@ private String getJsonGetUrl(int jsonGetUrl) { url = Url.Category.SWITCHTIMER; break; + case Json.Url.Request.UPDATE: + url = Url.System.UPDATE; + break; + default: throw new NullPointerException("getJsonGetUrl: No known JSON URL specified"); } @@ -513,10 +518,19 @@ public void getVersion(VersionReceiver receiver) { url); } + public void getUpdate(UpdateReceiver receiver) { + UpdateParser parser = new UpdateParser(receiver); + String url = constructGetUrl(Json.Url.Request.UPDATE); + RequestUtil.makeJsonGetRequest(parser, + getUserCredentials(Authentication.USERNAME), + getUserCredentials(Authentication.PASSWORD), + url); + } + public void getScenes(ScenesReceiver receiver) { ScenesParser parser = new ScenesParser(receiver); String url = constructGetUrl(Json.Url.Request.SCENES); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -526,7 +540,7 @@ public void getScenes(ScenesReceiver receiver) { public void getPlans(PlansReceiver receiver) { PlanParser parser = new PlanParser(receiver); String url = constructGetUrl(Json.Url.Request.PLANS); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -537,7 +551,7 @@ public void getCameras(CameraReceiver receiver) { CameraParser parser = new CameraParser(receiver); String url = constructGetUrl(Json.Url.Request.CAMERAS); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -547,7 +561,7 @@ public void getCameras(CameraReceiver receiver) { public void getSwitches(SwitchesReceiver switchesReceiver) { SwitchesParser parser = new SwitchesParser(switchesReceiver); String url = constructGetUrl(Json.Url.Request.SWITCHES); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -559,7 +573,7 @@ public void getSwitchLogs(int idx, SwitchLogReceiver switchesReceiver) { logger("for idx: " + String.valueOf(idx)); String url = constructGetUrl(Json.Url.Request.SWITCHLOG) + String.valueOf(idx); ; - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -571,7 +585,7 @@ public void getSwitchTimers(int idx, SwitchTimerReceiver switchesReceiver) { logger("for idx: " + String.valueOf(idx)); String url = constructGetUrl(Json.Url.Request.SWITCHTIMER) + String.valueOf(idx); ; - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -597,7 +611,7 @@ public void getStatus(int idx, StatusReceiver receiver) { String url = constructGetUrl(Json.Get.STATUS) + String.valueOf(idx); logger("for idx: " + String.valueOf(idx)); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -607,7 +621,7 @@ public void getStatus(int idx, StatusReceiver receiver) { public void getUtilities(UtilitiesReceiver receiver) { UtilitiesParser parser = new UtilitiesParser(receiver); String url = constructGetUrl(Json.Url.Request.UTILITIES); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -617,7 +631,7 @@ public void getUtilities(UtilitiesReceiver receiver) { public void getTemperatures(TemperatureReceiver receiver) { TemperaturesParser parser = new TemperaturesParser(receiver); String url = constructGetUrl(Json.Url.Request.TEMPERATURE); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -627,7 +641,7 @@ public void getTemperatures(TemperatureReceiver receiver) { public void getWeathers(WeatherReceiver receiver) { WeatherParser parser = new WeatherParser(receiver); String url = constructGetUrl(Json.Url.Request.WEATHER); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -641,7 +655,7 @@ public void getDevices(DevicesReceiver receiver, int plan) { if (plan > 0) url += "&plan=" + plan; - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -651,7 +665,7 @@ public void getDevices(DevicesReceiver receiver, int plan) { public void getLogs(LogsReceiver receiver) { LogsParser parser = new LogsParser(receiver); String url = constructGetUrl(Json.Url.Request.LOG); - RequestUtil.makeJsonGetRequest(parser, + RequestUtil.makeJsonGetResultRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), url, @@ -856,6 +870,7 @@ interface Request { int LOG = 13; int SWITCHLOG = 14; int SWITCHTIMER = 15; + int UPDATE = 16; } interface Set { @@ -956,6 +971,10 @@ interface Log { interface Security { String GET = "/json.htm?type=command¶m=getsecstatus"; } + + interface System { + String UPDATE = "/json.htm?type=command¶m=checkforupdate&forced=true"; + } } private interface FavoriteAction { diff --git a/app/src/main/java/nl/hnogames/domoticz/Domoticz/UpdateParser.java b/app/src/main/java/nl/hnogames/domoticz/Domoticz/UpdateParser.java new file mode 100644 index 0000000..e8e79e5 --- /dev/null +++ b/app/src/main/java/nl/hnogames/domoticz/Domoticz/UpdateParser.java @@ -0,0 +1,42 @@ +package nl.hnogames.domoticz.Domoticz; + +import android.util.Log; + +import org.json.JSONException; +import org.json.JSONObject; + +import nl.hnogames.domoticz.Interfaces.JSONParserInterface; +import nl.hnogames.domoticz.Interfaces.UpdateReceiver; +import nl.hnogames.domoticz.Interfaces.VersionReceiver; + +public class UpdateParser implements JSONParserInterface { + + private static final String TAG = UpdateParser.class.getSimpleName(); + private UpdateReceiver receiver; + + public UpdateParser(UpdateReceiver receiver) { + this.receiver = receiver; + } + + @Override + public void parseResult(String result) { + try { + JSONObject response = new JSONObject(result); + String version = ""; + if(response.has("revision")) + version= response.getString("revision"); + if(response.has("HaveUpdate") && !response.getBoolean("HaveUpdate")) + version= ""; + + receiver.onReceiveUpdate(version); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception error) { + Log.e(TAG, "VersionParser of JSONParserInterface exception"); + receiver.onError(error); + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java index 64a618f..d72f52c 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java @@ -87,20 +87,24 @@ private void setVersionInfo() { domoticz.getVersion(new VersionReceiver() { @Override public void onReceiveVersion(String version) { - domoticzversion.setSummary(version); + try { + String sVersion = version; + String sUpdateVersion = mSharedPrefs.getUpdateAvailable(); + if (sUpdateVersion != null && sUpdateVersion.length() > 0) + sVersion += " " + getString(R.string.update_available) + ": " + sUpdateVersion; + + domoticzversion.setSummary(sVersion); + } + catch(Exception ex){} } - @Override public void onError(Exception error) {} }); } private void setStartUpScreenDefaultValue() { - int defaultValue = mSharedPrefs.getStartupScreenIndex(); - ListPreference startup_screen = (ListPreference) findPreference("startup_screen"); startup_screen.setValueIndex(defaultValue); - } } \ No newline at end of file diff --git a/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java b/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java index 4d6802d..465c043 100644 --- a/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java +++ b/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java @@ -294,10 +294,8 @@ public void getLocation(String usedLocationService) { return; } //locationManager.requestLocationUpdates(usedLocationService, 0, 0, this); - Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); setMarker(new LatLng(location.getLatitude(), location.getLongitude())); - } private void setMarker(LatLng currentLatLng) { @@ -332,7 +330,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - public void showAddLocationDialog() { LocationDialog infoDialog = new LocationDialog( this, @@ -368,27 +365,6 @@ public void onDismissEmpty() { }); infoDialog.show(); } -/* - @Override - public void onLocationChanged(Location location) { - Log.d("Location Found", location.getLatitude() + " " + location.getLongitude()); - } - - @Override - public void onProviderDisabled(String provider) { - Log.d(TAG, "Disabled: " + provider); - } - - @Override - public void onProviderEnabled(String provider) { - Log.d(TAG, "Enabled: " + provider); - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - Log.d(TAG, "Status: " + status); - } -*/ /** * Checks if Google Play services is available. @@ -424,11 +400,6 @@ public void onConnected(Bundle bundle) { public void setGeoFenceService() { if (mGeofenceList != null && mGeofenceList.size() > 0) { - /*LocationServices.GeofencingApi.removeGeofences( - mApiClient, - getGeofenceTransitionPendingIntent() - );*/ - mGeofenceRequestIntent = getGeofenceTransitionPendingIntent(); LocationServices.GeofencingApi .addGeofences(mApiClient, mGeofenceList, mGeofenceRequestIntent); diff --git a/app/src/main/java/nl/hnogames/domoticz/Interfaces/UpdateReceiver.java b/app/src/main/java/nl/hnogames/domoticz/Interfaces/UpdateReceiver.java new file mode 100644 index 0000000..0474ada --- /dev/null +++ b/app/src/main/java/nl/hnogames/domoticz/Interfaces/UpdateReceiver.java @@ -0,0 +1,8 @@ +package nl.hnogames.domoticz.Interfaces; + +public interface UpdateReceiver { + + void onReceiveUpdate(String version); + void onError(Exception error); + +} diff --git a/app/src/main/java/nl/hnogames/domoticz/Interfaces/VersionReceiver.java b/app/src/main/java/nl/hnogames/domoticz/Interfaces/VersionReceiver.java index bb10383..38a94ac 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Interfaces/VersionReceiver.java +++ b/app/src/main/java/nl/hnogames/domoticz/Interfaces/VersionReceiver.java @@ -3,6 +3,6 @@ public interface VersionReceiver { void onReceiveVersion(String version); - void onError(Exception error); + } diff --git a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java index 74ce3b2..66b6b0d 100644 --- a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java +++ b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java @@ -23,10 +23,13 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ListView; +import android.widget.Toast; import java.util.List; import nl.hnogames.domoticz.Adapters.NavigationAdapter; +import nl.hnogames.domoticz.Domoticz.Domoticz; +import nl.hnogames.domoticz.Interfaces.UpdateReceiver; import nl.hnogames.domoticz.Utils.SharedPrefUtil; import nl.hnogames.domoticz.Welcome.WelcomeViewActivity; import nl.hnogames.domoticz.app.DomoticzCardFragment; @@ -78,6 +81,26 @@ private void buildScreen() if (mSharedPrefs.isWelcomeWizardSuccess()) { addDrawerItems(); addFragment(); + + //get latest update version + Domoticz domoticz = new Domoticz(this); + domoticz.getUpdate(new UpdateReceiver() { + @Override + public void onReceiveUpdate(String version) { + if(version!=null && version.length()>0) { + String prefVersion = mSharedPrefs.getUpdateAvailable(); + if (!prefVersion.equals(version)) { + Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.update_available) + ": " + version, Toast.LENGTH_SHORT).show(); + } + } + mSharedPrefs.setUpdateAvailable(version); + } + + @Override + public void onError(Exception error) { + Toast.makeText(MainActivity.this, "Could not check for updates:"+error.getMessage(), Toast.LENGTH_SHORT).show(); + } + }); } else { Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class); startActivityForResult(welcomeWizard, iWelcomeResultCode); diff --git a/app/src/main/java/nl/hnogames/domoticz/Preference/WearMultiSelectListPreference.java b/app/src/main/java/nl/hnogames/domoticz/Preference/WearMultiSelectListPreference.java index 9b2710a..07048a7 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Preference/WearMultiSelectListPreference.java +++ b/app/src/main/java/nl/hnogames/domoticz/Preference/WearMultiSelectListPreference.java @@ -5,14 +5,17 @@ import android.content.res.TypedArray; import android.preference.MultiSelectListPreference; import android.util.AttributeSet; +import android.util.Log; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import nl.hnogames.domoticz.Containers.ExtendedStatusInfo; import nl.hnogames.domoticz.Containers.SwitchInfo; import nl.hnogames.domoticz.Domoticz.Domoticz; +import nl.hnogames.domoticz.Interfaces.StatusReceiver; import nl.hnogames.domoticz.Interfaces.SwitchesReceiver; import nl.hnogames.domoticz.R; @@ -37,11 +40,52 @@ public WearMultiSelectListPreference(Context context, AttributeSet attrs) { initSwitches(); } + private ArrayList extendedStatusSwitches; + private int currentSwitch = 1; + private void initSwitches () { + extendedStatusSwitches = new ArrayList<>(); + currentSwitch = 1; mDomoticz.getSwitches(new SwitchesReceiver() { @Override public void onReceiveSwitches(ArrayList switches) { - processSwitches(switches); + for (SwitchInfo switchInfo : switches) { + int idx = switchInfo.getIdx(); + final int totalNumberOfSwitches = switches.size(); + + mDomoticz.getStatus(idx, new StatusReceiver() { + @Override + public void onReceiveStatus(ExtendedStatusInfo extendedStatusInfo) { + extendedStatusSwitches.add(extendedStatusInfo); + if (currentSwitch == totalNumberOfSwitches) { + { + final List appSupportedSwitchesValues = mDomoticz.getWearSupportedSwitchesValues(); + final List appSupportedSwitchesNames = mDomoticz.getWearSupportedSwitchesNames(); + ArrayList supportedSwitches = new ArrayList<>(); + + for (ExtendedStatusInfo mExtendedStatusInfo : extendedStatusSwitches) { + String name = mExtendedStatusInfo.getName(); + int switchTypeVal = mExtendedStatusInfo.getSwitchTypeVal(); + String switchType = mExtendedStatusInfo.getSwitchType(); + if (!name.startsWith(Domoticz.HIDDEN_CHARACTER) && + appSupportedSwitchesValues.contains(switchTypeVal) && + appSupportedSwitchesNames.contains(switchType)) { + supportedSwitches.add(mExtendedStatusInfo); + } + } + + if(supportedSwitches.size()>0) + processSwitches(supportedSwitches); + } + } else currentSwitch++; // Not there yet + } + + @Override + public void onError(Exception error) { + Log.e(TAG, error.getMessage()); + } + }); + } } @Override @@ -49,7 +93,8 @@ public void onError(Exception error) {} }); } - private void processSwitches (ArrayList switches) { + + private void processSwitches (ArrayList switches) { mEntries = getEntries(); mEntryValues = getEntryValues(); @@ -57,7 +102,7 @@ private void processSwitches (ArrayList switches) { List entries = new ArrayList<>(); List entryValues = new ArrayList<>(); - for(SwitchInfo s:switches) + for(ExtendedStatusInfo s:switches) { entryValues.add(s.getIdx()+""); entries.add(s.getIdx()+ " - " +s.getName()); diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java b/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java index 50b35de..c0ad894 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java +++ b/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java @@ -122,25 +122,26 @@ private void getSwitches() { domoticz.getSwitches(new SwitchesReceiver() { @Override public void onReceiveSwitches(ArrayList switches) { - for (SwitchInfo switchInfo : switches) { - int idx = switchInfo.getIdx(); - final int totalNumberOfSwitches = switches.size(); - - domoticz.getStatus(idx, new StatusReceiver() { - @Override - public void onReceiveStatus(ExtendedStatusInfo extendedStatusInfo) { - extendedStatusSwitches.add(extendedStatusInfo); // Add to array - if (currentSwitch == totalNumberOfSwitches) { - processAllSwitches(extendedStatusSwitches); // All extended info is in - } else currentSwitch++; // Not there yet - } - - @Override - public void onError(Exception error) { - Log.e(TAG, error.getMessage()); - } - }); - } + if(switches!=null) + for (SwitchInfo switchInfo : switches) { + int idx = switchInfo.getIdx(); + final int totalNumberOfSwitches = switches.size(); + + domoticz.getStatus(idx, new StatusReceiver() { + @Override + public void onReceiveStatus(ExtendedStatusInfo extendedStatusInfo) { + extendedStatusSwitches.add(extendedStatusInfo); // Add to array + if (currentSwitch == totalNumberOfSwitches) { + processAllSwitches(extendedStatusSwitches); // All extended info is in + } else currentSwitch++; // Not there yet + } + + @Override + public void onError(Exception error) { + Log.e(TAG, error.getMessage()); + } + }); + } } @Override diff --git a/app/src/main/java/nl/hnogames/domoticz/UI/LocationDialog.java b/app/src/main/java/nl/hnogames/domoticz/UI/LocationDialog.java index 66bf565..5fe1bd1 100644 --- a/app/src/main/java/nl/hnogames/domoticz/UI/LocationDialog.java +++ b/app/src/main/java/nl/hnogames/domoticz/UI/LocationDialog.java @@ -29,6 +29,7 @@ public class LocationDialog implements DialogInterface.OnDismissListener { private FloatingLabelEditText editName; private EditText txtLatitude; private EditText txtLongitude; + private EditText txtRadius; private DismissListener dismissListener; @@ -57,11 +58,11 @@ else if (foundLocation == null) if (dismissListener != null) dismissListener.onDismiss(new LocationInfo(new Random().nextInt(999999), editName.getInputWidgetText().toString(), new LatLng(Double.parseDouble(txtLatitude.getText().toString().replace(mContext.getString(R.string.latitude) + ": ", "")), - Double.parseDouble(txtLongitude.getText().toString().replace(mContext.getString(R.string.longitude) + ": ", ""))))); - + Double.parseDouble(txtLongitude.getText().toString().replace(mContext.getString(R.string.longitude) + ": ", ""))), + Integer.parseInt(txtRadius.getText().toString().replace(mContext.getString(R.string.radius) + ": ", "")))); } catch(Exception ex){ if (dismissListener != null) - dismissListener.onDismiss(new LocationInfo(new Random().nextInt(999999), editName.getInputWidgetText().toString(), foundLocation)); + dismissListener.onDismiss(new LocationInfo(new Random().nextInt(999999), editName.getInputWidgetText().toString(), foundLocation, 120)); } } } @@ -75,10 +76,11 @@ public void show() { Button getLocation = (Button) view.findViewById(R.id.get_address); txtLatitude = (EditText)view.findViewById(R.id.latitude); + txtRadius = (EditText)view.findViewById(R.id.radius); + txtRadius.setText(mContext.getString(R.string.radius )+ ": 120"); txtLongitude = (EditText)view.findViewById(R.id.longitude); editAddress = (FloatingLabelEditText)view.findViewById(R.id.address); editName = (FloatingLabelEditText)view.findViewById(R.id.name); - getLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -117,7 +119,6 @@ public LatLng getLocationFromAddress(Context context,String strAddress) { return p1; } - @Override public void onDismiss(DialogInterface dialog) { if (dismissListener != null) diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/RequestUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/RequestUtil.java index dd34bbd..af13956 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Utils/RequestUtil.java +++ b/app/src/main/java/nl/hnogames/domoticz/Utils/RequestUtil.java @@ -69,14 +69,50 @@ public Map getHeaders() throws AuthFailureError { AppController.getInstance().addToRequestQueue(jsonObjReq); } + public static void makeJsonGetRequest(@Nullable final JSONParserInterface parser, + final String username, + final String password, + String url) { + + JsonObjectRequest jsonObjReq = + new JsonObjectRequest(Request.Method.GET, + url, new Response.Listener() { + + @Override + public void onResponse(JSONObject response) { + if (parser != null) + parser.parseResult(response.toString()); + } + }, new Response.ErrorListener() { + + @Override + public void onErrorResponse(VolleyError volleyError) { + errorHandling(volleyError); + if (parser != null) parser.onError(volleyError); + } + }) { + + @Override + // HTTP basic authentication + // Taken from: http://blog.lemberg.co.uk/volley-part-1-quickstart + public Map getHeaders() throws AuthFailureError { + return createBasicAuthHeader(username, password); + } + + }; + + // Adding request to request queue + AppController.getInstance().addToRequestQueue(jsonObjReq); + } + /** * Method to get json object request where json response starts with { */ - public static void makeJsonGetRequest(@Nullable final JSONParserInterface parser, - final String username, - final String password, - String url, - Boolean secure) { + public static void makeJsonGetResultRequest(@Nullable final JSONParserInterface parser, + final String username, + final String password, + String url, + Boolean secure) { if (secure) { diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java index d536411..ad20975 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java +++ b/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java @@ -33,7 +33,7 @@ public class SharedPrefUtil { public static final String PREF_CUSTOM_WEAR = "enablewearitems"; public static final String PREF_CUSTOM_WEAR_ITEMS = "wearitems"; - + public static final String PREF_UPDATE_VERSION = "updateversion"; public static final String PREF_EXTRA_DATA = "extradata"; public static final String PREF_STARTUP_SCREEN = "startup_screen"; public static final String PREF_NAVIGATION_ITEMS = "enable_items"; @@ -43,8 +43,10 @@ public class SharedPrefUtil { public static final String PREF_DEBUGGING = "debugging"; private static final String PREF_FIRST_START = "isFirstStart"; private static final String PREF_WELCOME_SUCCESS = "welcomeSuccess"; + private static final String http = "http://"; private static final String https = "https://"; + private static final String REMOTE_SERVER_USERNAME = "remote_server_username"; private static final String REMOTE_SERVER_PASSWORD = "remote_server_password"; private static final String REMOTE_SERVER_URL = "remote_server_url"; @@ -52,6 +54,7 @@ public class SharedPrefUtil { private static final String REMOTE_SERVER_SECURE = "remote_server_secure"; private static final String REMOTE_SERVER_AUTHENTICATION_METHOD = "remote_server_authentication_method"; + private static final String IS_LOCAL_SERVER_ADDRESS_DIFFERENT = "local_server_different_address"; private static final String LOCAL_SERVER_USERNAME = "local_server_username"; private static final String LOCAL_SERVER_PASSWORD = "local_server_password"; @@ -60,12 +63,14 @@ public class SharedPrefUtil { private static final String LOCAL_SERVER_SECURE = "local_server_secure"; private static final String LOCAL_SERVER_AUTHENTICATION_METHOD = "local_server_authentication_method"; + private static final String LOCAL_SERVER_SSID = "local_server_ssid"; Context mContext; SharedPreferences prefs; SharedPreferences.Editor editor; + public SharedPrefUtil(Context mContext) { this.mContext = mContext; prefs = PreferenceManager.getDefaultSharedPreferences(mContext); @@ -260,6 +265,14 @@ public void setDomoticzRemotePassword(String password) { editor.putString(REMOTE_SERVER_PASSWORD, password).apply(); } + public void setUpdateAvailable(String version) { + editor.putString(PREF_UPDATE_VERSION, version).apply(); + } + + public String getUpdateAvailable() { + return prefs.getString(PREF_UPDATE_VERSION, ""); + } + public String getDomoticzRemoteUrl() { return prefs.getString(REMOTE_SERVER_URL, ""); } @@ -401,7 +414,6 @@ public void setLocalSsid(List ssids) { * Method for setting local server addresses the same as the remote server addresses */ public void setLocalSameAddressAsRemote() { - setDomoticzLocalUsername(getDomoticzRemoteUsername()); setDomoticzLocalPassword(getDomoticzRemotePassword()); setDomoticzLocalUrl(getDomoticzRemoteUrl()); @@ -418,12 +430,9 @@ public void saveLocations(Context context, List locations) { editor.commit(); } - - public ArrayList getLocations(Context context) { SharedPreferences settings; List locations; - if (prefs.contains(PREF_GEOFENCE_LOCATIONS)) { String jsonLocations = prefs.getString(PREF_GEOFENCE_LOCATIONS, null); Gson gson = new Gson(); @@ -439,7 +448,6 @@ public ArrayList getLocations(Context context) { public LocationInfo getLocation(Context context, int id) { List locations = getLocations(context); - for(LocationInfo l: locations) { if(l.getID() == id) @@ -449,7 +457,6 @@ public LocationInfo getLocation(Context context, int id) { return null; } - public void addLocation(Context context, LocationInfo location) { List locations = getLocations(context); if (locations == null) @@ -472,17 +479,21 @@ public void updateLocation(Context context, LocationInfo location) { } i++; } - saveLocations(context, locations); } public void removeLocation(Context context, LocationInfo location) { ArrayList locations = getLocations(context); + ArrayList removelocations = new ArrayList<>(); if (locations != null) { for (LocationInfo l : locations) { if (l.getID() == location.getID()) - locations.remove(l); + removelocations.add(l); } + for (LocationInfo l : removelocations) { + locations.remove(l); + } + saveLocations(context, locations); } } diff --git a/app/src/main/res/layout/dialog_location.xml b/app/src/main/res/layout/dialog_location.xml index 5c0c057..c2b17c9 100644 --- a/app/src/main/res/layout/dialog_location.xml +++ b/app/src/main/res/layout/dialog_location.xml @@ -39,6 +39,15 @@ android:background="@drawable/button_status" android:text="@string/getlocation" /> + + + + +