From e4de46b5832042e2e0a60f2c17c02b334ac776de Mon Sep 17 00:00:00 2001
From: Przemek Zygmunt
Date: Fri, 28 Jun 2019 12:04:41 +0200
Subject: [PATCH 1/4] Set token more thread safe
---
.../android/restapi/SuplaRestApiClientTask.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/org/supla/android/restapi/SuplaRestApiClientTask.java b/app/src/main/java/org/supla/android/restapi/SuplaRestApiClientTask.java
index e90fded37..e6b83db79 100644
--- a/app/src/main/java/org/supla/android/restapi/SuplaRestApiClientTask.java
+++ b/app/src/main/java/org/supla/android/restapi/SuplaRestApiClientTask.java
@@ -55,7 +55,7 @@ public abstract class SuplaRestApiClientTask extends AsyncTask {
private Context _context;
private int ChannelId = 0;
private long ActivityTime = 0;
- private SuplaOAuthToken Token;
+ private SuplaOAuthToken mToken;
private DbHelper MDbH = null;
private DbHelper DbH = null;
private IAsyncResults delegate;
@@ -74,7 +74,7 @@ public interface IAsyncResults {
@Override
protected void onPreExecute() {
super.onPreExecute();
- Token = SuplaApp.getApp().RegisterRestApiClientTask(this);
+ setToken(SuplaApp.getApp().RegisterRestApiClientTask(this));
if (delegate!=null) {
delegate.onRestApiTaskStarted(this);
@@ -127,12 +127,16 @@ public void setDelegate(IAsyncResults delegate) {
}
public synchronized void setToken(SuplaOAuthToken token) {
- Token = token == null ? null : new SuplaOAuthToken(token);
+ mToken = token == null ? null : new SuplaOAuthToken(token);
notify();
}
+ public synchronized SuplaOAuthToken getToken() {
+ return new SuplaOAuthToken(mToken);
+ }
+
public synchronized SuplaOAuthToken getTokenWhenIsAlive() {
- return Token != null && Token.isAlive() ? new SuplaOAuthToken(Token) : null;
+ return mToken != null && mToken.isAlive() ? getToken() : null;
}
public synchronized boolean isAlive(int timeout) {
@@ -144,6 +148,8 @@ public synchronized void keepAlive() {
}
private void makeTokenRequest() {
+
+ SuplaOAuthToken Token = getToken();
if (Token != null && Token.isAlive()) return;
SuplaClient client = SuplaApp.getApp().getSuplaClient();
@@ -208,6 +214,8 @@ public int getTotalCount() {
private ApiRequestResult apiRequest(boolean retry, String endpint) {
makeTokenRequest();
+ SuplaOAuthToken Token = getToken();
+
if (Token == null) {
Trace.d(log_tag, "Token == null");
return null;
From 5fca80aedd22e1192c151de7bc6475a4b75fb0d4 Mon Sep 17 00:00:00 2001
From: Przemek Zygmunt
Date: Sat, 29 Jun 2019 15:13:42 +0200
Subject: [PATCH 2/4] Store the last oauth token globally
---
app/src/main/java/org/supla/android/SuplaApp.java | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/app/src/main/java/org/supla/android/SuplaApp.java b/app/src/main/java/org/supla/android/SuplaApp.java
index 47438e19b..3127ffd68 100644
--- a/app/src/main/java/org/supla/android/SuplaApp.java
+++ b/app/src/main/java/org/supla/android/SuplaApp.java
@@ -41,7 +41,8 @@ public class SuplaApp extends Application {
private static SuplaClient _SuplaClient = null;
private static SuplaApp _SuplaApp = null;
- ArrayList _RestApiClientTasks = new ArrayList();
+ private SuplaOAuthToken _OAuthToken;
+ private ArrayList _RestApiClientTasks = new ArrayList();
private Handler _sc_msg_handler = new Handler() {
@Override
@@ -53,8 +54,9 @@ public void handleMessage(Message msg) {
if (_msg.getType() == SuplaClientMsg.onOAuthTokenRequestResult) {
synchronized (_lck3) {
+ _OAuthToken = _msg.getOAuthToken();
for(int a = 0; a< _RestApiClientTasks.size(); a++) {
- _RestApiClientTasks.get(a).setToken(_msg.getOAuthToken());
+ _RestApiClientTasks.get(a).setToken(_OAuthToken);
}
}
}
@@ -161,11 +163,8 @@ public static void Vibrate(Context context) {
public SuplaOAuthToken RegisterRestApiClientTask(SuplaRestApiClientTask task) {
SuplaOAuthToken result = null;
synchronized (_lck3) {
- for(int a = 0; a< _RestApiClientTasks.size(); a++) {
- result = _RestApiClientTasks.get(a).getTokenWhenIsAlive();
- if (result!=null) {
- break;
- }
+ if (_OAuthToken != null && _OAuthToken.isAlive()) {
+ result = new SuplaOAuthToken(_OAuthToken);
}
_RestApiClientTasks.add(task);
From 0f2125a041ff3bbf9b35722c939af7ffb57072d3 Mon Sep 17 00:00:00 2001
From: Przemek Zygmunt
Date: Sun, 30 Jun 2019 11:12:46 +0200
Subject: [PATCH 3/4] Copy the total cost to the current cost if the current
month is the first month of measurement.
---
app/src/main/java/org/supla/android/ChannelDetailEM.java | 7 +++++--
app/src/main/java/org/supla/android/ChannelDetailIC.java | 5 ++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/org/supla/android/ChannelDetailEM.java b/app/src/main/java/org/supla/android/ChannelDetailEM.java
index bf6faeb39..6422a1d34 100644
--- a/app/src/main/java/org/supla/android/ChannelDetailEM.java
+++ b/app/src/main/java/org/supla/android/ChannelDetailEM.java
@@ -345,25 +345,28 @@ public void channelExtendedDataToViews(boolean setIcon) {
SuplaChannelElectricityMeterValue.Summary sum = em.getSummary();
double currentConsumption = 0;
+ double currentCost = 0;
DbHelper mDBH = new DbHelper(getContext(), true);
if (mDBH.electricityMeterMeasurementsStartsWithTheCurrentMonth(channel.getChannelId())) {
currentConsumption = sum.getTotalForwardActiveEnergy();
+ currentCost = em.getTotalCost();
} else {
double v0 = mDBH.getLastElectricityMeterMeasurementValue(0,
channel.getChannelId());
double v1 = mDBH.getLastElectricityMeterMeasurementValue(-1,
channel.getChannelId());
currentConsumption = v0-v1;
+ currentCost = currentConsumption * em.getPricePerUnit();
}
tvTotalForwardActiveEnergy
.setText(getActiveEnergyFormattedString(sum.getTotalForwardActiveEnergy()));
+ tvTotalCost.setText(String.format("%.2f "+em.getCurrency(), em.getTotalCost()));
tvCurrentConsumption.setText(String.format("%.2f kWh", currentConsumption));
tvCurrentCost.setText(String.format("%.2f "+em.getCurrency(),
- currentConsumption * em.getPricePerUnit()));
- tvTotalCost.setText(String.format("%.2f "+em.getCurrency(), em.getTotalCost()));
+ currentCost));
SuplaChannelElectricityMeterValue.Measurement m = em.getMeasurement(phase, 0);
if (m!= null) {
diff --git a/app/src/main/java/org/supla/android/ChannelDetailIC.java b/app/src/main/java/org/supla/android/ChannelDetailIC.java
index add2c4e37..69e508e88 100644
--- a/app/src/main/java/org/supla/android/ChannelDetailIC.java
+++ b/app/src/main/java/org/supla/android/ChannelDetailIC.java
@@ -150,19 +150,22 @@ private void channelExtendedDataToViews(boolean setIcon) {
SuplaChannelImpulseCounterValue ic = cev.getExtendedValue().ImpulseCounterValue;
double currentConsumption = 0;
+ double currentCost = 0;
if (mDBH.impulseCounterMeasurementsStartsWithTheCurrentMonth(channel.getChannelId())) {
currentConsumption = ic.getCalculatedValue();
+ currentCost = ic.getTotalCost();
} else {
double v0 = mDBH.getLastImpulseCounterMeasurementValue(0,
channel.getChannelId());
double v1 = mDBH.getLastImpulseCounterMeasurementValue(-1,
channel.getChannelId());
currentConsumption = v0-v1;
+ currentCost = currentConsumption * ic.getPricePerUnit();
}
tvCurrentCost.setText(String.format("%.2f "+ic.getCurrency(),
- currentConsumption * ic.getPricePerUnit()));
+ currentCost));
tvMeterValue.setText(String.format("%.2f "+channel.getUnit(), ic.getCalculatedValue()));
tvCurrentConsumption.setText(String.format("%.2f "+channel.getUnit(), currentConsumption));
From cc3de5e1e1cccbb24dcedda511d2edbd38520fe1 Mon Sep 17 00:00:00 2001
From: Przemek Zygmunt
Date: Sun, 30 Jun 2019 11:14:33 +0200
Subject: [PATCH 4/4] Version increment
---
app/build.gradle | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 8863bee03..69a427248 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -9,8 +9,8 @@ android {
applicationId "org.supla.android"
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
- versionCode 61
- versionName "2.3.8"
+ versionCode 62
+ versionName "2.3.9"
sourceSets.main {
jniLibs.srcDir 'src/main/libs'