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();
}
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());
}
});
}
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() {
}
});
}
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);
}
}
}
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);
}
}
}
Aggregations