Search in sources :

Example 16 with CourseV2

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

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

the class AddActivity method clickLocationItem.

private void clickLocationItem(final LinearLayout locationItem) {
    PopupWindowDialog dialog = new PopupWindowDialog();
    CourseV2 courseV2 = null;
    Object obj = locationItem.getTag();
    // has tag data
    if (obj != null && obj instanceof CourseV2) {
        courseV2 = (CourseV2) obj;
    } else {
        throw new RuntimeException("Course data tag not be found");
    }
    dialog.showSelectTimeDialog(this, courseV2, new PopupWindowDialog.SelectTimeCallback() {

        @Override
        public void onSelected(CourseV2 course) {
            StringBuilder builder = new StringBuilder();
            builder.append("周").append(Constant.WEEK_SINGLE[course.getCouWeek() - 1]).append(" 第").append(course.getCouStartNode()).append("-").append(course.getCouStartNode() + course.getCouNodeCount() - 1).append("节");
            if (!TextUtils.isEmpty(course.getCouLocation())) {
                builder.append("【").append(course.getCouLocation()).append("】");
            }
            ((TextView) locationItem.findViewById(R.id.tv_text)).setText(builder.toString());
        }
    });
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) PopupWindowDialog(com.mnnyang.gzuclassschedule.utils.spec.PopupWindowDialog)

Example 18 with CourseV2

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

the class HomePresenter method createShare.

/**
 * 建立分享
 */
@Override
public void createShare(final long groupId, final String groupName) {
    mView.showLoading("建立分享中");
    Observable.create(new ObservableOnSubscribe<ShareBean>() {

        @Override
        public void subscribe(final ObservableEmitter<ShareBean> emitter) throws Exception {
            List<CourseV2> list = Cache.instance().getCourseV2Dao().queryBuilder().where(CourseV2Dao.Properties.CouCgId.eq(groupId)).where(CourseV2Dao.Properties.CouDeleted.eq(false)).list();
            if (list != null && !list.isEmpty()) {
                String json = buildJsonOfGroups(list, groupName);
                MyHttpUtils utils = new MyHttpUtils();
                utils.uploadShare(json, new HttpCallback<ShareBean>() {

                    @Override
                    public void onSuccess(ShareBean bean) {
                        emitter.onNext(bean);
                    }

                    @Override
                    public void onFail(String errMsg) {
                        emitter.onError(new Exception(errMsg));
                    }
                });
            } else {
                emitter.onError(new Exception("该课表没有课程"));
            }
        }
    }).map(new Function<ShareBean, Bitmap>() {

        @Override
        public Bitmap apply(ShareBean bean) throws Exception {
            if (bean == null || TextUtils.isEmpty(bean.getData())) {
                return null;
            }
            Bitmap logo = BitmapFactory.decodeResource(Cache.instance().getContext().getResources(), R.mipmap.ic_launcher_round);
            final int width = ScreenUtils.dp2px(150);
            String content = Url.URL_SHARE + "?id=" + bean.getData();
            return new QRCode().makeQRCodeImage(content, width, width, logo);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Bitmap bitmap) {
            if (!mView.isActive()) {
                return;
            }
            mView.stopLoading();
            if (bitmap == null) {
                mView.showMassage("分享失败!");
                return;
            }
            mView.createQRCodeSucceed(bitmap);
        }

        @Override
        public void onError(Throwable e) {
            if (!mView.isActive()) {
                return;
            }
            mView.stopLoading();
            mView.showMassage(e.getMessage());
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : MyHttpUtils(com.mnnyang.gzuclassschedule.data.http.MyHttpUtils) Disposable(io.reactivex.disposables.Disposable) HttpCallback(com.mnnyang.gzuclassschedule.data.http.HttpCallback) JSONException(org.json.JSONException) Function(io.reactivex.functions.Function) ShareBean(com.mnnyang.gzuclassschedule.data.beanv2.ShareBean) Bitmap(android.graphics.Bitmap) QRCode(com.mnnyang.gzuclassschedule.utils.spec.QRCode) List(java.util.List)

Example 19 with CourseV2

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

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

CourseV2 (com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)19 CourseV2Dao (com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao)8 CourseGroup (com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)4 View (android.view.View)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 JSONException (org.json.JSONException)3 ImageView (android.widget.ImageView)2 DownCourseWrapper (com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)2 Disposable (io.reactivex.disposables.Disposable)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LinearLayout (android.widget.LinearLayout)1 CourseAncestor (com.mnnyang.gzuclassschedule.custom.course.CourseAncestor)1 CourseView (com.mnnyang.gzuclassschedule.custom.course.CourseView)1