From 14578e26fcd39cf671aa4584d3abf311a66afba2 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 24 Apr 2019 19:51:37 -0700 Subject: Apply updates from services --- .../com/pitchedapps/frost/activities/BaseMainActivity.kt | 7 ++++++- .../com/pitchedapps/frost/services/NotificationService.kt | 4 ++++ .../com/pitchedapps/frost/widgets/NotificationWidget.kt | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index c43c31a2..d6f1abe7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -104,6 +104,7 @@ import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.views.BadgedIcon import com.pitchedapps.frost.views.FrostVideoViewer import com.pitchedapps.frost.views.FrostViewPager +import com.pitchedapps.frost.widgets.NotificationWidget import kotlinx.android.synthetic.main.activity_frame_wrapper.* import kotlinx.android.synthetic.main.view_main_fab.* import kotlinx.android.synthetic.main.view_main_toolbar.* @@ -450,7 +451,11 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, Runtime.getRuntime().exit(0) return } - if (resultCode and REQUEST_RESTART > 0) return restart() + if (resultCode and REQUEST_RESTART > 0) { + NotificationWidget.forceUpdate(this) + restart() + return + } /* * These results can be stacked */ diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index 760c681a..0eee5558 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -27,6 +27,7 @@ import com.pitchedapps.frost.db.selectAll import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.frostEvent +import com.pitchedapps.frost.widgets.NotificationWidget import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.isActive import kotlinx.coroutines.launch @@ -105,6 +106,9 @@ class NotificationService : BaseJobService() { L.i { "Sent $notifCount notifications" } if (notifCount == 0 && jobId == NOTIFICATION_JOB_NOW) generalNotification(665, R.string.no_new_notifications, BuildConfig.DEBUG) + if (notifCount > 0) { + NotificationWidget.forceUpdate(this@NotificationService) + } } /** diff --git a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt index 1897b042..57cc4fe1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt @@ -19,6 +19,7 @@ package com.pitchedapps.frost.widgets import android.app.PendingIntent import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider +import android.content.ComponentName import android.content.Context import android.content.Intent import android.graphics.Bitmap @@ -51,6 +52,7 @@ import org.koin.standalone.KoinComponent import org.koin.standalone.inject class NotificationWidget : AppWidgetProvider() { + override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { super.onUpdate(context, appWidgetManager, appWidgetIds) val type = NotificationType.GENERAL @@ -82,6 +84,18 @@ class NotificationWidget : AppWidgetProvider() { } appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_notification_list) } + + companion object { + fun forceUpdate(context: Context) { + val manager = AppWidgetManager.getInstance(context) + val ids = manager.getAppWidgetIds(ComponentName(context, NotificationWidget::class.java)) + val intent = Intent().apply { + action = AppWidgetManager.ACTION_APPWIDGET_UPDATE + putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids) + } + context.sendBroadcast(intent) + } + } } private const val NOTIF_WIDGET_TYPE = "notif_widget_type" -- cgit v1.2.3