1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

Add experimental support for TinyWeatherForecastGermany

This commit is contained in:
Andreas Shimokawa 2020-07-05 21:54:10 +02:00
parent c437347236
commit 7980d928a8
2 changed files with 77 additions and 16 deletions

View File

@ -0,0 +1,44 @@
/* Copyright (C) 2020 Andreas Shimokawa
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
public class TinyWeatherForecastGermanyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
WeatherSpec weatherSpec = bundle.getParcelable("WeatherSpec");
if (weatherSpec != null) {
Weather.getInstance().setWeatherSpec(weatherSpec);
GBApplication.deviceService().onSendWeather(weatherSpec);
}
}
}
}
}

View File

@ -63,6 +63,7 @@ import nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.TinyWeatherForecastGermanyReceiver;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec; import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
@ -197,6 +198,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
private CalendarReceiver mCalendarReceiver = null; private CalendarReceiver mCalendarReceiver = null;
private CMWeatherReceiver mCMWeatherReceiver = null; private CMWeatherReceiver mCMWeatherReceiver = null;
private LineageOsWeatherReceiver mLineageOsWeatherReceiver = null; private LineageOsWeatherReceiver mLineageOsWeatherReceiver = null;
private TinyWeatherForecastGermanyReceiver mTinyWeatherForecastGermanyReceiver = null;
private OmniJawsObserver mOmniJawsObserver = null; private OmniJawsObserver mOmniJawsObserver = null;
private final String[] mMusicActions = { private final String[] mMusicActions = {
@ -735,18 +737,26 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
filter.addAction(AlarmClockReceiver.GOOGLE_CLOCK_ALARM_DONE_ACTION); filter.addAction(AlarmClockReceiver.GOOGLE_CLOCK_ALARM_DONE_ACTION);
registerReceiver(mAlarmClockReceiver, filter); registerReceiver(mAlarmClockReceiver, filter);
} }
if (mCMWeatherReceiver == null && coordinator != null && coordinator.supportsWeather()) {
mCMWeatherReceiver = new CMWeatherReceiver();
registerReceiver(mCMWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER"));
}
if (GBApplication.isRunningOreoOrLater()) {
if (mLineageOsWeatherReceiver == null && coordinator != null && coordinator.supportsWeather()) {
// Weather receivers
if ( coordinator != null && coordinator.supportsWeather()) {
if (GBApplication.isRunningOreoOrLater()) {
if (mLineageOsWeatherReceiver == null) {
mLineageOsWeatherReceiver = new LineageOsWeatherReceiver(); mLineageOsWeatherReceiver = new LineageOsWeatherReceiver();
registerReceiver(mLineageOsWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER")); registerReceiver(mLineageOsWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER"));
} }
} }
if (mOmniJawsObserver == null && coordinator != null && coordinator.supportsWeather()) { else {
if (mCMWeatherReceiver == null) {
mCMWeatherReceiver = new CMWeatherReceiver();
registerReceiver(mCMWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER"));
}
}
if (mTinyWeatherForecastGermanyReceiver == null) {
mTinyWeatherForecastGermanyReceiver = new TinyWeatherForecastGermanyReceiver();
registerReceiver(mTinyWeatherForecastGermanyReceiver, new IntentFilter("de.kaffeemitkoffein.broadcast.WEATHERDATA"));
}
if (mOmniJawsObserver == null) {
try { try {
mOmniJawsObserver = new OmniJawsObserver(new Handler()); mOmniJawsObserver = new OmniJawsObserver(new Handler());
getContentResolver().registerContentObserver(OmniJawsObserver.WEATHER_URI, true, mOmniJawsObserver); getContentResolver().registerContentObserver(OmniJawsObserver.WEATHER_URI, true, mOmniJawsObserver);
@ -754,6 +764,8 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
//Nothing wrong, it just means we're not running on omnirom. //Nothing wrong, it just means we're not running on omnirom.
} }
} }
}
if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) && if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) &&
coordinator != null && coordinator.supportsActivityDataFetching() && mGBAutoFetchReceiver == null) { coordinator != null && coordinator.supportsActivityDataFetching() && mGBAutoFetchReceiver == null) {
mGBAutoFetchReceiver = new GBAutoFetchReceiver(); mGBAutoFetchReceiver = new GBAutoFetchReceiver();
@ -807,6 +819,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
} }
if (mOmniJawsObserver != null) { if (mOmniJawsObserver != null) {
getContentResolver().unregisterContentObserver(mOmniJawsObserver); getContentResolver().unregisterContentObserver(mOmniJawsObserver);
mOmniJawsObserver = null;
}
if (mTinyWeatherForecastGermanyReceiver != null) {
unregisterReceiver(mTinyWeatherForecastGermanyReceiver);
mTinyWeatherForecastGermanyReceiver = null;
} }
if (mGBAutoFetchReceiver != null) { if (mGBAutoFetchReceiver != null) {
unregisterReceiver(mGBAutoFetchReceiver); unregisterReceiver(mGBAutoFetchReceiver);