Search in sources :

Example 1 with GojuonMemory

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory in project MyJapanese by 54wall.

the class DBManager method getGojuonMemory.

public synchronized List<GojuonMemory> getGojuonMemory() {
    if (gojuonMemoryList == null) {
        SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
        // Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.DB_TABLE_GOJUON, null);
        Cursor cursor = db.query(DatabaseHelper.DB_TABLE_GOJUON, null, null, null, null, null, null);
        gojuonMemoryList = new ArrayList<>();
        GojuonMemory item;
        while (cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndex("id"));
            String memory = cursor.getString(cursor.getColumnIndex("memory"));
            if (memory != null) {
                String hiragana = cursor.getString(cursor.getColumnIndex("hiragana"));
                String katakana = cursor.getString(cursor.getColumnIndex("katakana"));
                String rome = cursor.getString(cursor.getColumnIndex("rome"));
                String chengyu = cursor.getString(cursor.getColumnIndex("chengyu"));
                item = new GojuonMemory(id, hiragana, katakana, rome, memory, chengyu);
                gojuonMemoryList.add(item);
            }
        }
        cursor.close();
        db.close();
    }
    return gojuonMemoryList;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) Cursor(android.database.Cursor)

Example 2 with GojuonMemory

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory in project MyJapanese by 54wall.

the class GojuonMemoryFragmentModelImpl method getData.

@Override
public void getData(final int category, Consumer<List<GojuonMemory>> consumer) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<GojuonMemory>>() {

        @Override
        public void subscribe(ObservableEmitter<List<GojuonMemory>> emitter) throws Exception {
            List<GojuonMemory> list;
            switch(category) {
                case Constants.GOJUON_MEMORY:
                    list = DBManager.getInstance().getGojuonMemory();
                    break;
                case Constants.GOJUON_CHENGYU:
                    list = DBManager.getInstance().getGojuonChengyu();
                    break;
                default:
                    list = null;
                    break;
            }
            if (list == null) {
                emitter.onError(new Exception());
            } else {
                emitter.onNext(list);
            }
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
    mCompositeDisposable.add(disposable);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 3 with GojuonMemory

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory in project LiYuJapanese by 54wall.

the class GojuonMemoryFragmentModelImpl method getData.

@Override
public void getData(final int category, Consumer<List<GojuonMemory>> consumer) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<GojuonMemory>>() {

        @Override
        public void subscribe(ObservableEmitter<List<GojuonMemory>> emitter) throws Exception {
            List<GojuonMemory> list;
            switch(category) {
                case Constants.GOJUON_MEMORY:
                    list = DBManager.getInstance().getGojuonMemory();
                    break;
                case Constants.GOJUON_CHENGYU:
                    list = DBManager.getInstance().getGojuonChengyu();
                    break;
                default:
                    list = null;
                    break;
            }
            if (list == null) {
                emitter.onError(new Exception());
            } else {
                emitter.onNext(list);
            }
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
    mCompositeDisposable.add(disposable);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 4 with GojuonMemory

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory in project LiYuJapanese by 54wall.

the class DBManager method getGojuonChengyu.

public synchronized List<GojuonMemory> getGojuonChengyu() {
    if (gojuonMemoryChengyu == null) {
        SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
        // Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.DB_TABLE_GOJUON, null);
        Cursor cursor = db.query(DatabaseHelper.DB_TABLE_GOJUON, null, null, null, null, null, null);
        gojuonMemoryChengyu = new ArrayList<>();
        GojuonMemory item;
        while (cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndex("id"));
            String chengyu = cursor.getString(cursor.getColumnIndex("chengyu"));
            if (chengyu != null) {
                String hiragana = cursor.getString(cursor.getColumnIndex("hiragana"));
                String katakana = cursor.getString(cursor.getColumnIndex("katakana"));
                String rome = cursor.getString(cursor.getColumnIndex("rome"));
                String memory = cursor.getString(cursor.getColumnIndex("memory"));
                item = new GojuonMemory(id, hiragana, katakana, rome, memory, chengyu);
                gojuonMemoryChengyu.add(item);
            }
        }
        cursor.close();
        db.close();
    }
    return gojuonMemoryChengyu;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) Cursor(android.database.Cursor)

Example 5 with GojuonMemory

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory in project LiYuJapanese by 54wall.

the class DBManager method getGojuonMemory.

public synchronized List<GojuonMemory> getGojuonMemory() {
    if (gojuonMemoryList == null) {
        SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
        // Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.DB_TABLE_GOJUON, null);
        Cursor cursor = db.query(DatabaseHelper.DB_TABLE_GOJUON, null, null, null, null, null, null);
        gojuonMemoryList = new ArrayList<>();
        GojuonMemory item;
        while (cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndex("id"));
            String memory = cursor.getString(cursor.getColumnIndex("memory"));
            if (memory != null) {
                String hiragana = cursor.getString(cursor.getColumnIndex("hiragana"));
                String katakana = cursor.getString(cursor.getColumnIndex("katakana"));
                String rome = cursor.getString(cursor.getColumnIndex("rome"));
                String chengyu = cursor.getString(cursor.getColumnIndex("chengyu"));
                item = new GojuonMemory(id, hiragana, katakana, rome, memory, chengyu);
                gojuonMemoryList.add(item);
            }
        }
        cursor.close();
        db.close();
    }
    return gojuonMemoryList;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GojuonMemory(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory) Cursor(android.database.Cursor)

Aggregations

GojuonMemory (pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonMemory)8 Cursor (android.database.Cursor)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 ObservableEmitter (io.reactivex.ObservableEmitter)2 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)2 Disposable (io.reactivex.disposables.Disposable)2 ImageDialog (pri.weiqaing.common.widget.dialog.ImageDialog)2 GojuonGif (pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonGif)2 GojuonMemoryRecyclerAdapter (pri.weiqiang.liyujapanese.ui.adapter.GojuonMemoryRecyclerAdapter)2