Search in sources :

Example 6 with CourseV2

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

the class CourseActivity method initCourseViewEvent.

/**
 * courseVIew事件
 */
private void initCourseViewEvent() {
    mCourseViewV2.setOnItemClickListener(new CourseView.OnItemClickListener() {

        @Override
        public void onClick(List<CourseAncestor> course, View itemView) {
            mDialog = new ShowDetailDialog();
            mDialog.show(CourseActivity.this, (CourseV2) course.get(0), new PopupWindow.OnDismissListener() {

                @Override
                public void onDismiss() {
                    mDialog = null;
                }
            });
        }

        @Override
        public void onLongClick(List<CourseAncestor> courses, View itemView) {
            final CourseV2 course = (CourseV2) courses.get(0);
            DialogHelper dialogHelper = new DialogHelper();
            dialogHelper.showNormalDialog(CourseActivity.this, getString(R.string.confirm_to_delete), "课程 【" + course.getCouName() + "】" + Constant.WEEK[course.getCouWeek()] + "第" + course.getCouStartNode() + "节 ", new DialogListener() {

                @Override
                public void onPositive(DialogInterface dialog, int which) {
                    super.onPositive(dialog, which);
                    deleteCancelSnackBar(course);
                }
            });
        }

        public void onAdd(CourseAncestor course, View addView) {
            Intent intent = new Intent(CourseActivity.this, AddActivity.class);
            intent.putExtra(Constant.INTENT_ADD_COURSE_ANCESTOR, course);
            intent.putExtra(Constant.INTENT_ADD, true);
            startActivity(intent);
        }
    });
}
Also used : DialogHelper(com.mnnyang.gzuclassschedule.utils.DialogHelper) DialogInterface(android.content.DialogInterface) CourseView(com.mnnyang.gzuclassschedule.custom.course.CourseView) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) CourseView(com.mnnyang.gzuclassschedule.custom.course.CourseView) RecyclerView(android.support.v7.widget.RecyclerView) ShowDetailDialog(com.mnnyang.gzuclassschedule.utils.spec.ShowDetailDialog) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) AddActivity(com.mnnyang.gzuclassschedule.mvp.add.AddActivity) DialogListener(com.mnnyang.gzuclassschedule.utils.DialogListener) CourseAncestor(com.mnnyang.gzuclassschedule.custom.course.CourseAncestor)

Example 7 with CourseV2

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

the class ImptPresenter method parseCoursesHtmlToDb.

