Skip to content

Commit

Permalink
Merge pull request #540 from tumuyan/patch-1
Browse files Browse the repository at this point in the history
改善添加网址功能
  • Loading branch information
gedoor authored Sep 29, 2020
2 parents 638c04b + bdc29a5 commit 02c71e7
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,44 @@ private Observable<BookShelfBean> addBookUrlO(String bookUrl) {
} else {
String baseUrl = StringUtils.getBaseUrl(bookUrl);
BookSourceBean bookSourceBean = DbHelper.getDaoSession().getBookSourceBeanDao().load(baseUrl);

// RuleBookUrlPattern推定 考虑有书源规则不完善,需要排除RuleBookUrlPatternt填写.*匹配全部url的情况
if (bookSourceBean == null) {
List<BookSourceBean> 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;
break;
}
}
}

//BookSourceUrl推定 考虑有书源规则不完善,没有填写RuleBookUrlPattern的情况(但是通常会填写bookSourceUrl),因此需要做补充
if (bookSourceBean == null) {
String siteUrl = bookUrl.replaceFirst("^(http://|https://)", "")
.replaceFirst("/.*$", "");
if(siteUrl.length()>3){
List<BookSourceBean> 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());
Expand Down Expand Up @@ -158,4 +186,4 @@ public void recreate(Boolean recreate) {
mView.recreate();
}

}
}

0 comments on commit 02c71e7

Please sign in to comment.