Skip to content

Commit

Permalink
Config bike weather hint
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahMitt committed Nov 21, 2015
1 parent 73c9bdf commit c737b9d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/com/morristaedt/mirror/MirrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ public void onWeatherToday(String weatherToday) {

@Override
public void onShouldBike(boolean showToday, boolean shouldBike) {
mBikeTodayText.setVisibility(showToday ? View.VISIBLE : View.GONE);
mBikeTodayText.setText(shouldBike ? R.string.bike_today : R.string.no_bike_today);
if (mConfigSettings.showBikingHint()) {
mBikeTodayText.setVisibility(showToday ? View.VISIBLE : View.GONE);
mBikeTodayText.setText(shouldBike ? R.string.bike_today : R.string.no_bike_today);
} else {
mBikeTodayText.setVisibility(View.GONE);
}
}
};

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/morristaedt/mirror/SetUpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SetUpActivity extends Activity {
private Location mLocation;

private RadioGroup mTemperatureChoice;
private CheckBox mBikingCheckbox;
private CheckBox mMoodDetectionCheckbox;
private CheckBox mShowNextCaledarEventCheckbox;
private CheckBox mShowNewsHeadlineCheckbox;
Expand All @@ -57,6 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
mTemperatureChoice = (RadioGroup) findViewById(R.id.temperature_group);
mTemperatureChoice.check(mConfigSettings.getIsCelsius() ? R.id.celsius : R.id.farenheit);

mBikingCheckbox = (CheckBox) findViewById(R.id.biking_checkbox);
mBikingCheckbox.setChecked(mConfigSettings.showBikingHint());

mMoodDetectionCheckbox = (CheckBox) findViewById(R.id.mood_detection_checkbox);
mMoodDetectionCheckbox.setChecked(mConfigSettings.showMoodDetection());

Expand Down Expand Up @@ -157,6 +161,7 @@ public void onProviderDisabled(String provider) {

private void saveFields() {
mConfigSettings.setIsCelsius(mTemperatureChoice.getCheckedRadioButtonId() == R.id.celsius);
mConfigSettings.setShowBikingHint(mBikingCheckbox.isChecked());
mConfigSettings.setShowMoodDetection(mMoodDetectionCheckbox.isChecked());
mConfigSettings.setShowNextCalendarEvent(mShowNextCaledarEventCheckbox.isChecked());
mConfigSettings.setShowNewsHeadline(mShowNewsHeadlineCheckbox.isChecked());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ConfigurationSettings {
private static final String PREFS_MIRROR = "MirrorPrefs";

private static final String FORECAST_UNITS = "forecast_units";
private static final String BIKING_HINT = "biking_hint";
private static final String USE_MOOD_DETECTION = "mood_detection";
private static final String SHOW_CALENDAR = "show_calendar";
private static final String SHOW_HEADLINE = "show_headline";
Expand All @@ -30,6 +31,7 @@ public class ConfigurationSettings {

private String mForecastUnits;

private boolean mShowBikingHint;
private boolean mShowMoodDetection;
private boolean mShowNextCalendarEvent;
private boolean mShowNewsHeadline;
Expand All @@ -48,6 +50,7 @@ public ConfigurationSettings(Context context) {

private void readPrefs() {
mForecastUnits = mSharedPrefs.getString(FORECAST_UNITS, ForecastRequest.UNITS_US);
mShowBikingHint = mSharedPrefs.getBoolean(BIKING_HINT, false);
mShowMoodDetection = mSharedPrefs.getBoolean(USE_MOOD_DETECTION, false);
mShowNextCalendarEvent = mSharedPrefs.getBoolean(SHOW_CALENDAR, false);
mShowNewsHeadline = mSharedPrefs.getBoolean(SHOW_HEADLINE, false);
Expand All @@ -66,6 +69,13 @@ public void setIsCelsius(boolean isCelsius) {
editor.apply();
}

public void setShowBikingHint(boolean show) {
mShowBikingHint = show;
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putBoolean(BIKING_HINT, show);
editor.apply();
}

public void setShowMoodDetection(boolean show) {
mShowMoodDetection = show;
SharedPreferences.Editor editor = mSharedPrefs.edit();
Expand Down Expand Up @@ -122,6 +132,10 @@ public String getForecastUnits() {
return mForecastUnits;
}

public boolean showBikingHint() {
return mShowBikingHint;
}

public boolean showMoodDetection() {
return mShowMoodDetection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ private boolean shouldBikeToday(List<ForecastResponse.Hour> hours) {
// Only check hourly forecast for today
if (hourCalendar.get(Calendar.DAY_OF_MONTH) == dayOfMonthToday) {
int hourOfDay = hourCalendar.get(Calendar.HOUR_OF_DAY);
Log.i("mirror", "Hour of day is " + hourOfDay + " with precipProb " + hour.precipProbability);
if (hourOfDay >= 7 && hourOfDay <= 11) {
if (hour.precipProbability >= 0.3) {
return false;
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/layout/activity_configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@

</RadioGroup>

<CheckBox
android:id="@+id/biking_checkbox"
style="@style/ConfigurationItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/biking_hint" />

<CheckBox
android:id="@+id/mood_detection_checkbox"
style="@style/ConfigurationItemText"
Expand Down Expand Up @@ -193,6 +201,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/item_margin"
android:text="To get back to Set Up and stop mirror updates, swipe up from bottom of launched mirror, and press Back." />
android:text="@string/how_to_stop" />
</LinearLayout>
</ScrollView>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<string name="found_location">Found location</string>
<string name="mood_explanation">Uses the front facing camera to read your expression</string>
<string name="stock_description">Displays on weekdays if the stock swings more than 3%</string>
<string name="biking_hint">Show biking weather hint</string>
<string name="how_to_stop">To get back to Set Up and stop mirror updates, swipe up from bottom of launched mirror, and press Back.</string>

</resources>

0 comments on commit c737b9d

Please sign in to comment.