mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 06:08:51 +00:00
NearestFavoriteStationWidgetService: Run appwidget update in foreground.
This commit is contained in:
parent
1f66669608
commit
4c4d967c54
7 changed files with 54 additions and 0 deletions
|
@ -33,6 +33,7 @@
|
|||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
|
||||
<uses-feature
|
||||
|
|
|
@ -14,6 +14,7 @@ dependencies {
|
|||
compile 'androidx.annotation:annotation:1.0.0'
|
||||
compile 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
compile 'androidx.drawerlayout:drawerlayout:1.0.0'
|
||||
compile 'androidx.core:core:1.0.0'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.12.0'
|
||||
compile 'com.squareup.okhttp3:logging-interceptor:3.12.0'
|
||||
compile 'com.google.guava:guava:27.0.1-android'
|
||||
|
|
9
oeffi/res/drawable-anydpi/ic_stat_notify_sync_24dp.xml
Executable file
9
oeffi/res/drawable-anydpi/ic_stat_notify_sync_24dp.xml
Executable file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
|
||||
</vector>
|
|
@ -334,6 +334,7 @@
|
|||
<string name="alert_crash_report_update">Google Play</string>
|
||||
<string name="alert_crash_report_download">Herunterladen</string>
|
||||
<string name="alert_crash_report_negative">Schließen</string>
|
||||
<string name="notification_channel_appwidget_name">App-Widget-Aktivität</string>
|
||||
|
||||
<!-- products -->
|
||||
<string name="product_i">Fernverkehr</string>
|
||||
|
|
|
@ -335,6 +335,7 @@
|
|||
<string name="alert_crash_report_update">Google Play</string>
|
||||
<string name="alert_crash_report_download">Download</string>
|
||||
<string name="alert_crash_report_negative">Dismiss</string>
|
||||
<string name="notification_channel_appwidget_name">App-widget activity</string>
|
||||
|
||||
<!-- products -->
|
||||
<string name="product_i">Highspeed</string>
|
||||
|
|
|
@ -30,13 +30,18 @@ import com.google.common.base.Stopwatch;
|
|||
|
||||
import de.schildbach.oeffi.directions.QueryHistoryProvider;
|
||||
import de.schildbach.oeffi.stations.FavoriteStationsProvider;
|
||||
import de.schildbach.oeffi.stations.NearestFavoriteStationWidgetService;
|
||||
import de.schildbach.oeffi.util.Downloader;
|
||||
import de.schildbach.oeffi.util.ErrorReporter;
|
||||
import de.schildbach.pte.NetworkId;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
@ -147,6 +152,8 @@ public class Application extends android.app.Application {
|
|||
QueryHistoryProvider.migrateQueryHistory(this, VAGFR, NetworkId.NVBW);
|
||||
|
||||
log.info("Migrations took {}", watch);
|
||||
|
||||
initNotificationManager();
|
||||
}
|
||||
|
||||
private void initLogging() {
|
||||
|
@ -202,6 +209,20 @@ public class Application extends android.app.Application {
|
|||
config.setUserAgentValue(getPackageName());
|
||||
}
|
||||
|
||||
private void initNotificationManager() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
final Stopwatch watch = Stopwatch.createStarted();
|
||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
final NotificationChannel appwidget = new NotificationChannel(
|
||||
NearestFavoriteStationWidgetService.NOTIFICATION_CHANNEL_ID_APPWIDGET,
|
||||
getString(R.string.notification_channel_appwidget_name), NotificationManager.IMPORTANCE_LOW);
|
||||
nm.createNotificationChannel(appwidget);
|
||||
|
||||
log.info("created notification channels, took {}", watch);
|
||||
}
|
||||
}
|
||||
|
||||
private void migrateSelectedNetwork(final String fromName, final NetworkId to) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ import android.location.LocationListener;
|
|||
import android.location.LocationManager;
|
||||
import android.location.LocationProvider;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
|
@ -70,6 +71,7 @@ import android.text.format.DateFormat;
|
|||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
import androidx.core.app.JobIntentService;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class NearestFavoriteStationWidgetService extends JobIntentService {
|
||||
|
@ -80,6 +82,8 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
|||
private Handler backgroundHandler;
|
||||
|
||||
private static final int JOB_ID = 1;
|
||||
public static final String NOTIFICATION_CHANNEL_ID_APPWIDGET = "appwidget";
|
||||
private static final int NOTIFICATION_ID_APPWIDGET_UPDATE = 1;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NearestFavoriteStationWidgetService.class);
|
||||
|
||||
|
@ -110,6 +114,22 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
|||
|
||||
@Override
|
||||
protected void onHandleWork(final Intent intent) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
final NotificationCompat.Builder notification = new NotificationCompat.Builder(this,
|
||||
NOTIFICATION_CHANNEL_ID_APPWIDGET);
|
||||
notification.setSmallIcon(R.drawable.ic_stat_notify_sync_24dp);
|
||||
notification.setWhen(System.currentTimeMillis());
|
||||
notification.setOngoing(true);
|
||||
startForeground(NOTIFICATION_ID_APPWIDGET_UPDATE, notification.build());
|
||||
}
|
||||
|
||||
handleIntent();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
final ComponentName providerName = new ComponentName(this, NearestFavoriteStationWidgetProvider.class);
|
||||
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue