Skip to content

Commit

Permalink
Merge pull request #250 from hello/dz/partial_data_state_fix
Browse files Browse the repository at this point in the history
Added unit to placeholder text. [ref #107420228]
  • Loading branch information
jimmymlu committed Nov 24, 2015
2 parents a42ef36 + ce2d757 commit 6b0c5ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,9 @@ public void onGraphHighlightBegin() {
@Override
public void onGraphValueHighlighted(int section, int position) {
final SensorGraphSample instant = getSection(section).get(position);
if (instant.isValuePlaceholder()) {
readingText.setText(R.string.missing_data_placeholder);
} else {
final UnitPrinter printer = unitFormatter.getUnitPrinterForSensor(sensor);
final CharSequence reading = printer.print(instant.getValue());
readingText.setText(reading);
}
final UnitPrinter printer = unitFormatter.getUnitPrinterForSensor(sensor);
final CharSequence reading = printer.print(instant.getValue());
readingText.setText(reading);

if (sensorHistoryPresenter.getMode() == SensorHistoryPresenter.Mode.WEEK) {
messageText.setText(dateFormatter.formatAsDayAndTime(instant.getShiftedTime(), use24Time));
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/is/hello/sense/ui/widget/util/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public final class Styles {
return assembleReadingAndUnit(String.format("%.0f", value), suffix, UNIT_STYLE_SUPERSCRIPT);
}

public static @NonNull CharSequence assembleReadingAndUnit(String value, @NonNull String suffix) {
return assembleReadingAndUnit(String.format("%1$2s", value), suffix, UNIT_STYLE_SUPERSCRIPT);
}

public static @NonNull GradientDrawable createGraphFillGradientDrawable(@NonNull Resources resources) {
return new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
resources.getColor(R.color.graph_fill_gradient_top),
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/is/hello/sense/units/UnitFormatter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package is.hello.sense.units;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.Locale;

import javax.inject.Inject;

import is.hello.sense.R;
import is.hello.sense.api.ApiService;
import is.hello.sense.graph.presenters.PreferencesPresenter;
import is.hello.sense.ui.widget.util.Styles;
Expand All @@ -28,6 +30,7 @@ public class UnitFormatter {

private final PreferencesPresenter preferences;
private final boolean defaultMetric;
private final String placeHolder;

public static boolean isDefaultLocaleMetric() {
String country = Locale.getDefault().getCountry();
Expand All @@ -36,9 +39,10 @@ public static boolean isDefaultLocaleMetric() {
!"MM".equals(country));
}

@Inject public UnitFormatter(@NonNull PreferencesPresenter preferences) {
@Inject public UnitFormatter(@NonNull PreferencesPresenter preferences, @NonNull Context context) {
this.preferences = preferences;
this.defaultMetric = isDefaultLocaleMetric();
this.placeHolder = context.getString(R.string.missing_data_placeholder);
}

public Observable<String> unitPreferenceChanges() {
Expand All @@ -50,6 +54,9 @@ public Observable<String> unitPreferenceChanges() {
//region Formatting

public @NonNull CharSequence formatTemperature(double value) {
if (value == -1){
return Styles.assembleReadingAndUnit(placeHolder, UNIT_SUFFIX_TEMPERATURE);
}
double convertedValue = value;
if (!preferences.getBoolean(PreferencesPresenter.USE_CELSIUS, defaultMetric)) {
convertedValue = UnitOperations.celsiusToFahrenheit(convertedValue);
Expand Down Expand Up @@ -84,7 +91,9 @@ public Observable<String> unitPreferenceChanges() {
}

public @NonNull CharSequence formatLight(double value) {
if (value < 10.0) {
if (value == -1){
return Styles.assembleReadingAndUnit(placeHolder, UNIT_SUFFIX_LIGHT);
}else if (value < 10.0) {
return Styles.assembleReadingAndUnit(String.format("%.1f", value),
UNIT_SUFFIX_LIGHT,
Styles.UNIT_STYLE_SUPERSCRIPT);
Expand All @@ -94,14 +103,23 @@ public Observable<String> unitPreferenceChanges() {
}

public @NonNull CharSequence formatHumidity(double value) {
if (value == -1){
return Styles.assembleReadingAndUnit(placeHolder, UNIT_SUFFIX_HUMIDITY);
}
return Styles.assembleReadingAndUnit(value, UNIT_SUFFIX_HUMIDITY);
}

public @NonNull CharSequence formatAirQuality(double value) {
if (value == -1){
return Styles.assembleReadingAndUnit(placeHolder, UNIT_SUFFIX_AIR_QUALITY);
}
return Styles.assembleReadingAndUnit(value, UNIT_SUFFIX_AIR_QUALITY);
}

public @NonNull CharSequence formatNoise(double value) {
if (value == -1){
return Styles.assembleReadingAndUnit(placeHolder, UNIT_SUFFIX_NOISE);
}
return Styles.assembleReadingAndUnit(value, UNIT_SUFFIX_NOISE);
}

Expand Down

0 comments on commit 6b0c5ee

Please sign in to comment.