diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-03-07 12:13:37 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-03-08 00:11:22 +0300 |
commit | 6cbbab725d7f29ee50db51786c5c519bbdaf70de (patch) | |
tree | e591c9e14d969974d1b15fe7c890223d4822217f /app/src/main/java/it/niedermann/owncloud/notes/widget | |
parent | 71f4b5da16bb51a408a2630b289f848fa10e5766 (diff) |
Prepare first entry of list widget to be scrollable
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/widget')
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java index f4179d97..901a9f3e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java @@ -1,5 +1,6 @@ package it.niedermann.owncloud.notes.widget.notelist; +import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; @@ -9,15 +10,18 @@ import android.util.Log; import android.widget.RemoteViews; import android.widget.RemoteViewsService; +import java.util.ArrayList; import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; import it.niedermann.owncloud.notes.edit.EditNoteActivity; +import it.niedermann.owncloud.notes.shared.model.Category; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.NotesApplication; +import static it.niedermann.owncloud.notes.edit.EditNoteActivity.PARAM_CATEGORY; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_CATEGORY; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_STARRED; @@ -27,8 +31,8 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact private final Context context; private final NoteListsWidgetData data; - private NotesDatabase db; - private List<DBNote> dbNotes; + private final NotesDatabase db; + private final List<DBNote> dbNotes = new ArrayList<>(); NoteListWidgetFactory(Context context, Intent intent) { this.context = context; @@ -45,18 +49,19 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact @Override public void onDataSetChanged() { + dbNotes.clear(); try { Log.v(TAG, "--- data - " + data); switch (data.getMode()) { case MODE_DISPLAY_ALL: - dbNotes = db.getNotes(data.getAccountId()); + dbNotes.addAll(db.getNotes(data.getAccountId())); break; case MODE_DISPLAY_STARRED: - dbNotes = db.searchNotes(data.getAccountId(), null, null, true); + dbNotes.addAll(db.searchNotes(data.getAccountId(), null, null, true)); break; case MODE_DISPLAY_CATEGORY: if (data.getCategoryId() != null) { - dbNotes = db.searchNotes(data.getAccountId(), null, db.getCategoryTitleById(data.getAccountId(), data.getCategoryId()), null); + dbNotes.addAll(db.searchNotes(data.getAccountId(), null, db.getCategoryTitleById(data.getAccountId(), data.getCategoryId()), null)); } break; } @@ -77,37 +82,50 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact */ @Override public int getCount() { - if (dbNotes == null) { - return 0; - } - return dbNotes.size(); } @Override public RemoteViews getViewAt(int position) { - RemoteViews note_content; - - if (dbNotes == null || position > dbNotes.size() - 1 || dbNotes.get(position) == null) { - Log.e(TAG, "Could not find position \"" + position + "\" in dbNotes list."); - return null; - } + final RemoteViews note_content; + +// if(position == 0) { +// final Intent fillInIntent = new Intent(); +// final Bundle extras = new Bundle(); +// extras.putExtra(PARAM_CATEGORY, new Category(db.getCategoryTitleById(data.getAccountId(), data.getCategoryId()), data.getMode() == MODE_DISPLAY_STARRED)), +// extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId()); +// +// fillInIntent.putExtras(extras); +// fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME))); +// +// fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME))); +// +// note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry); +// note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent); +// note_content.setTextViewText(R.id.widget_entry_content_tv, "Add new note in this category"); +// note_content.setImageViewResource(R.id.widget_entry_fav_icon, R.drawable.ic_add_blue_24dp); +// } else { + if (position > dbNotes.size() - 1 || dbNotes.get(position) == null) { + Log.e(TAG, "Could not find position \"" + position + "\" in dbNotes list."); + return null; + } - DBNote note = dbNotes.get(position); - final Intent fillInIntent = new Intent(); - final Bundle extras = new Bundle(); - extras.putLong(EditNoteActivity.PARAM_NOTE_ID, note.getId()); - extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId()); - - fillInIntent.putExtras(extras); - fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME))); - - note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry); - note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent); - note_content.setTextViewText(R.id.widget_entry_content_tv, note.getTitle()); - note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.isFavorite() - ? R.drawable.ic_star_yellow_24dp - : R.drawable.ic_star_grey_ccc_24dp); + DBNote note = dbNotes.get(position); + final Intent fillInIntent = new Intent(); + final Bundle extras = new Bundle(); + extras.putLong(EditNoteActivity.PARAM_NOTE_ID, note.getId()); + extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId()); + + fillInIntent.putExtras(extras); + fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME))); + + note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry); + note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent); + note_content.setTextViewText(R.id.widget_entry_content_tv, note.getTitle()); + note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.isFavorite() + ? R.drawable.ic_star_yellow_24dp + : R.drawable.ic_star_grey_ccc_24dp); +// } return note_content; |