private void parseCoursesHtmlToDb(final String html, final String courseTimeTerm) {
    try {
        Observable.create(new ObservableOnSubscribe<String>() {

            @Override
            public void subscribe(ObservableEmitter<String> emitter) throws Exception {
                ArrayList<CourseV2> courseV2s = ParseCourse.parse(html);
                // 删除旧数据
                CourseGroup group = Cache.instance().getCourseGroupDao().queryBuilder().where(CourseGroupDao.Properties.CgName.eq(courseTimeTerm)).unique();
                CourseV2Dao courseV2Dao = Cache.instance().getCourseV2Dao();
                if (null != group) {
                    courseV2Dao.queryBuilder().where(CourseV2Dao.Properties.CouCgId.eq(group.getCgId())).buildDelete().executeDeleteWithoutDetachingEntities();
                } else {
                    // 不存在旧数据 创建新的课表组
                    group = new CourseGroup();
                    group.setCgName(courseTimeTerm);
                    Cache.instance().getCourseGroupDao().insert(group);
                }
                for (CourseV2 courseV2 : courseV2s) {
                    courseV2.setCouCgId(group.getCgId());
                    courseV2Dao.insert(courseV2);
                }
                emitter.onNext("导入成功");
                emitter.onComplete();
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(String s) {
                if (mImptView == null) {
                    // view被销毁
                    return;
                }
                LogUtil.i(this, "导入成功:" + courseTimeTerm);
                Long curGroupId = Cache.instance().getCourseGroupDao().queryBuilder().where(CourseGroupDao.Properties.CgName.eq(courseTimeTerm)).unique().getCgId();
                Preferences.putLong(app.mContext.getString(R.string.app_preference_current_cs_name_id), curGroupId);
                mImptView.hideImpting();
                mImptView.showSucceed();
            }

            @Override
            public void onError(Throwable e) {
                if (mImptView == null) {
                    // view被销毁
                    return;
                }
                e.printStackTrace();
                mImptView.hideImpting();
                mImptView.showErrToast("插入数据库失败", true);
            }

            @Override
            public void onComplete() {
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        mImptView.hideImpting();
        mImptView.showErrToast("导入错误", true);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 8 with CourseV2

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

the class AddActivity method submit.

private void submit() {
    // name
    String name = mEtlName.getText().trim();
    if (TextUtils.isEmpty(name)) {
        toast("课程名称不能为空!");
        return;
    }
    // teacher
    String teacher = mEtlTeacher.getText().trim();
    // group
    long couCgId = Preferences.getLong(getString(R.string.app_preference_current_cs_name_id), 0);
    int childCount = mLayoutLocationContainer.getChildCount();
    boolean hasLocation = false;
    for (int i = 0; i < childCount; i++) {
        View locationItem = mLayoutLocationContainer.getChildAt(i);
        Object obj = locationItem.getTag();
        if (obj != null) {
            hasLocation = true;
            CourseV2 courseV2 = (CourseV2) obj;
            courseV2.setCouName(name);
            courseV2.setCouTeacher(teacher);
            if (mAddMode || courseV2.getCouId() == null) {
                courseV2.setCouCgId(couCgId);
                courseV2.init();
                Cache.instance().getCourseV2Dao().insert(courseV2);
            } else {
                courseV2.init();
                Cache.instance().getCourseV2Dao().update(courseV2);
            }
        }
    }
    if (!hasLocation) {
        toast("没有设置课程时间!☆\\( ̄▽ ̄)/");
    }
    if (mAddMode) {
        toast("添加成功!☆\\( ̄▽ ̄)/");
    } else {
        toast("编辑成功!☆\\( ̄▽ ̄)/");
    }
    EventBus.getDefault().post(new CourseDataChangeEvent());
    finish();
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) CourseDataChangeEvent(com.mnnyang.gzuclassschedule.utils.event.CourseDataChangeEvent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 9 with CourseV2

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

the class HomePresenter method buildJsonOfGroups.

/**
 * 建立json
 */
private String buildJsonOfGroups(List<CourseV2> courseV2s, String groupName) {
    JSONObject result = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try {
        result.put("data", jsonArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    for (CourseV2 course : courseV2s) {
        try {
            JSONObject jsonItem = new JSONObject();
            jsonItem.put("id", course.getCouId());
            jsonItem.put("name", course.getCouName());
            jsonItem.put("location", course.getCouLocation() == null ? "" : course.getCouLocation());
            jsonItem.put("week", course.getCouWeek());
            jsonItem.put("teacher", course.getCouTeacher() == null ? "" : course.getCouTeacher());
            jsonItem.put("all_week", course.getCouAllWeek());
            jsonItem.put("start_node", course.getCouStartNode());
            jsonItem.put("node_count", course.getCouNodeCount());
            jsonItem.put("color", course.getCouColor() == null ? "-1" : course.getCouColor());
            jsonItem.put("group_name", groupName);
            jsonArray.put(jsonItem);
        } catch (JSONException e) {
            LogUtil.e(this, "buildJsonOfAllCourse() failed--->" + course.toString());
            e.printStackTrace();
        }
    }
    return result.toString();
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 10 with CourseV2

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

the class HomePresenter method buildJsonOfAllCourse.

/**
 * 对所有course建立json
 */
@NonNull
private JSONObject buildJsonOfAllCourse() {
    List<CourseGroup> groups = Cache.instance().getCourseGroupDao().queryBuilder().list();
    CourseV2Dao courseV2Dao = Cache.instance().getCourseV2Dao();
    JSONObject result = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try {
        result.put("data", jsonArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    for (CourseGroup group : groups) {
        List<CourseV2> courseV2s = courseV2Dao.queryBuilder().where(CourseV2Dao.Properties.CouCgId.eq(group.getCgId())).list();
        for (CourseV2 course : courseV2s) {
            try {
                JSONObject jsonItem = new JSONObject();
                jsonItem.put("id", course.getCouId());
                jsonItem.put("name", course.getCouName());
                jsonItem.put("location", course.getCouLocation() == null ? "" : course.getCouLocation());
                jsonItem.put("week", course.getCouWeek());
                jsonItem.put("teacher", course.getCouTeacher() == null ? "" : course.getCouTeacher());
                jsonItem.put("all_week", course.getCouAllWeek());
                jsonItem.put("start_node", course.getCouStartNode());
                jsonItem.put("node_count", course.getCouNodeCount());
                jsonItem.put("color", course.getCouColor() == null ? "-1" : course.getCouColor());
                jsonItem.put("group_name", group.getCgName());
                jsonItem.put("only_id", course.getCouOnlyId());
                jsonItem.put("deleted", course.getCouDeleted());
                jsonArray.put(jsonItem);
            } catch (JSONException e) {
                LogUtil.e(this, "buildJsonOfAllCourse() failed--->" + course.toString());
                e.printStackTrace();
            }
        }
    }
    return result;
}
Also used : CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) JSONObject(org.json.JSONObject) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) NonNull(android.support.annotation.NonNull)

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