Skip to content

Commit be222b0

Browse files
don't show + button on list widget when showing all notes
1 parent c2fea3b commit be222b0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/src/main/java/com/nononsenseapps/notepad/widget/list/ListWidgetConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,10 @@ public void onLoaderReset(@NonNull Loader<Cursor> l) {
354354
}
355355

356356
/**
357-
* Calling {@link SimpleWidgetPreviewAdapter#notifyDataSetChanged} on {@link #mNotesAdapter}
358-
* can only refresh the views, but it doesn't change the cursor, so it can't toggle between
359-
* "do/dont show completed notes". This function can, because it updates the underlying cursor
357+
* Calling {@link SimpleWidgetPreviewAdapter#notifyDataSetChanged} on
358+
* {@link #mNotesAdapter} can only refresh the views, but it doesn't change the
359+
* cursor, so it can't toggle between "do/dont show completed notes". This function
360+
* can, because it updates the underlying cursor
360361
*/
361362
void reloadTasks() {
362363
LoaderManager.getInstance(this).restartLoader(0, null, mCallback);

app/src/main/java/com/nononsenseapps/notepad/widget/list/ListWidgetProvider.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public static RemoteViews buildRemoteViews(final Context context,
231231
PendingIntent openConfigPendingIntent = getThePendingIntentForActivity(configIntent, context);
232232
rv.setOnClickPendingIntent(R.id.widgetConfigButton, openConfigPendingIntent);
233233

234+
// + button to create a new note from the widget
234235
final Intent createIntent = new Intent();
235236
createIntent
236237
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
@@ -240,8 +241,15 @@ public static RemoteViews buildRemoteViews(final Context context,
240241
.setData(Uri.withAppendedPath(Task.URI, "/widget/" + appWidgetId + "/-1"))
241242
.putExtra(TaskDetailFragment.ARG_ITEM_LIST_ID, listId);
242243

243-
PendingIntent createPendingIntent = getThePendingIntentForActivity(createIntent, context);
244-
rv.setOnClickPendingIntent(R.id.createNoteButton, createPendingIntent);
244+
if (listId > 0) {
245+
rv.setViewVisibility(R.id.createNoteButton, View.VISIBLE);
246+
PendingIntent createPendingIntent = getThePendingIntentForActivity(createIntent, context);
247+
rv.setOnClickPendingIntent(R.id.createNoteButton, createPendingIntent);
248+
} else {
249+
// the widget is showing notes from all lists: hide the + button,
250+
// because it would not find a valid list to add a note to
251+
rv.setViewVisibility(R.id.createNoteButton, View.GONE);
252+
}
245253

246254
return rv;
247255
}

0 commit comments

Comments
 (0)