Search in sources :

Example 1 with CourseGroupDao

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

the class MgPresenter method deleteCsName.

@Override
public void deleteCsName(final long csNameId) {
    CourseGroupDao groupDao = Cache.instance().getCourseGroupDao();
    groupDao.deleteByKey(csNameId);
    if (mView == null) {
        // 检查到view已经被销毁
        return;
    }
    mView.deleteFinish();
}
Also used : CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao)

Example 2 with CourseGroupDao

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

the class HomePresenter method getGroupId.

/**
 * 获取group_id
 */
private Long getGroupId(DownCourseWrapper.DownCourse downCourse) {
    if (downCourse == null) {
        return null;
    }
    CourseGroupDao groupDao = Cache.instance().getCourseGroupDao();
    String groupName = downCourse.getGroup_name();
    if (!TextUtils.isEmpty(groupName)) {
        Long groupId = mCacheGroup.get(groupName);
        if (null == groupId) {
            CourseGroup dbGroup = groupDao.queryBuilder().where(CourseGroupDao.Properties.CgName.eq(groupName)).unique();
            if (dbGroup == null) {
                CourseGroup newGroup = new CourseGroup().setCgName(groupName);
                groupId = groupDao.insert(newGroup);
            } else {
                groupId = dbGroup.getCgId();
            }
            mCacheGroup.put(groupName, groupId);
        }
        return groupId;
    } else {
        LogUtil.e(this, "下载的数据未找到group_name");
        return null;
    }
}
Also used : CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)

Example 3 with CourseGroupDao

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

the class CourseActivity method initFirstStart.

@Override
public void initFirstStart() {
    boolean isFirst = Preferences.getBoolean(getString(R.string.app_preference_app_is_first_start), true);
    if (!isFirst) {
        return;
    }
    Preferences.putBoolean(getString(R.string.app_preference_app_is_first_start), false);
    CourseGroupDao groupDao = Cache.instance().getCourseGroupDao();
    CourseGroup defaultGroup = groupDao.queryBuilder().where(CourseGroupDao.Properties.CgName.eq("默认课表")).unique();
    long insert;
    if (defaultGroup == null) {
        insert = groupDao.insert(new CourseGroup(0L, "默认", ""));
    } else {
        insert = defaultGroup.getCgId();
    }
    // migrate old data
    AppUtils.copyOldData(this);
    Preferences.putLong(getString(R.string.app_preference_current_cs_name_id), insert);
    showOnceSplash();
}
Also used : CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)

Example 4 with CourseGroupDao

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

the class MgPresenter method addCsName.

@Override
public void addCsName(String csName) {
    if (mView == null) {
        // 检查到view已经被销毁
        return;
    }
    if (TextUtils.isEmpty(csName)) {
        mView.showNotice(app.mContext.getString(R.string.course_name_can_not_be_empty));
    } else {
        // TODO 检查
        CourseGroupDao groupDao = Cache.instance().getCourseGroupDao();
        CourseGroup group = groupDao.queryBuilder().where(CourseGroupDao.Properties.CgName.eq(csName)).unique();
        if (group != null) {
            // notice conflict
            mView.showNotice(app.mContext.getString(R.string.course_name_is_conflicting));
        } else {
            // add cs_name
            groupDao.insert(new CourseGroup(null, csName, null));
            mView.addCsNameSucceed();
        }
    }
}
Also used : CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)

Example 5 with CourseGroupDao

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

the class MgPresenter method editCsName.

@Override
public void editCsName(long id, String newCsName) {
    CourseGroupDao groupDao = Cache.instance().getCourseGroupDao();
    if (mView == null) {
        // 检查到view已经被销毁
        return;
    }
    CourseGroup group = groupDao.queryBuilder().where(CourseGroupDao.Properties.CgName.eq(newCsName)).unique();
    if (group != null) {
        // notice conflict
        mView.showNotice(app.mContext.getString(R.string.course_name_is_conflicting));
        return;
    }
    Cache.instance().getCourseGroupDao().update(new CourseGroup(id, newCsName, null));
    mView.editCsNameSucceed();
}
Also used : CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)

Aggregations

CourseGroupDao (com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao)6 CourseGroup (com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)5 Course (com.mnnyang.gzuclassschedule.data.bean.Course)1 CsItem (com.mnnyang.gzuclassschedule.data.bean.CsItem)1 CourseV2 (com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)1 CourseV2Dao (com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao)1 DaoMaster (com.mnnyang.gzuclassschedule.data.greendao.DaoMaster)1 DaoSession (com.mnnyang.gzuclassschedule.data.greendao.DaoSession)1 MyOpenHelper (com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper)1