Skip to content

Commit

Permalink
Merge pull request #77 from SUPLA/develop
Browse files Browse the repository at this point in the history
v2.3.9
  • Loading branch information
przemyslawzygmunt authored Jun 30, 2019
2 parents c226352 + cc3de5e commit bd59858
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/org/supla/android/ChannelDetailEM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/org/supla/android/ChannelDetailIC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/org/supla/android/SuplaApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class SuplaApp extends Application {

private static SuplaClient _SuplaClient = null;
private static SuplaApp _SuplaApp = null;
ArrayList<SuplaRestApiClientTask> _RestApiClientTasks = new ArrayList<SuplaRestApiClientTask>();
private SuplaOAuthToken _OAuthToken;
private ArrayList<SuplaRestApiClientTask> _RestApiClientTasks = new ArrayList<SuplaRestApiClientTask>();

private Handler _sc_msg_handler = new Handler() {
@Override
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bd59858

Please sign in to comment.