Skip to content

Commit

Permalink
Merge pull request #154 from nightscout/kl.0.1.12-timefix
Browse files Browse the repository at this point in the history
Daylight savings time fix
  • Loading branch information
jasoncalabrese committed Mar 9, 2015
2 parents 6e4cedd + 780206f commit 37d1fe0
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 102 deletions.
18 changes: 10 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'robolectric'

def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
def codeName = "Dreamsicle"

android {
compileSdkVersion 21
buildToolsVersion '21.1.1'

defaultConfig {
applicationId "com.nightscout.android"
minSdkVersion 12
targetSdkVersion 18
versionCode 22
versionName "0.1.13"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
buildConfigField "String", "VERSION_CODENAME", "\"${codeName}\""
}

lintOptions {
quiet false
checkAllWarnings true
Expand All @@ -33,7 +40,6 @@ android {
checkReleaseBuilds true
warning 'ProtectedPermissions', 'InvalidPackage'
}

packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
Expand All @@ -42,7 +48,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

sourceSets {
androidTest {
setRoot('src/test')
Expand All @@ -68,22 +73,19 @@ dependencies {
exclude group: 'org.apache.httpcomponents'
exclude group: 'joda-time', module: 'joda-time'
}
compile files('libs/acra-4.5.0.jar')
compile 'ch.acra:acra:4.6.1'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'org.mongodb:mongo-java-driver:2.10.1'
compile 'net.danlew:android.joda:2.6.0'
compile 'com.google.guava:guava:18.0'
// compile 'com.noveogroup.android:android-logger:1.3.4'

compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'
compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
compile 'com.google.zxing:core:3.0.1'

compile 'com.getpebble:pebblekit:2.6.0@aar'

androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile('junit:junit:4.11') {
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nightscout.android"
android:versionCode="20"
android:versionName="0.1.11">
package="com.nightscout.android">

<uses-feature android:name="android.hardware.usb.host" />

Expand All @@ -25,7 +23,8 @@
android:allowBackup="true">
<!-- Hard code this version for now. Robolectric has troubles starting when this is
a variable. See: https://github.com/robolectric/robolectric/issues/1025 -->
<meta-data android:name="com.google.android.gms.version"
<meta-data
android:name="com.google.android.gms.version"
tools:replace="android:value"
android:value="6587000" />
<activity
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/nightscout/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected void onResume() {

// Set and deal with mmol/L<->mg/dL conversions
Log.d(TAG, "display_options_units: " + preferences.getPreferredUnits().name());
pebble.config(preferences.getPwdName(), preferences.getPreferredUnits());
pebble.config(preferences.getPwdName(), preferences.getPreferredUnits(), getApplicationContext());
int sgv = (Integer) mTextSGV.getTag(R.string.display_sgv);

int direction = (Integer) mTextSGV.getTag(R.string.display_trend);
Expand Down Expand Up @@ -319,7 +319,12 @@ protected void onDestroy() {
unregisterReceiver(mCGMStatusReceiver);
unregisterReceiver(mDeviceStatusReceiver);
unregisterReceiver(toastReceiver);
uploaderDevice.close();
if (pebble != null) {
pebble.close();
}
if (uploaderDevice != null) {
uploaderDevice.close();
}
}

@Override
Expand Down Expand Up @@ -380,7 +385,7 @@ public void onReceive(Context context, Intent intent) {
String json = intent.getStringExtra(SyncingService.RESPONSE_JSON);

if (responseSGV != -1) {
pebble.sendDownload(reading, trend, responseSGVTimestamp);
pebble.sendDownload(reading, trend, responseSGVTimestamp, getApplicationContext());
}
// Reload d3 chart with new data
if (json != null) {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/com/nightscout/android/Nightscout.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@
import org.acra.annotation.ReportsCrashes;

@ReportsCrashes(
formKey = "",
formUri = "http://nightscout.cloudant.com/acra-nightscout/_design/acra-storage/_update/report",
reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT,
formUriBasicAuthLogin="whisphisheiringliketfurg",
formUriBasicAuthPassword="8CgjF6r2u4i8EhPHoPJjnk8f",
formUri = "https://collector.tracepot.com/a64e4a51",
resToastText = R.string.crash_toast_text,
resDialogText = R.string.feebback_dialog_text,
resDialogIcon = R.drawable.ic_launcher,
resDialogTitle = R.string.feedback_dialog_title,
resDialogCommentPrompt = R.string.feedback_dialog_comment_prompt,
resDialogOkToast = R.string.feedback_dialog_ok_toast,
excludeMatchingSharedPreferencesKeys= {"cloud_storage_mongodb_uri", "cloud_storage_api_base"},
excludeMatchingSharedPreferencesKeys = {"cloud_storage_mongodb_uri", "cloud_storage_api_base"},
mode = ReportingInteractionMode.TOAST,
logcatArguments = { "-t", "250", "-v", "time" }
logcatArguments = {"-t", "500", "-v", "time"}
)
public class Nightscout extends Application {
private final String TAG = MainActivity.class.getSimpleName();
Expand All @@ -44,12 +39,12 @@ public void onCreate() {
synchronized public Tracker getTracker() {
Log.d(TAG, "getTracker called");
if (tracker == null) {
Log.d(TAG,"tracker was null - returning new tracker");
Log.d(TAG, "tracker was null - returning new tracker");
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.setDryRun(false);
analytics.getLogger().setLogLevel(Logger.LogLevel.WARNING);
analytics.setLocalDispatchPeriod(7200);
tracker = analytics.newTracker(R.xml.app_tracker);
tracker = analytics.newTracker(R.xml.app_tracker);
return tracker;
}
return tracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

public class AndroidUploaderDevice extends AbstractUploaderDevice {
private int uploaderBattery;
private static AndroidUploaderDevice uploaderDevice;
private Context context;

private AndroidUploaderDevice(Context context) {
Expand All @@ -23,11 +22,9 @@ public int getBatteryLevel() {
return uploaderBattery;
}

// TODO: This registers everytime. Need to fix
public static AndroidUploaderDevice getUploaderDevice(Context context) {
if (uploaderDevice == null) {
uploaderDevice = new AndroidUploaderDevice(context);
}
return uploaderDevice;
return new AndroidUploaderDevice(context);
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.nightscout.android.settings;

import com.google.common.base.Optional;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;

import com.google.common.base.Optional;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.nightscout.android.BuildConfig;
import com.nightscout.android.R;
import com.nightscout.android.barcode.AndroidBarcode;
import com.nightscout.android.preferences.AndroidPreferences;
Expand All @@ -39,9 +38,9 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void refreshFragments() {
mainPreferenceFragment = new MainPreferenceFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content,
mainPreferenceFragment).commit();
mainPreferenceFragment = new MainPreferenceFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content,
mainPreferenceFragment).commit();
}

private void setupActionBar() {
Expand Down Expand Up @@ -80,7 +79,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
prefs.setMongoClientUri(barcode.getMongoUri().get());
prefs.setMongoCollection(barcode.getMongoCollection().orNull());
prefs.setMongoDeviceStatusCollection(
barcode.getMongoDeviceStatusCollection().orNull());
barcode.getMongoDeviceStatusCollection().orNull());
}
} else {
prefs.setMongoUploadEnabled(false);
Expand All @@ -106,14 +105,11 @@ public void onCreate(Bundle savedInstanceState) {
}

private void setupVersionNumbers() {
try {
PackageInfo pInfo;
pInfo = getActivity().getPackageManager().getPackageInfo(
getActivity().getPackageName(), 0);
findPreference("about_version_number").setSummary(pInfo.versionName);
} catch (PackageManager.NameNotFoundException e) {
// nom
}
findPreference("about_version_number").setSummary(BuildConfig.VERSION_CODENAME);
findPreference("about_version_number").setSummary(BuildConfig.VERSION_NAME);
findPreference("about_build_hash").setSummary(BuildConfig.GIT_SHA);
findPreference("about_device_id").setSummary(Settings.Secure.getString(getActivity().getContentResolver(),
Settings.Secure.ANDROID_ID));
}

private void setupBarcodeScanner() {
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/com/nightscout/android/upload/Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ private boolean initializeRestUploaders(Context context, NightscoutPreferences p
return allInitialized;
}

// public boolean upload(GlucoseDataSet glucoseDataSet, MeterRecord meterRecord,
// CalRecord calRecord) {
// return upload(Lists.newArrayList(glucoseDataSet), Lists.newArrayList(meterRecord),
// Lists.newArrayList(calRecord));
// }

public boolean upload(DownloadResults downloadResults, int numRecords) {
G4Download download = downloadResults.getDownload();
List<SensorGlucoseValueEntry> sgvList = filterRecords(numRecords, download.sgv);
Expand Down
37 changes: 21 additions & 16 deletions app/src/main/java/com/nightscout/android/wearables/Pebble.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,25 @@ public class Pebble {
private GlucoseReading lastDelta;
private TrendArrow lastTrend = TrendArrow.NONE;
private long lastRecordTime = 0;
private PebbleKit.PebbleDataReceiver dataReceiver = new PebbleKit.PebbleDataReceiver(PEBBLEAPP_UUID) {
@Override
public void receiveData(final Context mContext, final int transactionId, final PebbleDictionary data) {
Log.d(TAG, "Received query. data: " + data.size());
PebbleKit.sendAckToPebble(mContext, transactionId);
sendDownload(currentReading);
}
};

public Pebble(Context context) {
this.context = context;
currentReading = null;
init();
}

public void close() {
context.unregisterReceiver(dataReceiver);
}

public PebbleDictionary buildDictionary(TrendArrow trend, String bgValue, int recordTime, int uploaderTimeSec,
String delta, String uploaderBattery, String name) {
PebbleDictionary dictionary = new PebbleDictionary();
Expand All @@ -61,11 +73,11 @@ public PebbleDictionary buildDictionary(TrendArrow trend, String bgValue, int re
return dictionary;
}

public void sendDownload(GlucoseReading reading, TrendArrow trend, long recordTime) {
sendDownload(reading, trend, recordTime, false);
public void sendDownload(GlucoseReading reading, TrendArrow trend, long recordTime, Context cntx) {
sendDownload(reading, trend, recordTime, cntx, false);
}

public void sendDownload(GlucoseReading reading, TrendArrow trend, long recordTime, boolean resend) {
public void sendDownload(GlucoseReading reading, TrendArrow trend, long recordTime, Context cntx, boolean resend) {
GlucoseReading delta = new GlucoseReading(0, GlucoseUnit.MGDL);

if (currentReading != null) {
Expand All @@ -87,17 +99,17 @@ public void sendDownload(GlucoseReading reading, TrendArrow trend, long recordTi
lastTrend = trend;
lastDelta = delta;
recordTime = DateTimeZone.getDefault().convertUTCToLocal(recordTime);
int batLevel = AndroidUploaderDevice.getUploaderDevice(context).getBatteryLevel();
int batLevel = AndroidUploaderDevice.getUploaderDevice(cntx).getBatteryLevel();
PebbleDictionary dictionary = buildDictionary(trend, bgStr, (int) (recordTime / 1000),
(int) (DateTimeZone.getDefault().convertUTCToLocal(new DateTime().getMillis()) / 1000), deltaStr,
String.valueOf(batLevel), pwdName);
currentReading = dictionary;
sendDownload(dictionary);
}

public void resendDownload() {
public void resendDownload(Context cntx) {
if (currentReading != null) {
sendDownload(lastReading, lastTrend, lastRecordTime, true);
sendDownload(lastReading, lastTrend, lastRecordTime, cntx, true);
}
}

Expand All @@ -111,22 +123,15 @@ public void sendDownload(PebbleDictionary dictionary) {
}

private void init() {
PebbleKit.registerReceivedDataHandler(context, new PebbleKit.PebbleDataReceiver(PEBBLEAPP_UUID) {
@Override
public void receiveData(final Context mContext, final int transactionId, final PebbleDictionary data) {
Log.d(TAG, "Received query. data: " + data.size());
PebbleKit.sendAckToPebble(mContext, transactionId);
sendDownload(currentReading);
}
});
PebbleKit.registerReceivedDataHandler(context, dataReceiver);
}

public void config(String pwdName, GlucoseUnit units) {
public void config(String pwdName, GlucoseUnit units, Context cntx) {
boolean changed = !this.pwdName.equals(pwdName) || this.units != units;
if (changed) {
setPwdName(pwdName);
setUnits(units);
resendDownload();
resendDownload(cntx);
}
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<string name="feebback_dialog_text">Per favore facci sapere cosa ne pensi</string>
<string name="feedback_dialog_comment_prompt">Aggiungi i tuoi commenti qui sotto:</string>
<string name="feedback_dialog_ok_toast">Grazie!</string>
<string name="feedback_toast_text"/>
<string name="feedback_toast_text" />
<string name="message_user_not_understand">La lettura dal device è disabilitata finchè non leggi e accetti \"HO CAPITO\" nelle preferenze</string>
<string name="button_force_sync">Forza invio dati ultimi 2 giorni</string>
<string name="acra_enabled_summary">Crash reporting is enabled</string>
<string name="acra_disabled_summary">Crash reporting is disabled</string>
<string name="acra_email_dialog_title">Email</string>
<string name="acra_user_email_dialog_message">This is the email address included in bug reports and automatic crash reports. This field is optional</string>
<string name="display_sgv"/>
<string name="display_trend"/>
<string name="display_sgv" />
<string name="display_trend" />

<string name="close_menu_text">Esci</string>
<string name="feedback_menu_text">Feedback</string>
Expand All @@ -36,7 +36,7 @@
<string name="unknown_mongo_host">Error resolving Mongo host. Double check mongo url.</string>
<string name="illegal_rest_url">Could not create API uploader. Check your settings.</string>
<string name="auto_configure_title">Auto configure</string>

<string name="DexBatteryLabelText">Batteria Dex</string>
<string name="TimeSyncLabelText">Ora</string>
<string name="TimeChangeDetected">Trovata modifica temporale</string>
Expand All @@ -48,4 +48,5 @@
<string name="unknown_rest_host">Impossibile connettersi a %s, si prega di verificare che si è connessi a Internet, e che l\'URL sia corretto.</string>
<string name="version_unknown">Versione sconosciuta</string>
<string name="default_pwd_name">Camping</string>
<string name="pref_about_hash">Git hash</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-it/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<string name="pref_header_about">A proposito</string>

<string name="pref_title_about_release_name">Nome della versione</string>
<string name="pref_summary_about_release_name">Cookie Monster</string>
<string name="pref_summary_about_release_name">Dreamsicle</string>

<string name="pref_title_about_version_number">Numero della versione</string>

Expand All @@ -115,4 +115,5 @@
<string name="pref_enable_acra">Abilita il reporting dei crash</string>
<string name="prefs_pwd_display_name_title">PWD Display name</string>
<string name="prefs_pwd_display_name_summary">This is the name of the pwd that will be displayed on other monitors e.g. pebble</string>
<string name="pref_about_deviceid">Device ID</string>
</resources>
Loading

0 comments on commit 37d1fe0

Please sign in to comment.