Search in sources :

Example 1 with CourseV2

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

the class ParseCourse method main.

public static void main(String[] args) {
    // String s = readToString("/home/xxyangyoulin/Android/project/ClassSchedule/app/src/main/java/com/mnnyang/gzuclassschedule/impt/demo.html");
    String s = "<table id=\"Table1\" class=\"blacktab\" bordercolor=\"Black\" border=\"0\" width=\"100%\">\n" + "    <tbody>\n" + "    <tr>\n" + "        <td colspan=\"2\" rowspan=\"1\" width=\"2%\">时间</td>\n" + "        <td align=\"Center\" width=\"14%\">星期一</td>\n" + "        <td align=\"Center\" width=\"14%\">星期二</td>\n" + "        <td align=\"Center\" width=\"14%\">星期三</td>\n" + "        <td align=\"Center\" width=\"14%\">星期四</td>\n" + "        <td align=\"Center\" width=\"14%\">星期五</td>\n" + "        <td class=\"noprint\" align=\"Center\" width=\"14%\">星期六</td>\n" + "        <td class=\"noprint\" align=\"Center\" width=\"14%\">星期日</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td colspan=\"2\">早晨</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td rowspan=\"5\" width=\"1%\">上午</td>\n" + "        <td width=\"1%\">第1节</td>\n" + "        <td align=\"Center\" rowspan=\"2\" width=\"7%\">船舶货运专题A<br>任选<br>周一第1,2节{第6-8周}<br>王庸凯<br>獐210<br><br>船舶货运专题A<br>任选<br>周一第1,2节{第2-4周}<br>王庸凯<br>獐210\n" + "        </td>\n" + "        <td align=\"Center\" width=\"7%\">&nbsp;</td>\n" + "        <td align=\"Center\" width=\"7%\">&nbsp;</td>\n" + "        <td align=\"Center\" width=\"7%\">&nbsp;</td>\n" + "        <td align=\"Center\" rowspan=\"2\" width=\"7%\">远洋运输业务与海商法<br>必修<br>周五第1,2节{第6-17周}<br>姚智慧<br>獐332<br><br>远洋运输业务与海商法<br>必修<br>周五第1,2节{第1-4周}<br>姚智慧<br>獐332\n" + "        </td>\n" + "        <td class=\"noprint\" align=\"Center\" width=\"7%\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\" width=\"7%\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第2节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第3节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\" rowspan=\"2\">远洋运输业务与海商法<br>必修<br>周三第3,4节{第6-17周}<br>姚智慧<br>獐131<br><br>远洋运输业务与海商法<br>必修<br>周三第3,4节{第1-4周}<br>姚智慧<br>獐131\n" + "        </td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第4节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第5节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td rowspan=\"5\">下午</td>\n" + "        <td>第6节</td>\n" + "        <td align=\"Center\" rowspan=\"2\">航海气象与海洋学专题<br>任选<br>周一第6,7节{第7-18周}<br>张飞成<br>獐422</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\" rowspan=\"2\">船舶货运专题A<br>任选<br>周五第6,7节{第2-4周}<br>王庸凯<br>獐410<br><br>船舶货运专题A<br>任选<br>周五第6,7节{第6-8周}<br>王庸凯<br>獐410\n" + "        </td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第7节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第8节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\" rowspan=\"2\">大学生职业发展与就业指导<br>课外<br>周二第8,9节{第12-12周|双周}<br>王超鹏<br>獐103</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第9节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第10节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td rowspan=\"4\" width=\"1%\">晚上</td>\n" + "        <td>第11节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第12节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第13节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    <tr>\n" + "        <td>第14节</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "        <td class=\"noprint\" align=\"Center\">&nbsp;</td>\n" + "    </tr>\n" + "    </tbody>\n" + "</table>";
    ArrayList<CourseV2> courses = ParseCourse.parse(s);
    courses = mergeSameClass(courses);
    for (CourseV2 course : courses) {
        System.out.println("TEST  " + course.getCouName() + "--" + course.getCouColor());
    }
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)

Example 2 with CourseV2

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

the class ParseCourse method mergeSameClass.

/**
 * 合并同一门课
 */
