From 66abc0495a9f7f53f3ee0210e4fd9e4fa6d9d255 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 2 Aug 2019 14:18:25 +0800 Subject: [PATCH] =?UTF-8?q?kind=20=E6=94=B9=E4=BD=8DString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/content/BookChapterList.java | 30 ++++----- .../bookshelf/model/content/BookContent.java | 8 +-- .../bookshelf/model/content/BookInfo.java | 4 +- .../bookshelf/model/content/BookList.java | 64 +++++++++---------- .../kunfei/bookshelf/model/content/Debug.java | 15 +++-- 5 files changed, 64 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapterList.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapterList.java index 451155a2a7..d96f5ac739 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapterList.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapterList.java @@ -53,8 +53,8 @@ public Observable> analyzeChapterList(final String s, fina e.onError(new Throwable(MApplication.getInstance().getString(R.string.get_chapter_list_error) + bookShelfBean.getBookInfoBean().getChapterUrl())); return; } else { - Debug.printLog(tag, "┌成功获取目录页", analyzeNextUrl); - Debug.printLog(tag, "└" + bookShelfBean.getBookInfoBean().getChapterUrl(), analyzeNextUrl); + Debug.printLog(tag, 1, "┌成功获取目录页", analyzeNextUrl); + Debug.printLog(tag, 1, "└" + bookShelfBean.getBookInfoBean().getChapterUrl(), analyzeNextUrl); } bookShelfBean.setTag(tag); AnalyzeRule analyzer = new AnalyzeRule(bookShelfBean); @@ -157,7 +157,7 @@ private void finish(List chapterList, Emitter lh = new LinkedHashSet<>(chapterList); chapterList = new ArrayList<>(lh); Collections.reverse(chapterList); - Debug.printLog(tag, "-目录解析完成", analyzeNextUrl); + Debug.printLog(tag, 1, "-目录解析完成", analyzeNextUrl); emitter.onNext(chapterList); emitter.onComplete(); } @@ -167,23 +167,23 @@ private WebChapterBean analyzeChapterList(String s, String chapterUrl, String ru List nextUrlList = new ArrayList<>(); analyzer.setContent(s, chapterUrl); if (!TextUtils.isEmpty(bookSourceBean.getRuleChapterUrlNext()) && analyzeNextUrl) { - Debug.printLog(tag, "┌获取目录下一页网址", printLog); + Debug.printLog(tag, 1, "┌获取目录下一页网址", printLog); nextUrlList = analyzer.getStringList(bookSourceBean.getRuleChapterUrlNext(), true); int thisUrlIndex = nextUrlList.indexOf(chapterUrl); if (thisUrlIndex != -1) { nextUrlList.remove(thisUrlIndex); } - Debug.printLog(tag, "└" + nextUrlList.toString(), printLog); + Debug.printLog(tag, 1, "└" + nextUrlList.toString(), printLog); } List chapterBeans = new ArrayList<>(); - Debug.printLog(tag, "┌解析目录列表", printLog); + Debug.printLog(tag, 1, "┌解析目录列表", printLog); // 仅使用java正则表达式提取目录列表 if (ruleChapterList.startsWith(":")) { ruleChapterList = ruleChapterList.substring(1); regexChapter(s, ruleChapterList.split("&&"), 0, analyzer, chapterBeans); if (chapterBeans.size() == 0) { - Debug.printLog(tag, "└找到 0 个章节", printLog); + Debug.printLog(tag, 1, "└找到 0 个章节", printLog); return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList)); } } @@ -192,7 +192,7 @@ else if (ruleChapterList.startsWith("+")) { ruleChapterList = ruleChapterList.substring(1); List collections = analyzer.getElements(ruleChapterList); if (collections.size() == 0) { - Debug.printLog(tag, "└找到 0 个章节", printLog); + Debug.printLog(tag, 1, "└找到 0 个章节", printLog); return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList)); } String nameRule = bookSourceBean.getRuleChapterName(); @@ -214,7 +214,7 @@ else if (ruleChapterList.startsWith("+")) { else { List collections = analyzer.getElements(ruleChapterList); if (collections.size() == 0) { - Debug.printLog(tag, "└找到 0 个章节", printLog); + Debug.printLog(tag, 1, "└找到 0 个章节", printLog); return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList)); } List nameRule = analyzer.splitSourceRule(bookSourceBean.getRuleChapterName()); @@ -224,18 +224,18 @@ else if (ruleChapterList.startsWith("+")) { addChapter(chapterBeans, analyzer.getString(nameRule), analyzer.getString(linkRule)); } } - Debug.printLog(tag, "└找到 " + chapterBeans.size() + " 个章节", printLog); + Debug.printLog(tag, 1, "└找到 " + chapterBeans.size() + " 个章节", printLog); BookChapterBean firstChapter; if (dx) { - Debug.printLog(tag, "-倒序", printLog); + Debug.printLog(tag, 1, "-倒序", printLog); firstChapter = chapterBeans.get(chapterBeans.size() - 1); } else { firstChapter = chapterBeans.get(0); } - Debug.printLog(tag, "┌获取章节名称", printLog); - Debug.printLog(tag, "└" + firstChapter.getDurChapterName(), printLog); - Debug.printLog(tag, "┌获取章节网址", printLog); - Debug.printLog(tag, "└" + firstChapter.getDurChapterUrl(), printLog); + Debug.printLog(tag, 1, "┌获取章节名称", printLog); + Debug.printLog(tag, 1, "└" + firstChapter.getDurChapterName(), printLog); + Debug.printLog(tag, 1, "┌获取章节网址", printLog); + Debug.printLog(tag, 1, "└" + firstChapter.getDurChapterUrl(), printLog); return new WebChapterBean(chapterBeans, new LinkedHashSet<>(nextUrlList)); } diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java index 37ce0ce630..ae4e2d64ea 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java @@ -115,14 +115,14 @@ private WebContentBean analyzeBookContent(AnalyzeRule analyzer, final String s, WebContentBean webContentBean = new WebContentBean(); analyzer.setContent(s, NetworkUtils.getAbsoluteURL(baseUrl, chapterUrl)); - Debug.printLog(tag, "┌解析正文内容", printLog); + Debug.printLog(tag, 1, "┌解析正文内容", printLog); webContentBean.content = StringUtils.formatHtml(analyzer.getString(ruleBookContent)); - Debug.printLog(tag, "└" + webContentBean.content, printLog); + Debug.printLog(tag, 1, "└" + webContentBean.content, printLog); String nextUrlRule = bookSourceBean.getRuleContentUrlNext(); if (!TextUtils.isEmpty(nextUrlRule)) { - Debug.printLog(tag, "┌解析下一页url", printLog); + Debug.printLog(tag, 1, "┌解析下一页url", printLog); webContentBean.nextUrl = analyzer.getString(nextUrlRule, true); - Debug.printLog(tag, "└" + webContentBean.nextUrl, printLog); + Debug.printLog(tag, 1, "└" + webContentBean.nextUrl, printLog); } return webContentBean; diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookInfo.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookInfo.java index 225a1b0f05..5b284d1a71 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookInfo.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookInfo.java @@ -83,7 +83,7 @@ Observable analyzeBookInfo(String s, final BookShelfBean bookShel Debug.printLog(tag, "┌获取分类"); String bookKind = analyzer.getString(bookSourceBean.getRuleBookKind()); - Debug.printLog(tag, "└" + bookKind); + Debug.printLog(tag, 111, "└" + bookKind); Debug.printLog(tag, "┌获取最新章节"); String bookLastChapter = analyzer.getString(bookSourceBean.getRuleBookLastChapter()); @@ -93,7 +93,7 @@ Observable analyzeBookInfo(String s, final BookShelfBean bookShel Debug.printLog(tag, "┌获取简介"); String bookIntroduce = analyzer.getString(bookSourceBean.getRuleIntroduce()); if (!isEmpty(bookIntroduce)) bookInfoBean.setIntroduce(bookIntroduce); - Debug.printLog(tag, "└" + bookIntroduce, true, true); + Debug.printLog(tag, 1, "└" + bookIntroduce, true, true); Debug.printLog(tag, "┌获取封面"); String bookCoverUrl = analyzer.getString(bookSourceBean.getRuleCoverUrl(), true); diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java index 909f1d25e6..a05bfc4b65 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java @@ -215,13 +215,13 @@ private SearchBookBean getItem(AnalyzeRule analyzer, String baseUrl) throws Exce Debug.printLog(tag, "└" + item.getCoverUrl()); Debug.printLog(tag, "┌获取分类"); item.setKind(analyzer.getString(bookSourceBean.getRuleBookKind())); - Debug.printLog(tag, "└" + item.getKind()); + Debug.printLog(tag, 111, "└" + item.getKind()); Debug.printLog(tag, "┌获取最新章节"); item.setLastChapter(analyzer.getString(bookSourceBean.getRuleBookLastChapter())); Debug.printLog(tag, "└最新章节:" + item.getLastChapter()); Debug.printLog(tag, "┌获取简介"); item.setIntroduce(analyzer.getString(bookSourceBean.getRuleIntroduce())); - Debug.printLog(tag, "└" + item.getIntroduce(), true, true); + Debug.printLog(tag, 1, "└" + item.getIntroduce(), true, true); return item; } return null; @@ -231,34 +231,34 @@ private SearchBookBean getItemAllInOne(AnalyzeRule analyzer, Object object, Stri SearchBookBean item = new SearchBookBean(); analyzer.setBook(item); NativeObject nativeObject = (NativeObject) object; - Debug.printLog(tag, "┌获取书名", printLog); + Debug.printLog(tag, 1, "┌获取书名", printLog); String bookName = StringUtils.formatHtml(String.valueOf(nativeObject.get(ruleName))); - Debug.printLog(tag, "└" + bookName, printLog); + Debug.printLog(tag, 1, "└" + bookName, printLog); if (!isEmpty(bookName)) { item.setTag(tag); item.setOrigin(sourceName); item.setName(bookName); - Debug.printLog(tag, "┌获取作者", printLog); + Debug.printLog(tag, 1, "┌获取作者", printLog); item.setAuthor(StringUtils.formatHtml(String.valueOf(nativeObject.get(ruleAuthor)))); - Debug.printLog(tag, "└" + item.getAuthor(), printLog); - Debug.printLog(tag, "┌获取分类", printLog); + Debug.printLog(tag, 1, "└" + item.getAuthor(), printLog); + Debug.printLog(tag, 1, "┌获取分类", printLog); item.setKind(String.valueOf(nativeObject.get(ruleKind))); - Debug.printLog(tag, "└" + item.getKind(), printLog); - Debug.printLog(tag, "┌获取最新章节", printLog); + Debug.printLog(tag, 111, "└" + item.getKind(), printLog); + Debug.printLog(tag, 1, "┌获取最新章节", printLog); item.setLastChapter(String.valueOf(nativeObject.get(ruleLastChapter))); - Debug.printLog(tag, "└" + item.getLastChapter(), printLog); - Debug.printLog(tag, "┌获取简介", printLog); + Debug.printLog(tag, 1, "└" + item.getLastChapter(), printLog); + Debug.printLog(tag, 1, "┌获取简介", printLog); item.setIntroduce(String.valueOf(nativeObject.get(ruleIntroduce))); - Debug.printLog(tag, "└" + item.getIntroduce(), printLog, true); - Debug.printLog(tag, "┌获取封面", printLog); + Debug.printLog(tag, 1, "└" + item.getIntroduce(), printLog, true); + Debug.printLog(tag, 1, "┌获取封面", printLog); if (!isEmpty(ruleCoverUrl)) item.setCoverUrl(NetworkUtils.getAbsoluteURL(baseUrl, String.valueOf(nativeObject.get(ruleCoverUrl)))); - Debug.printLog(tag, "└" + item.getCoverUrl(), printLog); - Debug.printLog(tag, "┌获取书籍网址", printLog); + Debug.printLog(tag, 1, "└" + item.getCoverUrl(), printLog); + Debug.printLog(tag, 1, "┌获取书籍网址", printLog); String resultUrl = String.valueOf(nativeObject.get(ruleNoteUrl)); if (isEmpty(resultUrl)) resultUrl = baseUrl; item.setNoteUrl(resultUrl); - Debug.printLog(tag, "└" + item.getNoteUrl(), printLog); + Debug.printLog(tag, 1, "└" + item.getNoteUrl(), printLog); return item; } return null; @@ -268,33 +268,33 @@ private SearchBookBean getItemInList(AnalyzeRule analyzer, String baseUrl, boole Exception { SearchBookBean item = new SearchBookBean(); analyzer.setBook(item); - Debug.printLog(tag, "┌获取书名", printLog); + Debug.printLog(tag, 1, "┌获取书名", printLog); String bookName = StringUtils.formatHtml(analyzer.getString(ruleName)); - Debug.printLog(tag, "└" + bookName, printLog); + Debug.printLog(tag, 1, "└" + bookName, printLog); if (!TextUtils.isEmpty(bookName)) { item.setTag(tag); item.setOrigin(sourceName); item.setName(bookName); - Debug.printLog(tag, "┌获取作者", printLog); + Debug.printLog(tag, 1, "┌获取作者", printLog); item.setAuthor(StringUtils.formatHtml(analyzer.getString(ruleAuthor))); - Debug.printLog(tag, "└" + item.getAuthor(), printLog); - Debug.printLog(tag, "┌获取分类", printLog); + Debug.printLog(tag, 1, "└" + item.getAuthor(), printLog); + Debug.printLog(tag, 1, "┌获取分类", printLog); item.setKind(analyzer.getString(ruleKind)); - Debug.printLog(tag, "└" + item.getKind(), printLog); - Debug.printLog(tag, "┌获取最新章节", printLog); + Debug.printLog(tag, 111, "└" + item.getKind(), printLog); + Debug.printLog(tag, 1, "┌获取最新章节", printLog); item.setLastChapter(analyzer.getString(ruleLastChapter)); - Debug.printLog(tag, "└" + item.getLastChapter(), printLog); - Debug.printLog(tag, "┌获取简介", printLog); + Debug.printLog(tag, 1, "└" + item.getLastChapter(), printLog); + Debug.printLog(tag, 1, "┌获取简介", printLog); item.setIntroduce(analyzer.getString(ruleIntroduce)); - Debug.printLog(tag, "└" + item.getIntroduce(), printLog, true); - Debug.printLog(tag, "┌获取封面", printLog); + Debug.printLog(tag, 1, "└" + item.getIntroduce(), printLog, true); + Debug.printLog(tag, 1, "┌获取封面", printLog); item.setCoverUrl(analyzer.getString(ruleCoverUrl, true)); - Debug.printLog(tag, "└" + item.getCoverUrl(), printLog); - Debug.printLog(tag, "┌获取书籍网址", printLog); + Debug.printLog(tag, 1, "└" + item.getCoverUrl(), printLog); + Debug.printLog(tag, 1, "┌获取书籍网址", printLog); String resultUrl = analyzer.getString(ruleNoteUrl, true); if (isEmpty(resultUrl)) resultUrl = baseUrl; item.setNoteUrl(resultUrl); - Debug.printLog(tag, "└" + item.getNoteUrl(), printLog); + Debug.printLog(tag, 1, "└" + item.getNoteUrl(), printLog); return item; } return null; @@ -385,11 +385,11 @@ private void getBooksOfRegex(String res, String[] regs, Debug.printLog(tag, "┌获取作者名称"); Debug.printLog(tag, "└" + books.get(0).getAuthor()); Debug.printLog(tag, "┌获取分类信息"); - Debug.printLog(tag, "└" + books.get(0).getKind()); + Debug.printLog(tag, 111, "└" + books.get(0).getKind()); Debug.printLog(tag, "┌获取最新章节"); Debug.printLog(tag, "└" + books.get(0).getLastChapter()); Debug.printLog(tag, "┌获取简介内容"); - Debug.printLog(tag, "└" + books.get(0).getIntroduce(), true, true); + Debug.printLog(tag, 1, "└" + books.get(0).getIntroduce(), true, true); Debug.printLog(tag, "┌获取封面网址"); Debug.printLog(tag, "└" + books.get(0).getCoverUrl()); Debug.printLog(tag, "┌获取书籍网址"); diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/Debug.java b/app/src/main/java/com/kunfei/bookshelf/model/content/Debug.java index 2ab2d6c2dd..b3023e3726 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/Debug.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/Debug.java @@ -40,18 +40,25 @@ private static String getDoTime() { } public static void printLog(String tag, String msg) { - printLog(tag, msg, true); + printLog(tag, 1, msg, true); } - static void printLog(String tag, String msg, boolean print) { - printLog(tag, msg, print, false); + public static void printLog(String tag, int state, String msg) { + printLog(tag, state, msg, true); } - static void printLog(String tag, String msg, boolean print, boolean formatHtml) { + static void printLog(String tag, int state, String msg, boolean print) { + printLog(tag, state, msg, print, false); + } + + static void printLog(String tag, int state, String msg, boolean print, boolean formatHtml) { if (print && Objects.equals(SOURCE_DEBUG_TAG, tag)) { if (formatHtml) { msg = StringUtils.formatHtml(msg); } + if (state == 111) { + msg = msg.replace("\n", ","); + } msg = String.format("%s %s", getDoTime(), msg); RxBus.get().post(RxBusTag.PRINT_DEBUG_LOG, msg); }