Search in sources :

Example 6 with Lesson

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

the class DBManager method getBooks.

public synchronized List<Book> getBooks() {
    // 仅第一次调用数据库时填充mBookList
    if (mBookList == null) {
        Log.e(TAG, "mBookList = null");
        SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
        // Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.DB_TABLE_LESSONS, null);
        Cursor cursor = db.query(DatabaseHelper.DB_TABLE_LESSONS, null, null, null, null, null, null);
        mBookList = new ArrayList<>();
        mLessonList = new ArrayList<>();
        Book bookItem;
        Lesson lessonItem;
        String curbook = "大家的日本语第一册";
        int i = 0;
        while (cursor.moveToNext()) /*&& i < 50*/
        {
            i++;
            int id = cursor.getInt(cursor.getColumnIndex("_id"));
            String book = cursor.getString(cursor.getColumnIndex("book"));
            String title = cursor.getString(cursor.getColumnIndex("title"));
            int count = cursor.getInt(cursor.getColumnIndex("count"));
            if (book.equals(curbook)) {
                lessonItem = new Lesson(id, book, title, count);
                mLessonList.add(lessonItem);
            } else {
                bookItem = new Book(curbook, mLessonList);
                mBookList.add(bookItem);
                mLessonList = new ArrayList<>();
                lessonItem = new Lesson(id, book, title, count);
                mLessonList.add(lessonItem);
                curbook = book;
            }
        }
        if (curbook.equals("新编日语IV")) {
            bookItem = new Book(curbook, mLessonList);
            mBookList.add(bookItem);
        }
        cursor.close();
        db.close();
    }
    return mBookList;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Book(pri.weiqiang.liyujapanese.mvp.bean.dic.Book) Cursor(android.database.Cursor) Lesson(pri.weiqiang.liyujapanese.mvp.bean.dic.Lesson)

Aggregations

Lesson (pri.weiqiang.liyujapanese.mvp.bean.dic.Lesson)6 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 View (android.view.View)2 TextView (android.widget.TextView)2 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 Book (pri.weiqiang.liyujapanese.mvp.bean.dic.Book)2 LeftMenuAdapter (pri.weiqiang.liyujapanese.ui.adapter.LeftMenuAdapter)2 RightMenuAdapter (pri.weiqiang.liyujapanese.ui.adapter.RightMenuAdapter)2