Search in sources :

Example 6 with CourseGroup

use of com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup in project GzuClassSchedule by mnnyang.

the class MgActivity method editDialog.

private void editDialog(final long id) {
    mCsNameDialogHelper = new DialogHelper();
    View view = LayoutInflater.from(this).inflate(R.layout.layout_input_course_table_name, null);
    final EditText editText = view.findViewById(R.id.et_course_table_name);
    // default value
    CourseGroup group = Cache.instance().getCourseGroupDao().queryBuilder().where(CourseGroupDao.Properties.CgId.eq(id)).unique();
    if (group != null) {
        editText.setHint(group.getCgName());
    }
    mCsNameDialogHelper.showCustomDialog(this, view, getString(R.string.please_input_course_table_name), new DialogListener() {

        @Override
        public void onNegative(DialogInterface dialog, int which) {
            super.onNegative(dialog, which);
            mCsNameDialogHelper = null;
        }

        @Override
        public void onPositive(DialogInterface dialog, int which) {
            super.onPositive(dialog, which);
            String courseTableName = editText.getText().toString().trim();
            if (TextUtils.isEmpty(courseTableName)) {
                toast(getString(R.string.course_name_can_not_be_empty));
                return;
            }
            mPresenter.editCsName(id, courseTableName);
        }
    });
}
Also used : EditText(android.widget.EditText) DialogHelper(com.mnnyang.gzuclassschedule.utils.DialogHelper) DialogInterface(android.content.DialogInterface) DialogListener(com.mnnyang.gzuclassschedule.utils.DialogListener) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 7 with CourseGroup

use of com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup 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 8 with CourseGroup

use of com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup 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)

Example 9 with CourseGroup

use of com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup 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

CourseGroup (com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)9 CourseGroupDao (com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao)5 CourseV2 (com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)4 CourseV2Dao (com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao)4 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 EditText (android.widget.EditText)1 Course (com.mnnyang.gzuclassschedule.data.bean.Course)1 CsItem (com.mnnyang.gzuclassschedule.data.bean.CsItem)1 DownCourseWrapper (com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)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 DialogHelper (com.mnnyang.gzuclassschedule.utils.DialogHelper)1 DialogListener (com.mnnyang.gzuclassschedule.utils.DialogListener)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Disposable (io.reactivex.disposables.Disposable)1