Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/classes.dex
Binary file not shown.
Binary file modified bin/classes/usbong/android/questionloader/MainActivity$1.class
Binary file not shown.
Binary file modified bin/classes/usbong/android/questionloader/MainActivity$2.class
Binary file not shown.
Binary file modified bin/classes/usbong/android/questionloader/MainActivity.class
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
18 changes: 10 additions & 8 deletions src/usbong/android/questionloader/ChineseDBAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@
public class ChineseDBAdapter {

public static final String KEY_ROWID = "_id";
public static final String KEY_WORD = "word";
public static final String KEY_DEF = "def";
public static final String KEY_WORD = "WORD";
public static final String KEY_DEF = "DEF";
public static final String KEY_READING = "READING";

private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;

private static final String DATABASE_NAME = "ChineseDict";
private static final String SQLITE_TABLE = "cdict";
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;

private final Context mCtx;

private static final String DATABASE_CREATE = "CREATE TABLE if not exists "
+ SQLITE_TABLE + " (" + KEY_ROWID
+ " integer PRIMARY KEY autoincrement," + KEY_WORD + ","
+ KEY_DEF + ");";
+ KEY_DEF + "," + KEY_READING + ");";


// UTILITY TABLE HELPER CLASS
Expand Down Expand Up @@ -95,13 +96,14 @@ public void close() {
// ACTIONS


public long createEntry(String word, String def) {
public long createEntry(String word, String def, String reading) {


// INSERT
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_WORD, word);
initialValues.put(KEY_DEF, def);
initialValues.put(KEY_READING, reading);

// parameters
// mDb.insert(table, nullColumnHack, values);
Expand All @@ -126,11 +128,11 @@ public Cursor fetchDefByWord(String inputText) throws SQLException {
if (inputText == null || inputText.length() == 0) {

mCursor = mDb.query(SQLITE_TABLE, new String[] { KEY_ROWID,
KEY_WORD, KEY_DEF }, null, null, null, null, null);
KEY_WORD, KEY_DEF, KEY_READING }, null, null, null, null, null);

} else {
mCursor = mDb.query(true, SQLITE_TABLE, new String[] { KEY_ROWID,
KEY_WORD, KEY_DEF }, KEY_WORD + " like '%" + inputText
KEY_WORD, KEY_DEF, KEY_READING }, KEY_WORD + " like '%" + inputText
+ "%'", null, null, null, null, null);
}
if (mCursor != null) {
Expand All @@ -146,7 +148,7 @@ public Cursor fetchAll() {
// mDb.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)

Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] { KEY_ROWID,
KEY_WORD, KEY_DEF }, null, null, null, null, null);
KEY_WORD, KEY_DEF, KEY_READING }, null, null, null, null, null);

if (mCursor != null) {
mCursor.moveToFirst();
Expand Down
21 changes: 16 additions & 5 deletions src/usbong/android/questionloader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,11 @@ private boolean dictContains(String word)
readUrlContentAsString = NetUtil.readUrlContentAsString(url);
ObjectMapper mapper = new ObjectMapper();
List<LinkedHashMap> map = mapper.readValue(readUrlContentAsString, List.class);
System.out.println("Korean here " + map.get(0).get("DEF").toString());
if (inQuestion(word, map.get(0).get("DEF").toString())) //save it to local
//System.out.println("Korean here " + map.get(0).get("DEF").toString());
String full = map.get(0).get("DEF").toString()+"\n"+map.get(0).get("READING").toString();
if (inQuestion(word, full)) //save it to local
{
dbHelper.createEntry( word, map.get(0).get("DEF").toString());
dbHelper.createEntry( word, map.get(0).get("DEF").toString(), map.get(0).get("READING").toString());
System.out.println("Entry created");
cursor.close();
return true;
Expand All @@ -713,8 +714,9 @@ private boolean dictContains(String word)
System.out.println("Cursor is not empty");
if (cursor.moveToFirst()) {
do {
String dir = cursor.getString(cursor.getColumnIndex("def"));
if (inQuestion(word, dir))
String full = cursor.getString(cursor.getColumnIndex("DEF")) + "\n" + cursor.getString(cursor.getColumnIndex("READING"));
//String dir = cursor.getString(cursor.getColumnIndex("def"));
if (inQuestion(word, full))
{
cursor.close();
return true;
Expand Down Expand Up @@ -918,8 +920,10 @@ else if (language.equalsIgnoreCase("korean"))
Intent i = new Intent(getApplicationContext(), ResultPage.class);
i.putExtra("score", totalScore);
i.putExtra("language", language);
dbHelper.close();
startActivity(i);
MainActivity.this.finish();

//Switch to scoreboard
}

Expand Down Expand Up @@ -1115,6 +1119,13 @@ public String makeBold(ArrayList<Integer> index, String s)
return sb.toString();

}

@Override
public void finish()
{
dbHelper.close();
super.finish();
}
public static String postFormDataToUrl(String url, String data) throws Exception
{
InputStream is = null;
Expand Down