Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/res/values-de/strings.xml
  • Loading branch information
TebbeUbben committed May 1, 2018
2 parents 5bdefe8 + 2776a06 commit b26e296
Show file tree
Hide file tree
Showing 113 changed files with 1,047 additions and 373 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package sugar.free.sightremote.activities;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;

Expand Down Expand Up @@ -37,7 +35,6 @@
import sugar.free.sightremote.R;
import sugar.free.sightremote.adapters.BRProfileAdapter;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;

public class ChangeActiveBRProfileActivity extends SightActivity implements TaskRunner.ResultCallback, BRProfileAdapter.BRProfileChangeListener, BRProfileAdapter.OnClickListener {
Expand Down Expand Up @@ -133,8 +130,7 @@ protected void onPause() {
@Override
public void onError(Exception e) {
hideLoadingIndicator();
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void onResult(Object result) {

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void onLongItemClick(View view, int position) {

private StatusCallback statusCallback = new StatusCallback() {
@Override
public void onStatusChange(final Status status) {
public void onStatusChange(final Status status, long statusTime, long waitTime) {
if (viewPager.getCurrentItem() != 3) return;
runOnUiThread(() -> {
if (status == Status.CONNECTING)
Expand Down Expand Up @@ -293,7 +293,7 @@ else if (status == Status.CODE_REJECTED) {
private ServiceConnectionCallback connectionCallback = new ServiceConnectionCallback() {
@Override
public void onServiceConnected() {
statusCallback.onStatusChange(serviceConnector.getStatus());
statusCallback.onStatusChange(serviceConnector.getStatus(), 0, 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -148,6 +149,10 @@ protected void statusChanged(Status status) {

}

protected void statusChanged(Status status, long statusTime, long waitTime) {

}

@Override
protected void onStop() {
super.onStop();
Expand All @@ -169,7 +174,7 @@ public void onServiceConnected() {
Status status = sightServiceConnector.getStatus();
if (status != latest) {
if (useOverlay()) updateOverlay(status);
updateSnackbar(status);
updateSnackbar(status, sightServiceConnector.getStatusTime(), sightServiceConnector.getWaitTime());
latest = status;
}
connectedToService();
Expand All @@ -181,12 +186,19 @@ public void onServiceDisconnected() {
}
};

private void updateSnackbar(Status status) {
private void updateSnackbar(Status status, long statusTime, long waitTime) {
if (!snackbarEnabled()) return;
if (status == Status.CONNECTED) {
dismissSnackbar();
} else if (status == Status.CONNECTING) {
showSnackbar(Snackbar.make(getRootView(), R.string.connecting, Snackbar.LENGTH_INDEFINITE));
} else if (status == Status.WAITING) {
double leftOverWaitTime = waitTime - (System.currentTimeMillis() - statusTime);
int delay = (int) Math.round(leftOverWaitTime / 1000D);
delay = Math.max(delay, 0);
Snackbar snackbar = Snackbar.make(getRootView(), getResources().getQuantityString(R.plurals.waiting, delay, delay), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.connect_now, v -> sightServiceConnector.forceConnect());
showSnackbar(snackbar);
}
}

Expand Down Expand Up @@ -217,10 +229,11 @@ private void hideOverlay() {
});
}

private StatusCallback statusCallback = status -> {
updateSnackbar(status);
private StatusCallback statusCallback = (status, statusTime, waitTime) -> {
updateSnackbar(status, statusTime, waitTime);
updateOverlay(status);
statusChanged(status);
statusChanged(status, statusTime, waitTime);
};

public SightServiceConnector getServiceConnector() {
Expand Down Expand Up @@ -252,12 +265,11 @@ protected boolean snackbarEnabled() {
}

protected void showSnackbar(final Snackbar snackbar) {
runOnUiThread(() -> {
if (snackbar != null) snackbar.dismiss();
new Handler(Looper.getMainLooper()).postDelayed(() -> {
SightActivity.this.snackbar = snackbar;
snackbar.getView().setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
snackbar.show();
});
}, 300);
}

protected void dismissSnackbar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage;
import sugar.free.sightparser.applayer.messages.remote_control.SetPumpStatusMessage;
import sugar.free.sightparser.error.CancelledException;
import sugar.free.sightparser.error.DisconnectedError;
import sugar.free.sightparser.errors.CancelledException;
import sugar.free.sightparser.exceptions.DisconnectedException;
import sugar.free.sightparser.handling.HistoryBroadcast;
import sugar.free.sightparser.handling.SingleMessageTaskRunner;
import sugar.free.sightparser.handling.TaskRunner;
Expand All @@ -45,7 +45,6 @@
import sugar.free.sightremote.R;
import sugar.free.sightremote.database.BolusDelivered;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;
import sugar.free.sightremote.utils.UnitFormatter;

Expand Down Expand Up @@ -109,8 +108,7 @@ public void onResult(Object result) {

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(StatusActivity.this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(StatusActivity.this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}
};
private BroadcastReceiver historyBroadcastReceiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -355,7 +353,7 @@ public void onClick(View v) {
handler.removeCallbacks(taskRunnerRunnable);
AppLayerMessage message = null;
if (v == tbrCancel) {
tbrCancel.setVisibility(View.GONE);
tbrCancel.setVisibility(View.INVISIBLE);
message = new CancelTBRMessage();
Answers.getInstance().logCustom(new CustomEvent("TBR Cancelled"));
} else if (v == bolus1Cancel) {
Expand Down Expand Up @@ -394,11 +392,10 @@ public void onResult(Object result) {

@Override
public void onError(Exception e) {
if (!(e instanceof CancelledException) && !(e instanceof DisconnectedError)) {
Snackbar snackbar = Snackbar.make(getRootView(), R.string.error, Snackbar.LENGTH_INDEFINITE);
if (!(e instanceof CancelledException) && !(e instanceof DisconnectedException)) {
Snackbar snackbar = Snackbar.make(getRootView(), getString(R.string.error, e.getClass().getSimpleName()), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.retry, view -> taskRunnerRunnable.run());
showSnackbar(snackbar);
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import sugar.free.sightremote.R;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.DurationPicker;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;
import sugar.free.sightremote.utils.UnitFormatter;

Expand Down Expand Up @@ -113,16 +112,14 @@ public void onResult(Object result) {
dismissSnackbar();
}
} else {
Answers.getInstance().logCustom(
new CustomEvent("TBR Programmed"));
Answers.getInstance().logCustom(new CustomEvent("TBR Programmed"));
finish();
}
}

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sugar.free.sightremote.utils.BolusAmountPicker;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.DurationPicker;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;
import sugar.free.sightremote.utils.UnitFormatter;

Expand Down Expand Up @@ -103,8 +102,7 @@ protected void connectedToService() {

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sugar.free.sightremote.utils.BolusAmountPicker;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.DurationPicker;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;
import sugar.free.sightremote.utils.UnitFormatter;

Expand Down Expand Up @@ -123,8 +122,7 @@ protected void connectedToService() {

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import sugar.free.sightremote.activities.SightActivity;
import sugar.free.sightremote.utils.BolusAmountPicker;
import sugar.free.sightremote.dialogs.ConfirmationDialog;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HTMLUtil;
import sugar.free.sightremote.utils.UnitFormatter;

Expand Down Expand Up @@ -94,8 +93,7 @@ protected void connectedToService() {

@Override
public void onError(Exception e) {
runOnUiThread(() -> Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
runOnUiThread(() -> Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName()), Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.os.Looper;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;

Expand All @@ -31,7 +30,6 @@
import sugar.free.sightparser.pipeline.Status;
import sugar.free.sightremote.R;
import sugar.free.sightremote.activities.AlertActivity;
import sugar.free.sightremote.utils.CrashlyticsUtil;

public class AlertService extends Service implements StatusCallback, ServiceConnectionCallback, TaskRunner.ResultCallback {

Expand Down Expand Up @@ -61,7 +59,7 @@ public void onDestroy() {
}

@Override
public void onStatusChange(Status status) {
public void onStatusChange(Status status, long statusTime, long waitTime) {
if (status == Status.CONNECTED) {
if (fetchTimer != null) return;
fetchTimer = new Timer(false);
Expand All @@ -84,7 +82,7 @@ public void run() {
@Override
public void onServiceConnected() {
serviceConnector.addStatusCallback(this);
onStatusChange(serviceConnector.getStatus());
onStatusChange(serviceConnector.getStatus(), 0, 0);
}

@Override
Expand Down Expand Up @@ -142,7 +140,6 @@ public void dismissAlert() {

@Override
public void onError(Exception e) {
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
}

public class AlertServiceBinder extends Binder {
Expand All @@ -162,7 +159,6 @@ public void onResult(Object result) {
@Override
public void onError(Exception e) {
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(AlertService.this, R.string.error, Toast.LENGTH_SHORT).show());
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;
Expand All @@ -27,7 +22,6 @@
import java.util.Locale;
import java.util.TimeZone;

import org.spongycastle.util.Pack;
import sugar.free.sightparser.applayer.descriptors.HistoryReadingDirection;
import sugar.free.sightparser.applayer.descriptors.HistoryType;
import sugar.free.sightparser.applayer.descriptors.history_frames.*;
Expand Down Expand Up @@ -56,7 +50,6 @@
import sugar.free.sightremote.database.PumpStatusChanged;
import sugar.free.sightremote.database.TimeChanged;
import sugar.free.sightremote.database.TubeFilled;
import sugar.free.sightremote.utils.CrashlyticsUtil;
import sugar.free.sightremote.utils.HistoryResync;
import sugar.free.sightremote.utils.HistorySendIntent;

Expand Down Expand Up @@ -150,7 +143,7 @@ private List<String> getAppsWithHistoryPermission() {
}

@Override
public void onStatusChange(Status status) {
public void onStatusChange(Status status, long statusTime, long waitTime) {
if (status == Status.CONNECTED) {
connector.connect();
ReadStatusParamBlockMessage readMessage = new ReadStatusParamBlockMessage();
Expand Down Expand Up @@ -532,7 +525,6 @@ public void onError(Exception e) {
syncing = false;
HistorySendIntent.sendSyncFinished(this, getAppsWithHistoryPermission());
if (wakeLock.isHeld()) wakeLock.release();
CrashlyticsUtil.logExceptionWithCallStackTrace(e);
}

private void startSync() {
Expand All @@ -548,7 +540,7 @@ public void onServiceConnected() {
else {
connector.connect();
if (connector.getStatus() == Status.CONNECTED) {
onStatusChange(Status.CONNECTED);
onStatusChange(Status.CONNECTED, 0, 0);
}
}
}
Expand Down
Loading

0 comments on commit b26e296

Please sign in to comment.