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 +}