Search in sources :

Example 6 with Word

use of pri.weiqiang.liyujapanese.mvp.bean.dic.Word in project LiYuJapanese by 54wall.

the class DBManager method queryWord.

public synchronized List<Word> queryWord(String lesson) {
    Log.e(TAG, "queryWord lesson:" + lesson);
    SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
    String selection = "lesson_id=?";
    String[] selectionArgs = new String[] { lesson };
    Cursor cursor = db.query(DatabaseHelper.DB_TABLE_WORDS, null, selection, selectionArgs, null, null, null);
    mWordList = new ArrayList<>();
    Word item;
    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex("_id"));
        String book_id = cursor.getString(cursor.getColumnIndex("book_id"));
        String lesson_id = cursor.getString(cursor.getColumnIndex("lesson_id"));
        String word = cursor.getString(cursor.getColumnIndex("word"));
        String phonetic = cursor.getString(cursor.getColumnIndex("phonetic"));
        String translation = cursor.getString(cursor.getColumnIndex("translation"));
        int fav = cursor.getInt(cursor.getColumnIndex("fav"));
        int cache = cursor.getInt(cursor.getColumnIndex("cache"));
        item = new Word(id, book_id, lesson_id, word, phonetic, translation, fav, cache);
        // Log.e(TAG, "word:" + item.toString());
        mWordList.add(item);
    }
    cursor.close();
    db.close();
    return mWordList;
}
Also used : Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 7 with Word

use of pri.weiqiang.liyujapanese.mvp.bean.dic.Word in project LiYuJapanese by 54wall.

the class WordsFragment method setData.

@Override
public void setData(List<Word> data) {
    adapter = new WordsRecyclerAdapter(getContext(), data, isExpandable);
    mRecyclerView.setAdapter(adapter);
    LayoutAnimationHelper.getInstance().playLayoutAnimation(mRecyclerView, LayoutAnimationHelper.getInstance().getAnimationSetFromBottom(), LayoutAnimationController.ORDER_NORMAL);
    adapter.setOnItemClickListener(new WordsRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(Word bean) {
        }
    });
}
Also used : Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) WordsRecyclerAdapter(pri.weiqiang.liyujapanese.ui.adapter.WordsRecyclerAdapter)

Example 8 with Word

use of pri.weiqiang.liyujapanese.mvp.bean.dic.Word in project MyJapanese by 54wall.

the class DBManager method queryWord.

public synchronized List<Word> queryWord(String lesson) {
    Log.e(TAG, "queryWord lesson:" + lesson);
    SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
    String selection = "lesson_id=?";
    String[] selectionArgs = new String[] { lesson };
    Cursor cursor = db.query(DatabaseHelper.DB_TABLE_WORDS, null, selection, selectionArgs, null, null, null);
    mWordList = new ArrayList<>();
    Word item;
    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex("_id"));
        String book_id = cursor.getString(cursor.getColumnIndex("book_id"));
        String lesson_id = cursor.getString(cursor.getColumnIndex("lesson_id"));
        String word = cursor.getString(cursor.getColumnIndex("word"));
        String phonetic = cursor.getString(cursor.getColumnIndex("phonetic"));
        String translation = cursor.getString(cursor.getColumnIndex("translation"));
        int fav = cursor.getInt(cursor.getColumnIndex("fav"));
        int cache = cursor.getInt(cursor.getColumnIndex("cache"));
        item = new Word(id, book_id, lesson_id, word, phonetic, translation, fav, cache);
        // Log.e(TAG, "word:" + item.toString());
        mWordList.add(item);
    }
    cursor.close();
    db.close();
    return mWordList;
}
Also used : Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 9 with Word

use of pri.weiqiang.liyujapanese.mvp.bean.dic.Word in project MyJapanese by 54wall.

the class FavWordsFragmentModelImpl method getData.

@Override
public void getData(Consumer<List<Word>> consumer, Consumer<Throwable> throwable, final String lessonId) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Word>>() {

        @Override
        public void subscribe(ObservableEmitter<List<Word>> emitter) throws Exception {
            List<Word> list;
            list = DBManager.getInstance().getFav(lessonId);
            if (list == null) {
                Log.e(TAG, "list == null");
            // emitter.onError(new Exception());//经常报这个错误io.reactivex.exceptions.OnErrorNotImplementedException
            } else {
                emitter.onNext(list);
            }
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer, throwable);
    mCompositeDisposable.add(disposable);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 10 with Word

use of pri.weiqiang.liyujapanese.mvp.bean.dic.Word in project MyJapanese by 54wall.

the class FavWordsFragment method setData.

@Override
public void setData(List<Word> data) {
    adapter = new FavWordsRecyclerAdapter(getContext(), data, isExpandable);
    mRecyclerView.setAdapter(adapter);
    LayoutAnimationHelper.getInstance().playLayoutAnimation(mRecyclerView, LayoutAnimationHelper.getInstance().getAnimationSetFromBottom(), LayoutAnimationController.ORDER_NORMAL);
    adapter.setOnItemClickListener(new FavWordsRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(Word bean) {
        }
    });
}
Also used : Word(pri.weiqiang.liyujapanese.mvp.bean.dic.Word) FavWordsRecyclerAdapter(pri.weiqiang.liyujapanese.ui.adapter.FavWordsRecyclerAdapter)

Aggregations

Word (pri.weiqiang.liyujapanese.mvp.bean.dic.Word)14 Cursor (android.database.Cursor)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 ObservableEmitter (io.reactivex.ObservableEmitter)4 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)4 Disposable (io.reactivex.disposables.Disposable)4 FavWordsRecyclerAdapter (pri.weiqiang.liyujapanese.ui.adapter.FavWordsRecyclerAdapter)2 WordsRecyclerAdapter (pri.weiqiang.liyujapanese.ui.adapter.WordsRecyclerAdapter)2