Loading app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java +48 −30 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.widget.notelist; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; Loading @@ -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; Loading @@ -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; Loading @@ -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; } Loading @@ -77,18 +82,30 @@ 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) { 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; } Loading @@ -108,6 +125,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact 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; Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java +48 −30 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.widget.notelist; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; Loading @@ -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; Loading @@ -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; Loading @@ -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; } Loading @@ -77,18 +82,30 @@ 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) { 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; } Loading @@ -108,6 +125,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact 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; Loading