@@ -12,6 +12,7 @@ import android.appwidget.AppWidgetProvider
1212import android.content.ComponentName
1313import android.content.Context
1414import android.content.Intent
15+ import android.view.View
1516import android.widget.RemoteViews
1617import androidx.core.net.toUri
1718import it.niedermann.owncloud.notes.R
@@ -35,10 +36,16 @@ class SingleNoteWidget : AppWidgetProvider() {
3536 override fun onReceive (context : Context , intent : Intent ? ) {
3637 super .onReceive(context, intent)
3738 val awm = AppWidgetManager .getInstance(context)
38-
3939 val provider = ComponentName (context, SingleNoteWidget ::class .java)
4040 val appWidgetIds = awm.getAppWidgetIds(provider)
41- updateAppWidget(context, awm, appWidgetIds)
41+
42+ if (intent?.action == ACTION_DATA_CHANGED ) {
43+ appWidgetIds.forEach { appWidgetId ->
44+ awm.notifyAppWidgetViewDataChanged(appWidgetId, R .id.single_note_widget_lv)
45+ }
46+ } else {
47+ updateAppWidget(context, awm, appWidgetIds)
48+ }
4249 }
4350
4451 override fun onDeleted (context : Context , appWidgetIds : IntArray ) {
@@ -104,19 +111,19 @@ class SingleNoteWidget : AppWidgetProvider() {
104111 R .layout.widget_single_note
105112 ).apply {
106113 setPendingIntentTemplate(R .id.single_note_widget_lv, pendingIntent)
107- setEmptyView(
108- R .id.single_note_widget_lv,
109- R .id.widget_single_note_placeholder_tv
110- )
111114 setRemoteAdapter(R .id.single_note_widget_lv, serviceIntent)
115+ setViewVisibility(R .id.widget_single_note_placeholder_tv, View .VISIBLE )
116+ setTextViewText(R .id.widget_single_note_placeholder_tv, context.getString(R .string.widget_single_note_loading))
112117 }
113118 }
114119
115120 companion object {
121+ private const val ACTION_DATA_CHANGED = " it.niedermann.owncloud.notes.ACTION_WIDGET_DATA_CHANGED"
122+
116123 @JvmStatic
117124 fun updateSingleNoteWidgets (context : Context ) {
118125 val intent = Intent (context, SingleNoteWidget ::class .java).apply {
119- setAction( AppWidgetManager . ACTION_APPWIDGET_UPDATE )
126+ action = ACTION_DATA_CHANGED
120127 }
121128 context.sendBroadcast(intent)
122129 }
0 commit comments