private static ArrayList<CourseV2> mergeSameClass(ArrayList<CourseV2> courses) throws NumberFormatException {
    ArrayList<CourseV2> result = new ArrayList<>();
    int i = 0;
    for (CourseV2 cours : courses) {
        boolean find = false;
        for (CourseV2 courseV2 : result) {
            // 同一门课
            if (cours.isSameClass(courseV2)) {
                find = true;
                String oneAllWeek = courseV2.getCouAllWeek();
                String twoAllWeek = cours.getCouAllWeek();
                if (oneAllWeek.length() > 0 && twoAllWeek.length() > 0) {
                    if (Integer.decode(oneAllWeek.substring(0, 1)) < Integer.decode(twoAllWeek.substring(0, 1))) {
                        courseV2.setCouAllWeek(oneAllWeek + "," + twoAllWeek);
                    } else {
                        courseV2.setCouAllWeek(twoAllWeek + "," + oneAllWeek);
                    }
                } else if (twoAllWeek.length() > 0) {
                    courseV2.setCouAllWeek(twoAllWeek);
                }
            }
        }
        if (!find) {
            result.add(cours);
        }
    }
    for (int i1 = 0; i1 < result.size(); i1++) {
        CourseV2 left = result.get(i1);
        if (left.getCouColor() == null) {
            int color = Utils.getRandomColor();
            left.setCouColor(color);
            for (CourseV2 courseV2 : result) {
                if (courseV2.isSameClassWithoutLocation(left)) {
                    courseV2.setCouColor(color);
                }
            }
        }
    }
    return result;
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) ArrayList(java.util.ArrayList)

Example 3 with CourseV2

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

the class ParseCourse method parse.

/**
 * @param html
 * @return 解析失败返回空
 */
public static ArrayList<CourseV2> parse(String html) {
    Document doc = org.jsoup.Jsoup.parse(html);
    Element table1 = doc.getElementById("Table1");
    Elements trs = table1.getElementsByTag("tr");
    ArrayList<CourseV2> courses = new ArrayList<>();
    int node = 0;
    for (Element tr : trs) {
        Elements tds = tr.getElementsByTag("td");
        for (Element td : tds) {
            String courseSource = td.text().trim();
            if (courseSource.length() <= 6) {
                // null data
                continue;
            }
            if (Pattern.matches(pattern, courseSource)) {
                // node number
                try {
                    node = Integer.decode(courseSource.substring(1, courseSource.length() - 1));
                } catch (Exception e) {
                    node = 0;
                    e.printStackTrace();
                }
                continue;
            }
            if (inArray(other, courseSource)) {
                // other data
                continue;
            }
            courses.addAll(ParseCourse.parseTextInfo(courseSource, node));
        }
    }
    return mergeSameClass(courses);
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with CourseV2

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

the class ParseCourse method parseTextInfo.

private static ArrayList<CourseV2> parseTextInfo(String source, int node) {
    System.out.println("---->" + source + "");
    ArrayList<CourseV2> courses = new ArrayList<>();
    String[] split = source.split(" ");
    if (split.length / 4 > 0 && split.length % 4 == 0) {
        for (int i = 0; i < split.length / 4; i++) {
            CourseV2 course = new CourseV2().setCouOnlyId(AppUtils.createUUID());
            courses.add(course);
            // course.setSource(source);
            // course.setName(split[i * 4]);
            course.setCouName(split[i * 4]);
            String time = split[1 + i * 4];
            parseTime(course, time, node);
            // course.setTeacher(split[2 + i * 4]);
            // course.setClassRoom(split[3 + i * 4]);
            course.setCouTeacher(split[2 + i * 4]);
            course.setCouLocation(split[3 + i * 4]);
        }
    } else if (split.length / 5 > 0 && split.length % 5 == 0) {
        for (int i = 0; i < split.length / 5; i++) {
            CourseV2 course = new CourseV2().setCouOnlyId(AppUtils.createUUID());
            courses.add(course);
            course.setCouName(split[i * 5]);
            String time = split[2 + i * 5];
            parseTime(course, time, node);
            course.setCouTeacher(split[3 + i * 5]);
            course.setCouLocation(split[4 + i * 5]);
        }
    } else if (split.length > 2) {
        CourseV2 course = new CourseV2().setCouOnlyId(AppUtils.createUUID());
        courses.add(course);
        // course.setSource(source);
        // course.setName(split[0]);
        course.setCouName(split[0]);
        String time = split[1];
        parseTime(course, time, node);
        course.setCouTeacher(split[2]);
        if (split.length > 3) {
            course.setCouLocation(split[3]);
        }
    } else {
        // TODO other type
        LogUtil.e("ParseCourse", "解析爆炸:" + source);
    }
    return courses;
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) ArrayList(java.util.ArrayList)

Example 5 with CourseV2

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

the class UpdateService method initData.

private void initData() {
    // TODO
    long group_id = Preferences.getLong(getString(R.string.app_preference_current_cs_name_id), 0);
    mCurrentWeek = AppUtils.getCurrentWeek(getBaseContext());
    List<CourseV2> courseV2s = Cache.instance().getCourseV2Dao().queryBuilder().where(CourseV2Dao.Properties.CouCgId.eq(group_id)).list();
    mCourses = new ArrayList<>();
    for (CourseV2 course : courseV2s) {
        course.init();
        if (course.getColor() == -1) {
            course.setColor(Utils.getRandomColor());
        }
        course.setActiveStatus(course.shouldShow(mCurrentWeek));
        mCourses.add(course);
    }
}
Also used : CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)

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