Search in sources :

Example 1 with DeckStatus

use of com.ichi2.widget.DeckStatus in project Anki-Android by Ramblurr.

the class MetaDB method storeWidgetStatus.

/**
     * Stores the current state of the widget.
     * <p>
     * It replaces any stored state for the widget.
     * 
     * @param decks an array of {@link DeckStatus} objects, one for each of the know decks.
     */
public static void storeWidgetStatus(Context context, DeckStatus[] decks) {
    openDBIfClosed(context);
    try {
        mMetaDb.beginTransaction();
        try {
            // First clear all the existing content.
            mMetaDb.execSQL("DELETE FROM widgetStatus");
            for (DeckStatus deck : decks) {
                mMetaDb.execSQL("INSERT INTO widgetStatus(deckId, deckName, newCards, lrnCards, dueCards, progress, eta) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", new Object[] { deck.mDeckId, deck.mDeckName, deck.mNewCards, deck.mLrnCards, deck.mDueCards, deck.mProgress, deck.mEta });
            }
            mMetaDb.setTransactionSuccessful();
        } finally {
            mMetaDb.endTransaction();
        }
    } catch (IllegalStateException e) {
        Log.e(AnkiDroidApp.TAG, "MetaDB.storeWidgetStatus: failed", e);
    } catch (SQLiteException e) {
        Log.e(AnkiDroidApp.TAG, "MetaDB.storeWidgetStatus: failed", e);
        closeDB();
        Log.i(AnkiDroidApp.TAG, "Trying to reset Widget: " + resetWidget(context));
    }
}
Also used : DeckStatus(com.ichi2.widget.DeckStatus) SQLiteException(android.database.sqlite.SQLiteException)

Example 2 with DeckStatus

use of com.ichi2.widget.DeckStatus in project Anki-Android by Ramblurr.

the class MetaDB method getWidgetStatus.

/**
     * Return the current status of the widget.
     * 
     * @return an array of {@link DeckStatus} objects, each representing the status of one of the known decks
     */
public static DeckStatus[] getWidgetStatus(Context context) {
    openDBIfClosed(context);
    Cursor cursor = null;
    try {
        cursor = mMetaDb.query("widgetStatus", new String[] { "deckId", "deckName", "newCards", "lrnCards", "dueCards", "progress", "eta" }, null, null, null, null, "deckName");
        int count = cursor.getCount();
        DeckStatus[] decks = new DeckStatus[count];
        for (int index = 0; index < count; ++index) {
            if (!cursor.moveToNext()) {
                throw new SQLiteException("cursor count was incorrect");
            }
            decks[index] = new DeckStatus(cursor.getLong(cursor.getColumnIndexOrThrow("deckId")), cursor.getString(cursor.getColumnIndexOrThrow("deckName")), cursor.getInt(cursor.getColumnIndexOrThrow("newCards")), cursor.getInt(cursor.getColumnIndexOrThrow("lrnCards")), cursor.getInt(cursor.getColumnIndexOrThrow("dueCards")), cursor.getInt(cursor.getColumnIndexOrThrow("progress")), cursor.getInt(cursor.getColumnIndexOrThrow("eta")));
        }
        return decks;
    } catch (SQLiteException e) {
        Log.e(AnkiDroidApp.TAG, "Error while querying widgetStatus", e);
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
    return new DeckStatus[0];
}
Also used : DeckStatus(com.ichi2.widget.DeckStatus) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)2 DeckStatus (com.ichi2.widget.DeckStatus)2 Cursor (android.database.Cursor)1