Search in sources :

Example 6 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsTable method getLatestNotes.

public static ArrayList<Note> getLatestNotes(int limit) {
    Cursor cursor = getDb().query(NOTIFICATIONS_TABLE, new String[] { "note_id", "raw_note_data" }, null, null, null, null, "timestamp DESC", "" + limit);
    ArrayList<Note> notes = new ArrayList<Note>();
    while (cursor.moveToNext()) {
        String note_id = cursor.getString(0);
        String raw_note_data = cursor.getString(1);
        try {
            Note note = new Note(note_id, new JSONObject(raw_note_data));
            notes.add(note);
        } catch (JSONException e) {
            AppLog.e(AppLog.T.DB, "Can't parse notification with note_id:" + note_id + ", exception:" + e);
        }
    }
    cursor.close();
    return notes;
}
Also used : JSONObject(org.json.JSONObject) Note(org.wordpress.android.models.Note) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Example 7 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsActions method parseNotes.

public static List<Note> parseNotes(JSONObject response) throws JSONException {
    List<Note> notes;
    JSONArray notesJSON = response.getJSONArray("notes");
    notes = new ArrayList<>(notesJSON.length());
    for (int i = 0; i < notesJSON.length(); i++) {
        Note n = new Note(notesJSON.getJSONObject(i));
        notes.add(n);
    }
    return notes;
}
Also used : Note(org.wordpress.android.models.Note) JSONArray(org.json.JSONArray)

Example 8 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsUtils method buildNoteObjectFromBundle.

public static Note buildNoteObjectFromBundle(Bundle data) {
    if (data == null) {
        AppLog.e(T.NOTIFS, "Bundle is null! Cannot read '" + GCMMessageService.PUSH_ARG_NOTE_ID + "'.");
        return null;
    }
    Note note;
    String noteId = data.getString(GCMMessageService.PUSH_ARG_NOTE_ID, "");
    String base64FullData = data.getString(GCMMessageService.PUSH_ARG_NOTE_FULL_DATA);
    note = Note.buildFromBase64EncodedData(noteId, base64FullData);
    if (note == null) {
        // At this point we don't have the note :(
        AppLog.w(T.NOTIFS, "Cannot build the Note object by using info available in the PN payload. Please see " + "previous log messages for detailed information about the error.");
    }
    return note;
}
Also used : Note(org.wordpress.android.models.Note)

Aggregations

Note (org.wordpress.android.models.Note)8 Cursor (android.database.Cursor)1 ViewPager (android.support.v4.view.ViewPager)1 ActionBar (android.support.v7.app.ActionBar)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)1 NotesAdapter (org.wordpress.android.ui.notifications.adapters.NotesAdapter)1 WPViewPager (org.wordpress.android.widgets.WPViewPager)1 WPViewPagerTransformer (org.wordpress.android.widgets.WPViewPagerTransformer)1