Skip to content

Commit

Permalink
#31 - fixed manual update of weather; fixed change of update periods …
Browse files Browse the repository at this point in the history
…settings
  • Loading branch information
thuryn committed Mar 15, 2018
1 parent ee72100 commit 19c782a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "org.thosp.yourlocalweather"
minSdkVersion 14
targetSdkVersion 25
versionCode 26
versionName "3.0"
versionCode 27
versionName "3.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
playAccountConfig = playAccountConfigs.defaultAccountConfig
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<intent-filter>
<action android:name="org.thosp.yourlocalweather.action.START_ALARM_SERVICE" />
<action android:name="org.thosp.yourlocalweather.action.START_LOCATION_WEATHER_ALARM" />
<action android:name="org.thosp.yourlocalweather.action.RESTART_ALARM_SERVICE" />
</intent-filter>
</service>
<service android:name=".service.LocationUpdateService" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void updateSummary(String key, boolean changing) {
case Constants.KEY_PREF_LOCATION_AUTO_UPDATE_PERIOD:
entrySummary(key);
if (changing) {
Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.START_ALARM_SERVICE");
Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.RESTART_ALARM_SERVICE");
intentToStartUpdate.setPackage("org.thosp.yourlocalweather");
getActivity().startService(intentToStartUpdate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public int onStartCommand(Intent intent, int flags, final int startId) {
appendLog(getBaseContext(), TAG, "onStartCommand:intent.getAction():" + intent.getAction());
if ("org.thosp.yourlocalweather.action.START_ALARM_SERVICE".equals(intent.getAction())) {
setAlarm();
} else if ("org.thosp.yourlocalweather.action.RESTART_ALARM_SERVICE".equals(intent.getAction())) {
alarmStarted = false;
setAlarm();
} else if ("org.thosp.yourlocalweather.action.START_LOCATION_WEATHER_ALARM".equals(intent.getAction())) {
boolean autoLocation = intent.getBooleanExtra("autoLocation", false);
LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(getBaseContext());
Expand All @@ -56,7 +59,7 @@ public int onStartCommand(Intent intent, int flags, final int startId) {
if (autoLocation && !"0".equals(updateAutoPeriodStr)) {
long updateAutoPeriodMills = Utils.intervalMillisForAlarm(updateAutoPeriodStr);
scheduleNextRegularAlarm(true, updateAutoPeriodMills);
} else {
} else if (!"0".equals(updatePeriodStr) && (locationsDbHelper.getAllRows().size() > 1)) {
scheduleNextRegularAlarm(false, updatePeriodMills);
}

Expand Down Expand Up @@ -87,6 +90,7 @@ public void setAlarm() {
alarmStarted = true;
cancelAlarm(true);
cancelAlarm(false);
sendSensorStopIntent();
LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(getBaseContext());
String updatePeriodStr = AppPreference.getLocationUpdatePeriod(getBaseContext());
String updateAutoPeriodStr = AppPreference.getLocationAutoUpdatePeriod(getBaseContext());
Expand All @@ -105,7 +109,7 @@ public void setAlarm() {
scheduleNextRegularAlarm(true, updateAutoPeriodMills);
}
}
if (!"0".equals(updatePeriodStr) && locationsDbHelper.getAllRows().size() > 1) {
if (!"0".equals(updatePeriodStr) && (locationsDbHelper.getAllRows().size() > 1)) {
scheduleNextRegularAlarm(false, updatePeriodMills);
}
}
Expand Down Expand Up @@ -154,6 +158,9 @@ private void sendSensorStopIntent() {
Intent sendIntent = new Intent("android.intent.action.STOP_SENSOR_BASED_UPDATES");
sendIntent.setPackage("org.thosp.yourlocalweather");
startService(sendIntent);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(getPendingSensorStartIntent());
getPendingSensorStartIntent().cancel();
appendLog(getBaseContext(), TAG, "sendIntent:" + sendIntent);
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
</string-array>

<string-array name="notification_refresh_intervals_entries">
<item>@string/update_period_nothing</item>
<item>@string/update_period_15min</item>
<item>@string/update_period_30min</item>
<item>@string/update_period_1hour</item>
Expand All @@ -60,7 +59,6 @@
<item>@string/update_period_24hours</item>
</string-array>
<string-array name="notification_refresh_interval_values" translatable="false">
<item>0</item>
<item>15</item>
<item>30</item>
<item>60</item>
Expand Down Expand Up @@ -92,6 +90,7 @@
</string-array>

<string-array name="location_update_period_entries">
<item>@string/update_period_nothing</item>
<item>@string/update_period_15min</item>
<item>@string/update_period_30min</item>
<item>@string/update_period_1hour</item>
Expand All @@ -101,6 +100,7 @@
<item>@string/update_period_24hours</item>
</string-array>
<string-array name="location_update_period_values" translatable="false">
<item>0</item>
<item>15</item>
<item>30</item>
<item>60</item>
Expand Down

0 comments on commit 19c782a

Please sign in to comment.