0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

Fixes issue 72. Also includes my attempt to fix issue 70, which needs work

This commit is contained in:
Nicolas Raoul 2010-03-11 19:36:42 +09:00
parent 4055e3f358
commit fd529bc561
2 changed files with 22 additions and 19 deletions

View File

@ -20,6 +20,7 @@ package com.ichi2.anki;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -84,6 +85,8 @@ public class Deck
private static final double minimumAverage = 1.7; private static final double minimumAverage = 1.7;
private static final double maxScheduleTime = 36500.0; private static final double maxScheduleTime = 36500.0;
private static final Locale NULL_LOCALE = null;
// BEGIN: SQL table columns // BEGIN: SQL table columns
long id; long id;
@ -275,7 +278,7 @@ public class Deck
} finally { } finally {
if (cursor != null) cursor.close(); if (cursor != null) cursor.close();
} }
Log.i(TAG, String.format("openDeck - modified: %f currentTime: %f", deck.modified, System.currentTimeMillis()/1000.0)); Log.i(TAG, String.format(NULL_LOCALE, "openDeck - modified: %f currentTime: %f", deck.modified, System.currentTimeMillis()/1000.0));
deck.initVars(); deck.initVars();
@ -677,7 +680,7 @@ public class Deck
updateValues.put("answer", card.answer); updateValues.put("answer", card.answer);
updateValues.put("modified", now); updateValues.put("modified", now);
AnkiDb.database.update("cards", updateValues, "id = ?", new String[] {"" + card.id}); AnkiDb.database.update("cards", updateValues, "id = ?", new String[] {"" + card.id});
// AnkiDb.database.execSQL(String.format( // AnkiDb.database.execSQL(String.format(NULL_LOCALE,
// "UPDATE cards " + // "UPDATE cards " +
// "SET question = %s, " + // "SET question = %s, " +
// "answer = %s, " + // "answer = %s, " +
@ -800,7 +803,7 @@ public class Deck
} }
// space other cards // space other cards
AnkiDb.database.execSQL(String.format( AnkiDb.database.execSQL(String.format(NULL_LOCALE,
"UPDATE cards " + "UPDATE cards " +
"SET spaceUntil = %f, " + "SET spaceUntil = %f, " +
"combinedDue = max(%f, due), " + "combinedDue = max(%f, due), " +
@ -986,7 +989,7 @@ public class Deck
"WHERE type = 0 and " + "WHERE type = 0 and " +
"isDue = 1 and " + "isDue = 1 and " +
"combinedDue <= " + "combinedDue <= " +
String.format("%f", (double) (System.currentTimeMillis() / 1000.0))); String.format(NULL_LOCALE, "%f", (double) (System.currentTimeMillis() / 1000.0)));
revCount = (int) AnkiDb.queryScalar( revCount = (int) AnkiDb.queryScalar(
"SELECT count(id) " + "SELECT count(id) " +
"FROM cards " + "FROM cards " +
@ -1019,7 +1022,7 @@ public class Deck
"type = 0 and " + "type = 0 and " +
"isDue = 0 and " + "isDue = 0 and " +
"priority in (1,2,3,4) and " + "priority in (1,2,3,4) and " +
String.format("combinedDue <= %f", String.format(NULL_LOCALE, "combinedDue <= %f",
(double) ((System.currentTimeMillis() / 1000.0) + delay0)), (double) ((System.currentTimeMillis() / 1000.0) + delay0)),
null); null);
@ -1028,7 +1031,7 @@ public class Deck
"FROM cards " + "FROM cards " +
"WHERE type = 0 and " + "WHERE type = 0 and " +
"isDue = 1 and " + "isDue = 1 and " +
String.format("combinedDue <= %f", String.format(NULL_LOCALE, "combinedDue <= %f",
(double) (System.currentTimeMillis() / 1000.0))); (double) (System.currentTimeMillis() / 1000.0)));
// Review // Review
@ -1036,14 +1039,14 @@ public class Deck
val.put("isDue", 1); val.put("isDue", 1);
revCount += AnkiDb.database.update("cards", val, "type = 1 and " + "isDue = 0 and " revCount += AnkiDb.database.update("cards", val, "type = 1 and " + "isDue = 0 and "
+ "priority in (1,2,3,4) and " + "priority in (1,2,3,4) and "
+ String.format("combinedDue <= %f", (double) (System.currentTimeMillis() / 1000.0)), null); + String.format(NULL_LOCALE, "combinedDue <= %f", (double) (System.currentTimeMillis() / 1000.0)), null);
// New // New
val.clear(); val.clear();
val.put("isDue", 1); val.put("isDue", 1);
newCount += AnkiDb.database.update("cards", val, "type = 2 and " + "isDue = 0 and " newCount += AnkiDb.database.update("cards", val, "type = 2 and " + "isDue = 0 and "
+ "priority in (1,2,3,4) and " + "priority in (1,2,3,4) and "
+ String.format("combinedDue <= %f", (double) (System.currentTimeMillis() / 1000.0)), null); + String.format(NULL_LOCALE, "combinedDue <= %f", (double) (System.currentTimeMillis() / 1000.0)), null);
newCountToday = Math.max(Math.min(newCount, newCardsPerDay - newCardsToday()), 0); newCountToday = Math.max(Math.min(newCount, newCardsPerDay - newCardsToday()), 0);
} }
@ -1151,7 +1154,7 @@ public class Deck
"UPDATE cards SET " + "UPDATE cards SET " +
"isDue = 0, " + "isDue = 0, " +
"priority = -3, " + "priority = -3, " +
"modified = " + String.format("%f", (double) (System.currentTimeMillis() / 1000.0)) + "modified = " + String.format(NULL_LOCALE, "%f", (double) (System.currentTimeMillis() / 1000.0)) +
" WHERE id IN " + ids2str(ids)); " WHERE id IN " + ids2str(ids));
rebuildCounts(false); rebuildCounts(false);
flushMod(); flushMod();
@ -1169,7 +1172,7 @@ public class Deck
AnkiDb.database.execSQL( AnkiDb.database.execSQL(
"UPDATE cards SET " + "UPDATE cards SET " +
"priority = 0, " + "priority = 0, " +
"modified = " + String.format("%f", (double) (System.currentTimeMillis() / 1000.0)) + "modified = " + String.format(NULL_LOCALE, "%f", (double) (System.currentTimeMillis() / 1000.0)) +
" WHERE id IN " + ids2str(ids)); " WHERE id IN " + ids2str(ids));
updatePriorities(ids); updatePriorities(ids);
rebuildCounts(false); rebuildCounts(false);
@ -1217,7 +1220,7 @@ public class Deck
String extra = ""; String extra = "";
if (dirty) if (dirty)
extra = ", modified = " + String.format("%f", (double) (System.currentTimeMillis() / 1000.0)); extra = ", modified = " + String.format(NULL_LOCALE, "%f", (double) (System.currentTimeMillis() / 1000.0));
for (int pri = 0; pri < 5; pri++) for (int pri = 0; pri < 5; pri++)
{ {
int count = 0; int count = 0;
@ -1344,9 +1347,9 @@ public class Deck
"AFTER INSERT ON %s BEGIN " + "AFTER INSERT ON %s BEGIN " +
"INSERT INTO undoLog VALUES " + "INSERT INTO undoLog VALUES " +
"(null, 'DELETE FROM %s WHERE rowid = ' || new.rowid); END"; "(null, 'DELETE FROM %s WHERE rowid = ' || new.rowid); END";
AnkiDb.database.execSQL(String.format(sql, table, table, table)); AnkiDb.database.execSQL(String.format(NULL_LOCALE, sql, table, table, table));
// Update trigger // Update trigger
sql = String.format("CREATE TEMP TRIGGER _undo_%s_ut " + sql = String.format(NULL_LOCALE, "CREATE TEMP TRIGGER _undo_%s_ut " +
"AFTER UPDATE ON %s BEGIN " + "AFTER UPDATE ON %s BEGIN " +
"INSERT INTO undoLog VALUES " + "INSERT INTO undoLog VALUES " +
"(null, 'UPDATE %s ", "(null, 'UPDATE %s ",
@ -1358,13 +1361,13 @@ public class Deck
String column = columnIter.next(); String column = columnIter.next();
if (column.equals("unique")) if (column.equals("unique"))
continue; continue;
sql += String.format("%s%s=' || quote(old.%s) || '", sep, column, column); sql += String.format(NULL_LOCALE, "%s%s=' || quote(old.%s) || '", sep, column, column);
sep = ","; sep = ",";
} }
sql += "WHERE rowid = ' || old.rowid); END"; sql += "WHERE rowid = ' || old.rowid); END";
AnkiDb.database.execSQL(sql); AnkiDb.database.execSQL(sql);
// Delete trigger // Delete trigger
sql = String.format("CREATE TEMP TRIGGER _undo_%s_dt " + sql = String.format(NULL_LOCALE, "CREATE TEMP TRIGGER _undo_%s_dt " +
"BEFORE DELETE ON %s BEGIN " + "BEFORE DELETE ON %s BEGIN " +
"INSERT INTO undoLog VALUES " + "INSERT INTO undoLog VALUES " +
"(null, 'INSERT INTO %s (rowid", "(null, 'INSERT INTO %s (rowid",
@ -1373,7 +1376,7 @@ public class Deck
while (columnIter.hasNext()) while (columnIter.hasNext())
{ {
String column = columnIter.next(); String column = columnIter.next();
sql += String.format(",\"%s\"", column); sql += String.format(NULL_LOCALE, ",\"%s\"", column);
} }
sql += ") VALUES (' || old.rowid ||'"; sql += ") VALUES (' || old.rowid ||'";
columnIter = columns.iterator(); columnIter = columns.iterator();
@ -1384,7 +1387,7 @@ public class Deck
sql += ",1"; sql += ",1";
continue; continue;
} }
sql += String.format(", ' || quote(old.%s) ||'", column); sql += String.format(NULL_LOCALE, ", ' || quote(old.%s) ||'", column);
} }
sql += ")'); END"; sql += ")'); END";
AnkiDb.database.execSQL(sql); AnkiDb.database.execSQL(sql);
@ -1456,7 +1459,7 @@ public class Deck
end = latestUndoRow(); end = latestUndoRow();
ArrayList<String> sql = AnkiDb.queryColumn( ArrayList<String> sql = AnkiDb.queryColumn(
String.class, String.class,
String.format("SELECT sql FROM undoLog " + String.format(NULL_LOCALE, "SELECT sql FROM undoLog " +
"WHERE seq > %d and seq <= %d " + "WHERE seq > %d and seq <= %d " +
"ORDER BY seq DESC", start, end), "ORDER BY seq DESC", start, end),
0); 0);

View File

@ -68,7 +68,7 @@ public class Whiteboard extends View
* TODO: This bitmap size is arbitrary (taken from fingerpaint). It * TODO: This bitmap size is arbitrary (taken from fingerpaint). It
* should be set to the size of the Whiteboard view. * should be set to the size of the Whiteboard view.
*/ */
createBitmap(320, 480, Bitmap.Config.ARGB_8888); createBitmap(854, 854, Bitmap.Config.ARGB_8888);
mPath = new Path(); mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG); mBitmapPaint = new Paint(Paint.DITHER_FLAG);
} }