Skip to content

Commit

Permalink
Fixed crash on showing logic for stocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahMitt committed Aug 24, 2015
1 parent 47fdc41 commit 3c087c4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void setViewState() {
ForecastModule.getHourlyForecast(getResources(), 40.681045, -73.9931749, mForecastListener);
XKCDModule.getXKCDForToday(mXKCDListener);

if (WeekUtil.isWeekday()) {
if (WeekUtil.isWeekday() && WeekUtil.afterFive()) {
YahooFinanceModule.getStockForToday("ETSY", mStockListener);
} else {
mStockText.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void onPostExecute(ForecastResponse forecastResponse) {
listener.onWeatherToday(forecastResponse.currently.getDisplayTemperature() + " " + forecastResponse.currently.summary);
}

if (WeekUtil.isWeekday() && forecastResponse.hourly != null && forecastResponse.hourly.data != null) {
if (WeekUtil.isWeekday() && !WeekUtil.afterFive() && forecastResponse.hourly != null && forecastResponse.hourly.data != null) {
listener.onShouldBike(true, shouldBikeToday(forecastResponse.hourly.data));
} else {
listener.onShouldBike(false, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.morristaedt.mirror.requests;

import android.text.TextUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;

Expand All @@ -24,8 +26,12 @@ public class YahooQuoteResponse {
public float LastTradePriceOnly;

public BigDecimal getPercentageChange() {
BigDecimal decimalPercentage = new BigDecimal(PercentChange.trim().replace("%", "")).divide(BigDecimal.valueOf(100), RoundingMode.CEILING);
return decimalPercentage;
if (!TextUtils.isEmpty(PercentChange)) {
BigDecimal decimalPercentage = new BigDecimal(PercentChange.trim().replace("%", "")).divide(BigDecimal.valueOf(100), RoundingMode.CEILING);
return decimalPercentage;
} else {
return BigDecimal.valueOf(0);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/morristaedt/mirror/utils/WeekUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public static boolean isWeekday() {
int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
return dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY;
}

public static boolean afterFive(){
int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
return hourOfDay >= 17;
}
}
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.

0 comments on commit 3c087c4

Please sign in to comment.