Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Generator bug fixes
  • Loading branch information
audaciouscode committed May 19, 2017
1 parent f79153b commit f30b56b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 51 deletions.
Expand Up @@ -122,6 +122,8 @@ private void startGenerator() {
@Override
public void onReceive(final Context context, Intent intent) {
if (me.mDatabase == null) {
PassiveDataKit.getInstance(context).start();

return;
}

Expand Down
Expand Up @@ -17,7 +17,6 @@
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -733,73 +732,77 @@ private void fetchIntradayActivities() {
if (response.getInt("status") == 0) {
JSONObject body = response.getJSONObject("body");

JSONObject series = body.getJSONObject("series");
try {
JSONObject series = body.getJSONObject("series");

Iterator<String> keys = series.keys();
Iterator<String> keys = series.keys();

while (keys.hasNext()) {
String key = keys.next();
while (keys.hasNext()) {
String key = keys.next();

long timestamp = Long.parseLong(key);
long timestamp = Long.parseLong(key);

String where = WithingsDevice.INTRADAY_ACTIVITY_START + " = ?";
String[] args = { "" + timestamp };
String where = WithingsDevice.INTRADAY_ACTIVITY_START + " = ?";
String[] args = { "" + timestamp };

Cursor c = this.mDatabase.query(WithingsDevice.TABLE_INTRADAY_ACTIVITY_HISTORY, null, where, args, null, null, WithingsDevice.HISTORY_OBSERVED + " DESC");
Cursor c = this.mDatabase.query(WithingsDevice.TABLE_INTRADAY_ACTIVITY_HISTORY, null, where, args, null, null, WithingsDevice.HISTORY_OBSERVED + " DESC");

if (c.moveToNext() == false) {
JSONObject item = series.getJSONObject(key);
if (c.moveToNext() == false) {
JSONObject item = series.getJSONObject(key);

ContentValues values = new ContentValues();
values.put(WithingsDevice.HISTORY_OBSERVED, now);
values.put(WithingsDevice.INTRADAY_ACTIVITY_START, timestamp);
values.put(WithingsDevice.INTRADAY_ACTIVITY_DURATION, item.getLong("duration"));
ContentValues values = new ContentValues();
values.put(WithingsDevice.HISTORY_OBSERVED, now);
values.put(WithingsDevice.INTRADAY_ACTIVITY_START, timestamp);
values.put(WithingsDevice.INTRADAY_ACTIVITY_DURATION, item.getLong("duration"));

Bundle updated = new Bundle();
updated.putLong(WithingsDevice.HISTORY_OBSERVED, System.currentTimeMillis());
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_START, timestamp);
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_DURATION, item.getLong("duration"));
Bundle updated = new Bundle();
updated.putLong(WithingsDevice.HISTORY_OBSERVED, System.currentTimeMillis());
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_START, timestamp);
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_DURATION, item.getLong("duration"));

if (item.has("steps")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_STEPS, item.getLong("steps"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_STEPS, item.getLong("steps"));
}
if (item.has("steps")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_STEPS, item.getLong("steps"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_STEPS, item.getLong("steps"));
}

if (item.has("elevation")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_ELEVATION_CLIMBED, item.getLong("elevation"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_ELEVATION_CLIMBED, item.getLong("elevation"));
}
if (item.has("elevation")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_ELEVATION_CLIMBED, item.getLong("elevation"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_ELEVATION_CLIMBED, item.getLong("elevation"));
}

if (item.has("distance")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_DISTANCE, item.getLong("distance"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_DISTANCE, item.getLong("distance"));
}
if (item.has("distance")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_DISTANCE, item.getLong("distance"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_DISTANCE, item.getLong("distance"));
}

if (item.has("calories")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_CALORIES, item.getLong("calories"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_CALORIES, item.getLong("calories"));
}
if (item.has("calories")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_CALORIES, item.getLong("calories"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_CALORIES, item.getLong("calories"));
}

if (item.has("stroke")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_SWIM_STROKES, item.getLong("stroke"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_SWIM_STROKES, item.getLong("stroke"));
}
if (item.has("stroke")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_SWIM_STROKES, item.getLong("stroke"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_SWIM_STROKES, item.getLong("stroke"));
}

if (item.has("pool_lap")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_POOL_LAPS, item.getLong("pool_lap"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_POOL_LAPS, item.getLong("pool_lap"));
}
if (item.has("pool_lap")) {
values.put(WithingsDevice.INTRADAY_ACTIVITY_POOL_LAPS, item.getLong("pool_lap"));
updated.putLong(WithingsDevice.INTRADAY_ACTIVITY_POOL_LAPS, item.getLong("pool_lap"));
}

this.mDatabase.insert(WithingsDevice.TABLE_INTRADAY_ACTIVITY_HISTORY, null, values);
this.mDatabase.insert(WithingsDevice.TABLE_INTRADAY_ACTIVITY_HISTORY, null, values);

this.annotateGeneratorReading(updated);
this.annotateGeneratorReading(updated);

updated.putString(WithingsDevice.DATASTREAM, WithingsDevice.DATASTREAM_INTRADAY_ACTIVITY);
updated.putString(WithingsDevice.DATASTREAM, WithingsDevice.DATASTREAM_INTRADAY_ACTIVITY);

Generators.getInstance(this.mContext).notifyGeneratorUpdated(WithingsDevice.GENERATOR_IDENTIFIER, updated);
}
Generators.getInstance(this.mContext).notifyGeneratorUpdated(WithingsDevice.GENERATOR_IDENTIFIER, updated);
}

c.close();
c.close();
}
} catch (JSONException e) {
// JSON type mismatch when day's data is empty. Do nothing...
}
}
} catch (JSONException e) {
Expand Down Expand Up @@ -1391,6 +1394,10 @@ private static String bindActivityPage(ViewGroup container, DataPointViewHolder
entries.add(new PieEntry((long) intenseActivity, context.getString(R.string.generator_withings_intense_activities_label)));
}

if (entries.size() == 0) {
entries.add(new PieEntry(1L, context.getString(R.string.generator_withings_soft_activities_label)));
}

PieDataSet set = new PieDataSet(entries, " ");

int[] colors = {
Expand Down Expand Up @@ -1686,8 +1693,6 @@ private static String bindBodyPage(ViewGroup container, DataPointViewHolder hold

Cursor c = withings.mDatabase.query(WithingsDevice.TABLE_BODY_MEASURE_HISTORY, null, null, null, null, null, WithingsDevice.BODY_MEASURE_HISTORY_DATE + " DESC");

Log.e("PDK", "MEASURE COUNT: " + c.getCount());

while (c.moveToNext() && bodyValues.size() < labels.length) {
String label = c.getString(c.getColumnIndex(WithingsDevice.BODY_MEASURE_HISTORY_TYPE));

Expand Down

0 comments on commit f30b56b

Please sign in to comment.