Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.RemoteViews
import androidx.core.net.toUri
import it.niedermann.owncloud.notes.R
Expand All @@ -35,10 +36,16 @@ class SingleNoteWidget : AppWidgetProvider() {
override fun onReceive(context: Context, intent: Intent?) {
super.onReceive(context, intent)
val awm = AppWidgetManager.getInstance(context)

val provider = ComponentName(context, SingleNoteWidget::class.java)
val appWidgetIds = awm.getAppWidgetIds(provider)
updateAppWidget(context, awm, appWidgetIds)

if (intent?.action == ACTION_DATA_CHANGED) {
appWidgetIds.forEach { appWidgetId ->
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv)
}
} else {
updateAppWidget(context, awm, appWidgetIds)
}
}

override fun onDeleted(context: Context, appWidgetIds: IntArray) {
Expand Down Expand Up @@ -104,19 +111,19 @@ class SingleNoteWidget : AppWidgetProvider() {
R.layout.widget_single_note
).apply {
setPendingIntentTemplate(R.id.single_note_widget_lv, pendingIntent)
setEmptyView(
R.id.single_note_widget_lv,
R.id.widget_single_note_placeholder_tv
)
setRemoteAdapter(R.id.single_note_widget_lv, serviceIntent)
setViewVisibility(R.id.widget_single_note_placeholder_tv, View.VISIBLE)
setTextViewText(R.id.widget_single_note_placeholder_tv, context.getString(R.string.widget_single_note_loading))
}
}

companion object {
private const val ACTION_DATA_CHANGED = "it.niedermann.owncloud.notes.ACTION_WIDGET_DATA_CHANGED"

@JvmStatic
fun updateSingleNoteWidgets(context: Context) {
val intent = Intent(context, SingleNoteWidget::class.java).apply {
setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
action = ACTION_DATA_CHANGED
}
context.sendBroadcast(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

Expand Down Expand Up @@ -53,9 +54,16 @@ public void onDataSetChanged() {
Log.v(TAG, "Fetch note with id " + noteId);
note = repo.getNoteById(noteId);

final var views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
if (note == null) {
Log.e(TAG, "Error: note not found");
views.setViewVisibility(R.id.widget_single_note_placeholder_tv, View.VISIBLE);
views.setTextViewText(R.id.widget_single_note_placeholder_tv,
context.getString(R.string.widget_single_note_note_not_found));
} else {
views.setViewVisibility(R.id.widget_single_note_placeholder_tv, View.GONE);
}
AppWidgetManager.getInstance(context).partiallyUpdateAppWidget(appWidgetId, views);
} else {
Log.w(TAG, "Widget with ID " + appWidgetId + " seems to be not configured yet.");
}
Expand Down Expand Up @@ -110,7 +118,6 @@ public RemoteViews getViewAt(int position) {
}


// TODO Set loading view
@Override
public RemoteViews getLoadingView() {
return null;
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/widget_single_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
android:layout_height="match_parent"
android:gravity="center"
android:padding="@dimen/spacer_1x"
android:text="@string/widget_single_note_placeholder_tv"
android:text="@string/widget_single_note_note_not_found"
android:textAlignment="center"
android:textColor="@color/widget_foreground" />
android:textColor="@color/widget_foreground"
android:visibility="gone" />

</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
<string name="widget_note_list_title">Note list</string>
<string name="widget_note_list_placeholder">No notes</string>
<string name="widget_single_note_title">Single note</string>
<string name="widget_single_note_placeholder_tv">Note not found</string>
<string name="widget_single_note_loading">Loading note…</string>
<string name="widget_single_note_note_not_found">Note not found</string>
<string name="widget_not_logged_in">Please login to Notes before using this widget</string>
<string name="widget_entry_fav_contentDescription">Star icon is used to denote an item as a favorite</string>

Expand Down
Loading