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 @@ -114,8 +114,6 @@ class SingleNoteWidget : AppWidgetProvider() {
).apply {
setPendingIntentTemplate(R.id.single_note_widget_lv, pendingIntent)
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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,33 @@ public void onCreate() {
@Override
public void onDataSetChanged() {
final var data = repo.getSingleNoteWidgetData(appWidgetId);
if (data != null) {
final long noteId = data.getNoteId();
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.");
final var views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
if (data == null) {
showErrorView(context, views);
return;
}

final long noteId = data.getNoteId();
note = repo.getNoteById(noteId);
Log.v(TAG, "Fetch note with id " + noteId);

if (note == null) {
showErrorView(context, views);
Log.e(TAG, "Error: note not found");
return;
}
views.setViewVisibility(R.id.widget_single_note_placeholder_tv, View.GONE);

AppWidgetManager.getInstance(context).partiallyUpdateAppWidget(appWidgetId, views);
}

private void showErrorView(Context context, RemoteViews views) {
views.setViewVisibility(R.id.single_note_widget_lv, View.GONE);
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));

AppWidgetManager.getInstance(context).partiallyUpdateAppWidget(appWidgetId, views);
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/widget_single_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
android:layout_height="match_parent"
android:gravity="center"
android:padding="@dimen/spacer_1x"
android:text="@string/widget_single_note_note_not_found"
android:text="@string/widget_single_note_loading"
android:textAlignment="center"
android:textColor="@color/widget_foreground"
android:visibility="gone" />
android:textColor="@color/widget_foreground" />

</RelativeLayout>
Loading