adding some null checks at AppWidgetManager
This commit is contained in:
parent
f646d4e5b2
commit
e588494ff5
|
@ -47,7 +47,7 @@ val Context.eventsHelper: EventsHelper get() = EventsHelper(this)
|
|||
val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this)
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java))
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java)) ?: return
|
||||
if (widgetIDs.isNotEmpty()) {
|
||||
Intent(applicationContext, MyWidgetMonthlyProvider::class.java).apply {
|
||||
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
|
@ -61,7 +61,7 @@ fun Context.updateWidgets() {
|
|||
}
|
||||
|
||||
fun Context.updateListWidget() {
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetListProvider::class.java))
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetListProvider::class.java)) ?: return
|
||||
if (widgetIDs.isNotEmpty()) {
|
||||
Intent(applicationContext, MyWidgetListProvider::class.java).apply {
|
||||
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
|
@ -72,7 +72,7 @@ fun Context.updateListWidget() {
|
|||
}
|
||||
|
||||
fun Context.updateDateWidget() {
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateProvider::class.java))
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateProvider::class.java)) ?: return
|
||||
if (widgetIDs.isNotEmpty()) {
|
||||
Intent(applicationContext, MyWidgetDateProvider::class.java).apply {
|
||||
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
|
|
|
@ -31,7 +31,7 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
|||
val fontSize = context.getWidgetFontSize()
|
||||
val textColor = context.config.widgetTextColor
|
||||
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
|
||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_event_list).apply {
|
||||
applyColorFilter(R.id.widget_event_list_background, context.config.widgetBgColor)
|
||||
|
@ -97,7 +97,7 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
|||
|
||||
// hacky solution for reseting the events list
|
||||
private fun goToToday(context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
|
||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_event_list)
|
||||
Intent(context, WidgetServiceEmpty::class.java).apply {
|
||||
|
|
|
@ -177,7 +177,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||
val textColor = context.config.widgetTextColor
|
||||
val resources = context.resources
|
||||
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
|
||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.fragment_month_widget)
|
||||
views.setText(R.id.top_value, month)
|
||||
|
|
Loading…
Reference in New Issue