Search in sources :

Example 6 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class AddWordAsyncTask method doInBackground.

@SuppressLint("SimpleDateFormat")
@Override
protected Boolean doInBackground(Void... params) {
    if (mAdding == true) {
        return false;
    }
    mDictionaryDB = new DictionaryDB(mContext, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = mDictionaryDB.getWritableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery(// 检查是否已经在生词表中存在
    "select * from word where word='" + mToAddWord + "' limit 1", null);
    Boolean returnResult = false;
    if (cursor.getCount() == 0) {
        // 检查是否在word中存在
        if (QueryProcessor.instance(mContext).getWordID(mToAddWord) == QueryProcessor.MSG_WORD_NOT_EXISIT) {
            returnResult = false;
            mErrorCode = ERROR_NOT_EXSIST;
        } else {
            ContentValues contentValues = new ContentValues();
            contentValues.put("word", mToAddWord);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String addTime = simpleDateFormat.format(new Date());
            contentValues.put("addtime", addTime);
            sqLiteDatabase.insert("word", null, contentValues);
            returnResult = true;
        }
    } else {
        returnResult = false;
        mErrorCode = ERROR_ALREADY_ADDED;
    }
    sqLiteDatabase.close();
    mAddingList.remove(mToAddWord);
    return returnResult;
}
Also used : ContentValues(android.content.ContentValues) DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Example 7 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class OfflineListCursorAdapter method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    String id = buttonView.getContentDescription().toString();
    String status = isChecked == true ? "1" : "0";
    DictionaryDB dictionaryDB = new DictionaryDB(mContext, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getWritableDatabase();
    String[] argsStrings = { status, id };
    sqLiteDatabase.execSQL("update `dictionary_list` set `dictionary_show`=? where `_id`=?", argsStrings);
    sqLiteDatabase.close();
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)7 DictionaryDB (com.zhan_dui.dictionary.db.DictionaryDB)7 Cursor (android.database.Cursor)6 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 SpannableString (android.text.SpannableString)1 StickyListHeadersListView (com.emilsjolander.components.stickylistheaders.StickyListHeadersListView)1 DragSortListView (com.mobeta.android.dslv.DragSortListView)1 OfflineListCursorAdapter (com.zhan_dui.dictionary.cursoradapters.OfflineListCursorAdapter)1 SimpleWordAdapter (com.zhan_dui.dictionary.cursoradapters.SimpleWordAdapter)1 WordAdapter (com.zhan_dui.dictionary.cursoradapters.WordAdapter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1