From bdc29a545d31364f79dcfc17977af42e3a83f41b Mon Sep 17 00:00:00 2001 From: tumuyan Date: Wed, 30 Sep 2020 01:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=96=84=E6=B7=BB=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E5=9D=80=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 降低了由于书源规则不完善导致的添加网址的异常 --- .../bookshelf/presenter/MainPresenter.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/presenter/MainPresenter.java b/app/src/main/java/com/kunfei/bookshelf/presenter/MainPresenter.java index a968c5581e..7eabe9700c 100644 --- a/app/src/main/java/com/kunfei/bookshelf/presenter/MainPresenter.java +++ b/app/src/main/java/com/kunfei/bookshelf/presenter/MainPresenter.java @@ -69,9 +69,14 @@ private Observable addBookUrlO(String bookUrl) { } else { String baseUrl = StringUtils.getBaseUrl(bookUrl); BookSourceBean bookSourceBean = DbHelper.getDaoSession().getBookSourceBeanDao().load(baseUrl); + + // RuleBookUrlPattern推定 考虑有书源规则不完善,需要排除RuleBookUrlPatternt填写.*匹配全部url的情况 if (bookSourceBean == null) { List sourceBeans = DbHelper.getDaoSession().getBookSourceBeanDao().queryBuilder() - .where(BookSourceBeanDao.Properties.RuleBookUrlPattern.isNotNull(), BookSourceBeanDao.Properties.RuleBookUrlPattern.notEq("")).list(); + .where(BookSourceBeanDao.Properties.RuleBookUrlPattern.isNotNull() + , BookSourceBeanDao.Properties.RuleBookUrlPattern.notEq("") + , BookSourceBeanDao.Properties.RuleBookUrlPattern.notEq(".*") + ).list(); for (BookSourceBean sourceBean : sourceBeans) { if (bookUrl.matches(sourceBean.getRuleBookUrlPattern())) { bookSourceBean = sourceBean; @@ -79,6 +84,29 @@ private Observable addBookUrlO(String bookUrl) { } } } + + //BookSourceUrl推定 考虑有书源规则不完善,没有填写RuleBookUrlPattern的情况(但是通常会填写bookSourceUrl),因此需要做补充 + if (bookSourceBean == null) { + String siteUrl = bookUrl.replaceFirst("^(http://|https://)", "") + .replaceFirst("/.*$", ""); + if(siteUrl.length()>3){ + List sourceBeans = DbHelper.getDaoSession().getBookSourceBeanDao().queryBuilder() + .where(BookSourceBeanDao.Properties.BookSourceUrl.like("%" + siteUrl + "%")).list(); + for (BookSourceBean sourceBean : sourceBeans) { + if (sourceBean.getRuleBookUrlPattern().equals(null)) { + bookSourceBean = sourceBean; + break; + } else if (sourceBean.getRuleBookUrlPattern().replaceAll("\\s", "").length() == 0) { + bookSourceBean = sourceBean; + break; + } else if (bookUrl.matches(sourceBean.getRuleBookUrlPattern())) { + bookSourceBean = sourceBean; + break; + } + } + } + } + if (bookSourceBean != null) { BookShelfBean bookShelfBean = new BookShelfBean(); bookShelfBean.setTag(bookSourceBean.getBookSourceUrl()); @@ -158,4 +186,4 @@ public void recreate(Boolean recreate) { mView.recreate(); } -} \ No newline at end of file +}