Search in sources :

Example 6 with CourseV2Dao

use of com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao in project GzuClassSchedule by mnnyang.

the class CoursePresenter method deleteCourse.

@Override
public void deleteCourse(long courseId) {
    // Cache.instance().getCourseV2Dao().deleteByKey(courseId);
    CourseV2Dao courseV2Dao = Cache.instance().getCourseV2Dao();
    CourseV2 courseV2 = courseV2Dao.queryBuilder().where(CourseV2Dao.Properties.CouId.eq(courseId)).unique();
    if (courseV2 != null) {
        courseV2.setCouDeleted(true);
        courseV2Dao.update(courseV2);
    }
    // must be main thread
    mView.updateCoursePreference();
}
Also used : CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)

Example 7 with CourseV2Dao

use of com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao in project GzuClassSchedule by mnnyang.

the class HomePresenter method overWriteLocal.

/**
 * 覆盖本地
 */
private void overWriteLocal(List<DownCourseWrapper.DownCourse> downCourses) {
    mCacheGroup = new HashMap<>();
    CourseV2Dao courseDao = Cache.instance().getCourseV2Dao();
    for (DownCourseWrapper.DownCourse downCourse : downCourses) {
        Long groupId = getGroupId(downCourse);
        if (groupId != null) {
            CourseV2 oldCourse = courseDao.queryBuilder().where(CourseV2Dao.Properties.CouOnlyId.eq(downCourse.getOnly_id())).unique();
            if (oldCourse != null) {
                // 删除手机上的数据 (覆盖)
                courseDao.delete(oldCourse);
            }
            addCourse(downCourse, groupId);
        }
    }
}
Also used : CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) DownCourseWrapper(com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)

Example 8 with CourseV2Dao

use of com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao in project GzuClassSchedule by mnnyang.

the class CourseGroup method getCgItems.

/**
 * To-many relationship, resolved on first access (and after reset).
 * Changes to to-many relations are not persisted, make changes to the target entity.
 */
@Generated(hash = 136005675)
public List<CourseV2> getCgItems() {
    if (cgItems == null) {
        final DaoSession daoSession = this.daoSession;
        if (daoSession == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        CourseV2Dao targetDao = daoSession.getCourseV2Dao();
        List<CourseV2> cgItemsNew = targetDao._queryCourseGroup_CgItems(cgId);
        synchronized (this) {
            if (cgItems == null) {
                cgItems = cgItemsNew;
            }
        }
    }
    return cgItems;
}
Also used : CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) DaoException(org.greenrobot.greendao.DaoException) DaoSession(com.mnnyang.gzuclassschedule.data.greendao.DaoSession) Generated(org.greenrobot.greendao.annotation.Generated)

Example 9 with CourseV2Dao

use of com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao in project GzuClassSchedule by mnnyang.

the class AppUtils method migrateData.

/**
 * 迁移旧数据
 */
private static void migrateData(Context context) {
    MyOpenHelper myOpenHelper = new MyOpenHelper(context, "coursev2.db", null);
    DaoMaster daoMaster = new DaoMaster(myOpenHelper.getWritableDatabase());
    DaoSession daoSession = daoMaster.newSession();
    CourseGroupDao courseGroupDao = daoSession.getCourseGroupDao();
    CourseV2Dao courseV2Dao = daoSession.getCourseV2Dao();
    ArrayList<CsItem> csItems = CourseDbDao.instance().loadCsNameList();
    for (CsItem csItem : csItems) {
        ArrayList<Course> courses = CourseDbDao.instance().loadCourses(csItem.getCsName().getCsNameId());
        CourseGroup group = new CourseGroup();
        group.setCgName(csItem.getCsName().getName());
        long insert1 = courseGroupDao.insert(group);
        for (Course course : courses) {
            if (course.getNodes() == null || course.getNodes().size() == 0 || course.getEndWeek() == 0) {
                continue;
            }
            CourseV2 courseV2 = new CourseV2().setCouOnlyId(AppUtils.createUUID());
            courseV2.setCouName(course.getName());
            courseV2.setCouTeacher(course.getTeacher());
            courseV2.setCouLocation(course.getClassRoom());
            // node
            courseV2.setCouStartNode(course.getNodes().get(0));
            courseV2.setCouNodeCount(course.getNodes().size());
            // day
            courseV2.setCouWeek(course.getWeek());
            // week
            String couAllWeek = getAllWeek(course);
            if (couAllWeek.length() > 0) {
                couAllWeek = couAllWeek.substring(0, couAllWeek.length() - 1);
            }
            courseV2.setCouAllWeek(couAllWeek);
            courseV2.setCouCgId(insert1);
            courseV2Dao.insert(courseV2);
        }
    }
}
Also used : MyOpenHelper(com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper) CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup) CsItem(com.mnnyang.gzuclassschedule.data.bean.CsItem) DaoMaster(com.mnnyang.gzuclassschedule.data.greendao.DaoMaster) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) Course(com.mnnyang.gzuclassschedule.data.bean.Course) DaoSession(com.mnnyang.gzuclassschedule.data.greendao.DaoSession)

Aggregations

CourseV2Dao (com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao)9 CourseV2 (com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)8 CourseGroup (com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)4 DownCourseWrapper (com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)2 DaoSession (com.mnnyang.gzuclassschedule.data.greendao.DaoSession)2 NonNull (android.support.annotation.NonNull)1 Course (com.mnnyang.gzuclassschedule.data.bean.Course)1 CsItem (com.mnnyang.gzuclassschedule.data.bean.CsItem)1 CourseGroupDao (com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao)1 DaoMaster (com.mnnyang.gzuclassschedule.data.greendao.DaoMaster)1 MyOpenHelper (com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Disposable (io.reactivex.disposables.Disposable)1 DaoException (org.greenrobot.greendao.DaoException)1 Generated (org.greenrobot.greendao.annotation.Generated)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1