Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/data/GtfsMaintenanceWorker.kt
| Show All 26 Lines | class GtfsMaintenanceWorker(appContext: Context, workerParams: WorkerParameters) | ||||
| } | } | ||||
| override suspend fun getForegroundInfo(): ForegroundInfo { | override suspend fun getForegroundInfo(): ForegroundInfo { | ||||
| val context = applicationContext | val context = applicationContext | ||||
| Notifications.createDBNotificationChannelIfNeeded(context) | Notifications.createDBNotificationChannelIfNeeded(context) | ||||
| val notification = NotificationCompat.Builder(context, Notifications.DB_UPDATE_CHANNELS_ID) | val notification = NotificationCompat.Builder(context, Notifications.DB_UPDATE_CHANNELS_ID) | ||||
| //.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), Constants.PENDING_INTENT_FLAG_IMMUTABLE)) | //.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), Constants.PENDING_INTENT_FLAG_IMMUTABLE)) | ||||
| .setSmallIcon(R.drawable.bus) | .setSmallIcon(R.drawable.ic_bus) | ||||
| .setOngoing(true) | .setOngoing(true) | ||||
| .setAutoCancel(true) | .setAutoCancel(true) | ||||
| .setOnlyAlertOnce(true) | .setOnlyAlertOnce(true) | ||||
| .setPriority(NotificationCompat.PRIORITY_MIN) | .setPriority(NotificationCompat.PRIORITY_MIN) | ||||
| .setContentTitle(context.getString(R.string.app_name)) | .setContentTitle(context.getString(R.string.app_name)) | ||||
| .setLocalOnly(true) | .setLocalOnly(true) | ||||
| .setVisibility(NotificationCompat.VISIBILITY_SECRET) | .setVisibility(NotificationCompat.VISIBILITY_SECRET) | ||||
| .setContentText("Database maintenance") | .setContentText("Database maintenance") | ||||
| .build() | .build() | ||||
| return ForegroundInfo(3671672811121.toInt(), notification) | return ForegroundInfo(3671672811121.toInt(), notification) | ||||
| } | } | ||||
| companion object{ | companion object{ | ||||
| const val CLEAR_GTFS_TRIPS="trips_clear" | const val CLEAR_GTFS_TRIPS="trips_clear" | ||||
| const val OPERATION_TYPE="oper_type" | const val OPERATION_TYPE="oper_type" | ||||
| fun makeOneTimeRequest(type: String): OneTimeWorkRequest { | fun makeOneTimeRequest(type: String): OneTimeWorkRequest { | ||||
| val data = Data.Builder().putString(OPERATION_TYPE, type).build() | val data = Data.Builder().putString(OPERATION_TYPE, type).build() | ||||
| return OneTimeWorkRequest.Builder(GtfsMaintenanceWorker::class.java) | return OneTimeWorkRequest.Builder(GtfsMaintenanceWorker::class.java) | ||||
| .setInputData(data).setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) | .setInputData(data).setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) | ||||
| .addTag(type) | .addTag(type) | ||||
| .build() | .build() | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| No newline at end of file | No newline at end of file | ||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register