From 6f22ed7185a8e8a81f17c354104e0b4b853097c5 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sat, 15 May 2021 10:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E6=BA=90=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../entity/thirdsource/ThirdSourceUtil.java | 1 + .../{GreenDaoManager.java => DbManager.java} | 10 +- .../myreader/greendao/entity/CookieBean.java | 70 +++++++++ .../greendao/entity/rule/BookSource.java | 22 ++- .../greendao/service/BaseService.java | 12 +- .../greendao/service/BookGroupService.java | 10 +- .../greendao/service/BookMarkService.java | 23 +-- .../greendao/service/BookService.java | 20 +-- .../greendao/service/ChapterService.java | 11 +- .../service/SearchHistoryService.java | 4 +- .../greendao/util/MySQLiteOpenHelper.java | 2 +- .../myreader/model/ReplaceRuleManager.java | 35 ++--- .../sourceAnalyzer/BookSourceManager.java | 54 ++++--- .../xyz/fycz/myreader/model/storage/Backup.kt | 10 +- .../fycz/myreader/model/storage/Restore.kt | 14 +- .../model/third/content/BookContent.java | 4 +- .../ui/activity/BookDetailedActivity.java | 12 +- .../myreader/ui/activity/SplashActivity.java | 2 +- .../ui/adapter/BookSourceAdapter.java | 12 +- .../ui/adapter/holder/LocalSourceHolder.java | 6 +- .../ui/adapter/holder/SearchBookHolder.java | 6 + .../ui/fragment/DIYSourceFragment.java | 9 +- .../ui/fragment/LocalSourceFragment.java | 4 +- .../xyz/fycz/myreader/util/utils/AdUtils.java | 6 +- .../fycz/myreader/util/utils/OkHttpUtils.java | 30 +++- .../xyz/fycz/myreader/webapi/CommonApi.java | 105 +------------ .../fycz/myreader/webapi/ThirdSourceApi.java | 143 ++++++++++++++++++ .../webapi/crawler/base/BaseReadCrawler.java | 18 +++ .../webapi/crawler/base/ReadCrawler.java | 10 ++ app/src/main/res/menu/menu_source_edit.xml | 39 +++-- 31 files changed, 446 insertions(+), 260 deletions(-) rename app/src/main/java/xyz/fycz/myreader/greendao/{GreenDaoManager.java => DbManager.java} (80%) create mode 100644 app/src/main/java/xyz/fycz/myreader/greendao/entity/CookieBean.java create mode 100644 app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java diff --git a/app/build.gradle b/app/build.gradle index 4ba1860..790a8bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -208,7 +208,7 @@ dependencies { } greendao { - schemaVersion 26 + schemaVersion 27 daoPackage 'xyz.fycz.myreader.greendao.gen' // targetGenDir 'src/main/java' } diff --git a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java index b5ec3fe..c7f2ad2 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java +++ b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java @@ -22,6 +22,7 @@ public class ThirdSourceUtil { bookSource.setSourceName(bean.getBookSourceName()); bookSource.setSourceGroup(bean.getBookSourceGroup()); bookSource.setSourceType(APPCONST.THIRD_SOURCE); + bookSource.setLoginUrl(bean.getLoginUrl()); bookSource.setLastUpdateTime(bean.getLastUpdateTime()); bookSource.setOrderNum(bean.getSerialNumber()); bookSource.setWeight(bean.getWeight()); diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/GreenDaoManager.java b/app/src/main/java/xyz/fycz/myreader/greendao/DbManager.java similarity index 80% rename from app/src/main/java/xyz/fycz/myreader/greendao/GreenDaoManager.java rename to app/src/main/java/xyz/fycz/myreader/greendao/DbManager.java index 25abc8b..7f2c0e0 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/GreenDaoManager.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/DbManager.java @@ -8,21 +8,21 @@ import xyz.fycz.myreader.greendao.util.MySQLiteOpenHelper; -public class GreenDaoManager { - private static GreenDaoManager instance; +public class DbManager { + private static DbManager instance; private static DaoMaster daoMaster; private DaoSession mDaoSession; private static MySQLiteOpenHelper mySQLiteOpenHelper; - public static GreenDaoManager getInstance() { + public static DbManager getInstance() { if (instance == null) { - instance = new GreenDaoManager(); + instance = new DbManager(); } return instance; } - public GreenDaoManager(){ + public DbManager(){ mySQLiteOpenHelper = new MySQLiteOpenHelper(App.getmContext(), "read" , null); daoMaster = new DaoMaster(mySQLiteOpenHelper.getWritableDatabase()); mDaoSession = daoMaster.newSession(); diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/CookieBean.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/CookieBean.java new file mode 100644 index 0000000..5c4bd6c --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/CookieBean.java @@ -0,0 +1,70 @@ +package xyz.fycz.myreader.greendao.entity; + +import android.os.Parcel; +import android.os.Parcelable; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; + +@Entity +public class CookieBean implements Parcelable { + + @Id + private String url; + private String cookie; + + private CookieBean(Parcel in) { + url = in.readString(); + cookie = in.readString(); + } + + @Generated(hash = 517179762) + public CookieBean(String url, String cookie) { + this.url = url; + this.cookie = cookie; + } + + @Generated(hash = 769081142) + public CookieBean() { + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(url); + dest.writeString(cookie); + } + + @Override + public int describeContents() { + return 0; + } + + public String getUrl() { + return this.url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getCookie() { + return cookie == null ? "" : cookie; + } + + public void setCookie(String cookie) { + this.cookie = cookie; + } + + public static final Creator CREATOR = new Creator() { + @Override + public CookieBean createFromParcel(Parcel in) { + return new CookieBean(in); + } + + @Override + public CookieBean[] newArray(int size) { + return new CookieBean[size]; + } + }; +} diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java index e9615a6..6272b71 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java @@ -43,6 +43,7 @@ public class BookSource implements Parcelable, Cloneable { private String sourceCharset; private String sourceType; private String sourceHeaders; + private String loginUrl; private String sourceComment; private Long lastUpdateTime; @@ -72,11 +73,12 @@ public class BookSource implements Parcelable, Cloneable { @Convert(converter = FindRuleConvert.class, columnType = String.class) private FindRule findRule; - @Generated(hash = 1082429073) + @Generated(hash = 277037260) public BookSource(String sourceUrl, String sourceEName, String sourceName, String sourceGroup, - String sourceCharset, String sourceType, String sourceHeaders, String sourceComment, - Long lastUpdateTime, int orderNum, int weight, boolean enable, SearchRule searchRule, - InfoRule infoRule, TocRule tocRule, ContentRule contentRule, FindRule findRule) { + String sourceCharset, String sourceType, String sourceHeaders, String loginUrl, + String sourceComment, Long lastUpdateTime, int orderNum, int weight, boolean enable, + SearchRule searchRule, InfoRule infoRule, TocRule tocRule, ContentRule contentRule, + FindRule findRule) { this.sourceUrl = sourceUrl; this.sourceEName = sourceEName; this.sourceName = sourceName; @@ -84,6 +86,7 @@ public class BookSource implements Parcelable, Cloneable { this.sourceCharset = sourceCharset; this.sourceType = sourceType; this.sourceHeaders = sourceHeaders; + this.loginUrl = loginUrl; this.sourceComment = sourceComment; this.lastUpdateTime = lastUpdateTime; this.orderNum = orderNum; @@ -109,6 +112,7 @@ public class BookSource implements Parcelable, Cloneable { sourceCharset = in.readString(); sourceType = in.readString(); sourceHeaders = in.readString(); + loginUrl = in.readString(); sourceComment = in.readString(); if (in.readByte() == 0) { lastUpdateTime = null; @@ -134,6 +138,7 @@ public class BookSource implements Parcelable, Cloneable { dest.writeString(sourceCharset); dest.writeString(sourceType); dest.writeString(sourceHeaders); + dest.writeString(loginUrl); dest.writeString(sourceComment); if (lastUpdateTime == null) { dest.writeByte((byte) 0); @@ -181,6 +186,7 @@ public class BookSource implements Parcelable, Cloneable { stringEquals(sourceCharset, source.sourceCharset) && stringEquals(sourceType, source.sourceType) && stringEquals(sourceHeaders, source.sourceHeaders) && + stringEquals(loginUrl, source.loginUrl) && stringEquals(sourceComment, source.sourceComment) && Objects.equals(searchRule, source.searchRule) && Objects.equals(infoRule, source.infoRule) && @@ -383,4 +389,12 @@ public class BookSource implements Parcelable, Cloneable { public void setSourceHeaders(String sourceHeaders) { this.sourceHeaders = sourceHeaders; } + + public String getLoginUrl() { + return this.loginUrl; + } + + public void setLoginUrl(String loginUrl) { + this.loginUrl = loginUrl; + } } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/BaseService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/BaseService.java index 261e1aa..ad41666 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/BaseService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/BaseService.java @@ -3,23 +3,23 @@ package xyz.fycz.myreader.greendao.service; import android.database.Cursor; import xyz.fycz.myreader.greendao.gen.DaoSession; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; public class BaseService { public void addEntity(Object entity){ - DaoSession daoSession = GreenDaoManager.getInstance().getSession(); + DaoSession daoSession = DbManager.getInstance().getSession(); daoSession.insert(entity); } public void updateEntity(Object entity){ - DaoSession daoSession = GreenDaoManager.getInstance().getSession(); + DaoSession daoSession = DbManager.getInstance().getSession(); daoSession.update(entity); } public void deleteEntity(Object entity){ - DaoSession daoSession = GreenDaoManager.getInstance().getSession(); + DaoSession daoSession = DbManager.getInstance().getSession(); daoSession.delete(entity); } @@ -33,7 +33,7 @@ public class BaseService { Cursor cursor = null; try { - DaoSession daoSession = GreenDaoManager.getInstance().getSession(); + DaoSession daoSession = DbManager.getInstance().getSession(); cursor = daoSession.getDatabase().rawQuery(sql, selectionArgs); } catch (Exception e) { e.printStackTrace(); @@ -48,7 +48,7 @@ public class BaseService { * @param selectionArgs */ public void rawQuery(String sql, String[] selectionArgs) { - DaoSession daoSession = GreenDaoManager.getInstance().getSession(); + DaoSession daoSession = DbManager.getInstance().getSession(); Cursor cursor = daoSession.getDatabase().rawQuery(sql, selectionArgs); } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookGroupService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookGroupService.java index 2b81bb9..de4212f 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookGroupService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookGroupService.java @@ -2,7 +2,7 @@ package xyz.fycz.myreader.greendao.service; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.BookGroup; import xyz.fycz.myreader.greendao.gen.BookGroupDao; import xyz.fycz.myreader.util.SharedPreUtils; @@ -33,7 +33,7 @@ public class BookGroupService extends BaseService{ * @return */ public List getAllGroups(){ - return GreenDaoManager.getInstance().getSession().getBookGroupDao() + return DbManager.getInstance().getSession().getBookGroupDao() .queryBuilder() .orderAsc(BookGroupDao.Properties.Num) .list(); @@ -45,7 +45,7 @@ public class BookGroupService extends BaseService{ * @return */ public BookGroup getGroupById(String groupId){ - return GreenDaoManager.getInstance().getSession().getBookGroupDao() + return DbManager.getInstance().getSession().getBookGroupDao() .queryBuilder() .where(BookGroupDao.Properties.Id.eq(groupId)) .unique(); @@ -70,7 +70,7 @@ public class BookGroupService extends BaseService{ } public void deleteGroupById(String id){ - GreenDaoManager.getInstance().getSession().getBookGroupDao().deleteByKey(id); + DbManager.getInstance().getSession().getBookGroupDao().deleteByKey(id); } public void createPrivateGroup(){ @@ -97,7 +97,7 @@ public class BookGroupService extends BaseService{ } private int countBookGroup(){ - return (int) GreenDaoManager.getInstance().getSession().getBookGroupDao() + return (int) DbManager.getInstance().getSession().getBookGroupDao() .queryBuilder() .count(); } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookMarkService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookMarkService.java index e6d02ae..5bece16 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookMarkService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookMarkService.java @@ -1,20 +1,11 @@ package xyz.fycz.myreader.greendao.service; -import android.database.Cursor; -import xyz.fycz.myreader.greendao.GreenDaoManager; -import xyz.fycz.myreader.greendao.entity.Book; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.BookMark; -import xyz.fycz.myreader.greendao.entity.Chapter; -import xyz.fycz.myreader.greendao.entity.SearchHistory; -import xyz.fycz.myreader.greendao.gen.BookDao; import xyz.fycz.myreader.greendao.gen.BookMarkDao; -import xyz.fycz.myreader.greendao.gen.ChapterDao; -import xyz.fycz.myreader.greendao.gen.SearchHistoryDao; -import xyz.fycz.myreader.util.DateHelper; import xyz.fycz.myreader.util.StringHelper; import java.util.ArrayList; -import java.util.Date; import java.util.List; @@ -38,7 +29,7 @@ public class BookMarkService extends BaseService { * @return */ public BookMark getBookById(String id) { - BookMarkDao bookMarkDao = GreenDaoManager.getInstance().getSession().getBookMarkDao(); + BookMarkDao bookMarkDao = DbManager.getInstance().getSession().getBookMarkDao(); return bookMarkDao.load(id); } @@ -48,7 +39,7 @@ public class BookMarkService extends BaseService { * @return */ public BookMark findBookMarkByTitle(String title){ - return GreenDaoManager.getInstance().getSession().getBookMarkDao() + return DbManager.getInstance().getSession().getBookMarkDao() .queryBuilder() .where(BookMarkDao.Properties.Title.eq(title)) .unique(); @@ -62,7 +53,7 @@ public class BookMarkService extends BaseService { if (bookId == null) { return new ArrayList<>(); } - return GreenDaoManager.getInstance().getSession().getBookMarkDao() + return DbManager.getInstance().getSession().getBookMarkDao() .queryBuilder() .where(BookMarkDao.Properties.BookId.eq(bookId)) .orderAsc(BookMarkDao.Properties.Number) @@ -86,7 +77,7 @@ public class BookMarkService extends BaseService { * @param bookId */ public void deleteBookALLBookMarkById(String bookId) { - GreenDaoManager.getInstance().getSession().getBookMarkDao() + DbManager.getInstance().getSession().getBookMarkDao() .queryBuilder() .where(BookMarkDao.Properties.BookId.eq(bookId)) .buildDelete() @@ -108,7 +99,7 @@ public class BookMarkService extends BaseService { * @param id */ public void deleteBookMarkById(String id){ - BookMarkDao bookMarkDao = GreenDaoManager.getInstance().getSession().getBookMarkDao(); + BookMarkDao bookMarkDao = DbManager.getInstance().getSession().getBookMarkDao(); bookMarkDao.deleteByKey(id); } @@ -136,7 +127,7 @@ public class BookMarkService extends BaseService { e.printStackTrace(); }*/ - return (int) GreenDaoManager.getInstance().getSession().getBookMarkDao() + return (int) DbManager.getInstance().getSession().getBookMarkDao() .queryBuilder() .where(BookMarkDao.Properties.BookId.eq(bookId)) .count(); diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java index b096087..76fdc93 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java @@ -13,7 +13,7 @@ import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.gen.BookDao; import xyz.fycz.myreader.util.*; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.StringUtils; @@ -57,7 +57,7 @@ public class BookService extends BaseService { * @return */ public Book getBookById(String id) { - BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); + BookDao bookDao = DbManager.getInstance().getSession().getBookDao(); return bookDao.load(id); } @@ -67,7 +67,7 @@ public class BookService extends BaseService { * @return */ public List getAllBooks() { - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .orderAsc(BookDao.Properties.SortCode) .list(); @@ -97,7 +97,7 @@ public class BookService extends BaseService { if (StringHelper.isEmpty(groupId)){ return getAllBooksNoHide(); } - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .where(BookDao.Properties.GroupId.eq(groupId)) .orderAsc(BookDao.Properties.GroupSort) @@ -148,13 +148,13 @@ public class BookService extends BaseService { */ public Book findBookByAuthorAndName(String bookName, String author) { try { - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author)) .unique(); } catch (Exception e) { e.printStackTrace(); - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author)) .list().get(0); @@ -169,13 +169,13 @@ public class BookService extends BaseService { */ public Book findBookByPath(String path) { try { - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .where(BookDao.Properties.ChapterUrl.eq(path)) .unique(); } catch (Exception e) { e.printStackTrace(); - return GreenDaoManager.getInstance().getSession().getBookDao() + return DbManager.getInstance().getSession().getBookDao() .queryBuilder() .where(BookDao.Properties.ChapterUrl.eq(path)) .list().get(0); @@ -188,7 +188,7 @@ public class BookService extends BaseService { * @param id */ public void deleteBookById(String id) { - BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); + BookDao bookDao = DbManager.getInstance().getSession().getBookDao(); bookDao.deleteByKey(id); mChapterService.deleteBookALLChapterById(id); mBookMarkService.deleteBookALLBookMarkById(id); @@ -249,7 +249,7 @@ public class BookService extends BaseService { * @param books */ public void updateBooks(List books) { - BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); + BookDao bookDao = DbManager.getInstance().getSession().getBookDao(); bookDao.updateInTx(books); } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/ChapterService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/ChapterService.java index f0b94ab..f0a3ea5 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/ChapterService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/ChapterService.java @@ -2,13 +2,12 @@ package xyz.fycz.myreader.greendao.service; import android.database.Cursor; -import android.util.Log; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.gen.ChapterDao; import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.util.utils.FileUtils; import java.io.*; @@ -60,7 +59,7 @@ public class ChapterService extends BaseService { * @return */ public Chapter getChapterById(String id) { - ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); + ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao(); return chapterDao.load(id); } @@ -119,7 +118,7 @@ public class ChapterService extends BaseService { * @param bookId */ public void deleteBookALLChapterById(String bookId) { - GreenDaoManager.getInstance().getSession().getChapterDao() + DbManager.getInstance().getSession().getChapterDao() .queryBuilder() .where(ChapterDao.Properties.BookId.eq(bookId)) .buildDelete() @@ -131,7 +130,7 @@ public class ChapterService extends BaseService { * 更新章节 */ public void updateChapter(Chapter chapter) { - ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); + ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao(); chapterDao.update(chapter); } @@ -172,7 +171,7 @@ public class ChapterService extends BaseService { * 批量添加章节 */ public void addChapters(List chapters) { - ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); + ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao(); chapterDao.insertInTx(chapters); } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/service/SearchHistoryService.java b/app/src/main/java/xyz/fycz/myreader/greendao/service/SearchHistoryService.java index f35dd44..b93012c 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/service/SearchHistoryService.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/service/SearchHistoryService.java @@ -6,7 +6,7 @@ import xyz.fycz.myreader.greendao.entity.SearchHistory; import xyz.fycz.myreader.greendao.gen.SearchHistoryDao; import xyz.fycz.myreader.util.DateHelper; import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import java.util.ArrayList; import java.util.Date; @@ -77,7 +77,7 @@ public class SearchHistoryService extends BaseService { * 清空历史记录 */ public void clearHistory(){ - SearchHistoryDao searchHistoryDao = GreenDaoManager.getInstance().getSession().getSearchHistoryDao(); + SearchHistoryDao searchHistoryDao = DbManager.getInstance().getSession().getSearchHistoryDao(); searchHistoryDao.deleteAll(); } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/util/MySQLiteOpenHelper.java b/app/src/main/java/xyz/fycz/myreader/greendao/util/MySQLiteOpenHelper.java index d049bfb..5c89b97 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/util/MySQLiteOpenHelper.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/util/MySQLiteOpenHelper.java @@ -38,7 +38,7 @@ public class MySQLiteOpenHelper extends DaoMaster.OpenHelper { }, BookDao.class, ChapterDao.class, SearchHistoryDao.class, BookMarkDao.class, BookGroupDao.class, ReplaceRuleBeanDao.class, - BookSourceDao.class + BookSourceDao.class, CookieBeanDao.class ); } diff --git a/app/src/main/java/xyz/fycz/myreader/model/ReplaceRuleManager.java b/app/src/main/java/xyz/fycz/myreader/model/ReplaceRuleManager.java index 5bd8190..db47421 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/ReplaceRuleManager.java +++ b/app/src/main/java/xyz/fycz/myreader/model/ReplaceRuleManager.java @@ -8,14 +8,11 @@ import java.util.Collections; import java.util.List; import io.reactivex.Observable; -import io.reactivex.ObservableEmitter; import io.reactivex.ObservableOnSubscribe; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; -import io.reactivex.annotations.NonNull; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; -import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.gen.ReplaceRuleBeanDao; import xyz.fycz.myreader.util.utils.GsonUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; @@ -33,7 +30,7 @@ public class ReplaceRuleManager { public static List getEnabled() { if (replaceRuleBeansEnabled == null) { - replaceRuleBeansEnabled = GreenDaoManager.getDaoSession() + replaceRuleBeansEnabled = DbManager.getDaoSession() .getReplaceRuleBeanDao().queryBuilder() .where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) @@ -54,11 +51,11 @@ public class ReplaceRuleManager { int sn = replaceRuleBean.getSerialNumber(); if (sn == 0) { - sn = (int) (GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1); + sn = (int) (DbManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1); replaceRuleBean.setSerialNumber(sn); } - List list = GreenDaoManager.getDaoSession() + List list = DbManager.getDaoSession() .getReplaceRuleBeanDao().queryBuilder() .where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .where(ReplaceRuleBeanDao.Properties.ReplaceSummary.eq(replaceRuleBean.getReplaceSummary())) @@ -79,9 +76,9 @@ public class ReplaceRuleManager { return Single.create((SingleOnSubscribe) emitter -> { - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean); + DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean); for (ReplaceRuleBean li : list) { - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().delete(li); + DbManager.getDaoSession().getReplaceRuleBeanDao().delete(li); } refreshDataS(); emitter.onSuccess(true); @@ -130,14 +127,14 @@ public class ReplaceRuleManager { return buffer.toString().trim(); } public static Single> getAll() { - return Single.create((SingleOnSubscribe>) emitter -> emitter.onSuccess(GreenDaoManager.getDaoSession() + return Single.create((SingleOnSubscribe>) emitter -> emitter.onSuccess(DbManager.getDaoSession() .getReplaceRuleBeanDao().queryBuilder() .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .list())).compose(RxUtils::toSimpleSingle); } public static List getAllRules() { - return GreenDaoManager.getDaoSession() + return DbManager.getDaoSession() .getReplaceRuleBeanDao().queryBuilder() .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .list(); @@ -146,29 +143,29 @@ public class ReplaceRuleManager { public static Single saveData(ReplaceRuleBean replaceRuleBean) { return Single.create((SingleOnSubscribe) emitter -> { if (replaceRuleBean.getSerialNumber() == 0) { - replaceRuleBean.setSerialNumber((int) (GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1)); + replaceRuleBean.setSerialNumber((int) (DbManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1)); } - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean); + DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean); refreshDataS(); emitter.onSuccess(true); }).compose(RxUtils::toSimpleSingle); } public static void delData(ReplaceRuleBean replaceRuleBean) { - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().delete(replaceRuleBean); + DbManager.getDaoSession().getReplaceRuleBeanDao().delete(replaceRuleBean); refreshDataS(); } public static void addDataS(List replaceRuleBeans) { if (replaceRuleBeans != null && replaceRuleBeans.size() > 0) { - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(replaceRuleBeans); + DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(replaceRuleBeans); refreshDataS(); } } public static void delDataS(List replaceRuleBeans) { if (replaceRuleBeans == null) return; - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().deleteInTx(replaceRuleBeans); + DbManager.getDaoSession().getReplaceRuleBeanDao().deleteInTx(replaceRuleBeans); refreshDataS(); } @@ -179,14 +176,14 @@ public class ReplaceRuleManager { beans.get(i).setSerialNumber(i + 1); } bean.setSerialNumber(0); - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(beans); - GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(bean); + DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(beans); + DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(bean); e.onSuccess(true); }).compose(RxUtils::toSimpleSingle); } private static void refreshDataS() { - replaceRuleBeansEnabled = GreenDaoManager.getDaoSession() + replaceRuleBeansEnabled = DbManager.getDaoSession() .getReplaceRuleBeanDao().queryBuilder() .where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) diff --git a/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java index 1aa9344..9dfcc8e 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java @@ -14,15 +14,13 @@ import io.reactivex.Observable; import io.reactivex.ObservableEmitter; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; -import io.reactivex.annotations.NonNull; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; -import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.entity.thirdsource.BookSource3Bean; import xyz.fycz.myreader.entity.thirdsource.BookSourceBean; import xyz.fycz.myreader.entity.thirdsource.ThirdSourceUtil; import xyz.fycz.myreader.enums.LocalBookSource; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.util.SharedPreUtils; @@ -41,7 +39,7 @@ public class BookSourceManager { public static final int SOURCE_LENGTH = 500; public static List getEnabledBookSource() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.Enable.eq(true)) .orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC") .orderAsc(BookSourceDao.Properties.OrderNum) @@ -49,27 +47,27 @@ public class BookSourceManager { } public static List getAllBookSource() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .orderRaw(getBookSourceSort()) .orderAsc(BookSourceDao.Properties.OrderNum) .list(); } public static List getEnabledBookSourceByOrderNum() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.Enable.eq(true)) .orderAsc(BookSourceDao.Properties.OrderNum) .list(); } public static List getAllBookSourceByOrderNum() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .orderAsc(BookSourceDao.Properties.OrderNum) .list(); } public static List getEnableSourceByGroup(String group) { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.Enable.eq(true)) .where(BookSourceDao.Properties.SourceGroup.like("%" + group + "%")) .orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC") @@ -98,7 +96,7 @@ public class BookSourceManager { */ public static BookSource getBookSourceByUrl(String url) { if (url == null) return getDefaultSource(); - BookSource source = GreenDaoManager.getDaoSession().getBookSourceDao().load(url); + BookSource source = DbManager.getDaoSession().getBookSourceDao().load(url); if (source == null) return getDefaultSource(); return source; } @@ -113,7 +111,7 @@ public class BookSourceManager { public static BookSource getBookSourceByEName(String ename) { if (ename == null) return getDefaultSource(); if ("local".equals(ename)) return getLocalSource(); - BookSource source = GreenDaoManager.getDaoSession().getBookSourceDao(). + BookSource source = DbManager.getDaoSession().getBookSourceDao(). queryBuilder() .where(BookSourceDao.Properties.SourceEName.eq(ename)) .unique(); @@ -163,7 +161,7 @@ public class BookSourceManager { * @return */ public static List getAllLocalSource() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceEName.isNotNull()) .orderAsc(BookSourceDao.Properties.OrderNum) .list(); @@ -175,7 +173,7 @@ public class BookSourceManager { * @return */ public static List getAllNoLocalSource() { - return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + return DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceEName.isNull()) .orderAsc(BookSourceDao.Properties.OrderNum) .list(); @@ -188,12 +186,12 @@ public class BookSourceManager { */ public static void removeBookSource(BookSource source) { if (source == null) return; - GreenDaoManager.getDaoSession().getBookSourceDao().delete(source); + DbManager.getDaoSession().getBookSourceDao().delete(source); } public static void removeBookSources(List sources) { if (sources == null) return; - GreenDaoManager.getDaoSession().getBookSourceDao().deleteInTx(sources); + DbManager.getDaoSession().getBookSourceDao().deleteInTx(sources); } @@ -220,23 +218,23 @@ public class BookSourceManager { if (bookSource.getSourceUrl().endsWith("/")) { bookSource.setSourceUrl(bookSource.getSourceUrl().replaceAll("/+$", "")); } - BookSource temp = GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + BookSource temp = DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())).unique(); if (temp != null) { bookSource.setOrderNum(temp.getOrderNum()); } else { - bookSource.setOrderNum((int) (GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); + bookSource.setOrderNum((int) (DbManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); } - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(bookSource); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(bookSource); return true; } public static Single saveData(BookSource bookSource) { return Single.create((SingleOnSubscribe) emitter -> { if (bookSource.getOrderNum() == 0) { - bookSource.setOrderNum((int) (GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); + bookSource.setOrderNum((int) (DbManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); } - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(bookSource); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(bookSource); emitter.onSuccess(true); }).compose(RxUtils::toSimpleSingle); } @@ -245,10 +243,10 @@ public class BookSourceManager { return Single.create((SingleOnSubscribe) emitter -> { for (BookSource source : sources) { if (source.getOrderNum() == 0) { - source.setOrderNum((int) (GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); + source.setOrderNum((int) (DbManager.getDaoSession().getBookSourceDao().queryBuilder().count() + 1)); } } - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources); + DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources); emitter.onSuccess(true); }).compose(RxUtils::toSimpleSingle); } @@ -260,8 +258,8 @@ public class BookSourceManager { List.get(i).setOrderNum(i + 1); } source.setOrderNum(0); - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(List); - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(source); + DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(List); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(source); e.onSuccess(true); }).compose(RxUtils::toSimpleSingle); } @@ -272,7 +270,7 @@ public class BookSourceManager { + BookSourceDao.Properties.SourceGroup.columnName + " FROM " + BookSourceDao.TABLENAME + " WHERE " + BookSourceDao.Properties.Enable.name + " = 1"; - Cursor cursor = GreenDaoManager.getDaoSession().getDatabase().rawQuery(sql, null); + Cursor cursor = DbManager.getDaoSession().getDatabase().rawQuery(sql, null); if (!cursor.moveToFirst()) return groupList; do { String group = cursor.getString(0); @@ -290,7 +288,7 @@ public class BookSourceManager { public static List getNoLocalGroupList() { List groupList = new ArrayList<>(); String sql = "SELECT DISTINCT " + BookSourceDao.Properties.SourceGroup.columnName + " FROM " + BookSourceDao.TABLENAME; - Cursor cursor = GreenDaoManager.getDaoSession().getDatabase().rawQuery(sql, null); + Cursor cursor = DbManager.getDaoSession().getDatabase().rawQuery(sql, null); if (!cursor.moveToFirst()) return groupList; do { String group = cursor.getString(0); @@ -334,7 +332,7 @@ public class BookSourceManager { if (bookSources != null) { for (BookSource bookSource : bookSources) { if (bookSource.containsGroup("删除")) { - GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())) .buildDelete().executeDeleteWithoutDetachingEntities(); } else { @@ -406,7 +404,7 @@ public class BookSourceManager { public static void initDefaultSources() { Log.d("initDefaultSources", "execute"); - GreenDaoManager.getDaoSession().getBookSourceDao().deleteAll(); + DbManager.getDaoSession().getBookSourceDao().deleteAll(); String searchSource = SharedPreUtils.getInstance().getString(App.getmContext().getString(R.string.searchSource)); boolean isEmpty = StringHelper.isEmpty(searchSource); for (LocalBookSource source : LocalBookSource.values()) { @@ -418,7 +416,7 @@ public class BookSourceManager { source1.setEnable(isEmpty || searchSource.contains(source.toString())); source1.setSourceUrl(ReadCrawlerUtil.getReadCrawlerClz(source.toString())); source1.setOrderNum(0); - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(source1); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(source1); } String referenceSources = FileUtils.readAssertFile(App.getmContext(), "ReferenceSources.json"); diff --git a/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt b/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt index 8839d8f..f6094df 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt @@ -12,7 +12,7 @@ import xyz.fycz.myreader.application.App import xyz.fycz.myreader.application.SysManager import xyz.fycz.myreader.base.observer.MySingleObserver import xyz.fycz.myreader.common.APPCONST -import xyz.fycz.myreader.greendao.GreenDaoManager +import xyz.fycz.myreader.greendao.DbManager import xyz.fycz.myreader.greendao.service.BookService import xyz.fycz.myreader.greendao.service.SearchHistoryService import xyz.fycz.myreader.util.SharedPreUtils @@ -74,28 +74,28 @@ object Backup { .writeText(json) } } - GreenDaoManager.getInstance().session.bookMarkDao.queryBuilder().list().let { + DbManager.getInstance().session.bookMarkDao.queryBuilder().list().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) FileUtils.getFile(backupPath + File.separator + "myBookMark.json") .writeText(json) } } - GreenDaoManager.getInstance().session.bookGroupDao.queryBuilder().list().let { + DbManager.getInstance().session.bookGroupDao.queryBuilder().list().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) FileUtils.getFile(backupPath + File.separator + "myBookGroup.json") .writeText(json) } } - GreenDaoManager.getInstance().session.replaceRuleBeanDao.queryBuilder().list().let { + DbManager.getInstance().session.replaceRuleBeanDao.queryBuilder().list().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) FileUtils.getFile(backupPath + File.separator + "replaceRule.json") .writeText(json) } } - GreenDaoManager.getInstance().session.bookSourceDao.queryBuilder().list().let { + DbManager.getInstance().session.bookSourceDao.queryBuilder().list().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) FileUtils.getFile(backupPath + File.separator + "bookSource.json") diff --git a/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt b/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt index 3f9eea9..01e9f27 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt @@ -12,7 +12,7 @@ import xyz.fycz.myreader.application.SysManager import xyz.fycz.myreader.base.observer.MySingleObserver import xyz.fycz.myreader.entity.ReadStyle import xyz.fycz.myreader.entity.Setting -import xyz.fycz.myreader.greendao.GreenDaoManager +import xyz.fycz.myreader.greendao.DbManager import xyz.fycz.myreader.greendao.entity.* import xyz.fycz.myreader.greendao.entity.rule.BookSource import xyz.fycz.myreader.util.SharedPreUtils @@ -60,7 +60,7 @@ object Restore { if (bookshelf.bookInfoBean.noteUrl != null) { DbHelper.getDaoSession().bookInfoBeanDao.insertOrReplace(bookshelf.bookInfoBean) }*/ - GreenDaoManager.getInstance().session.bookDao.insertOrReplace(bookshelf) + DbManager.getInstance().session.bookDao.insertOrReplace(bookshelf) } } catch (e: Exception) { e.printStackTrace() @@ -69,7 +69,7 @@ object Restore { val file = FileUtils.getFile(path + File.separator + "mySearchHistory.json") val json = file.readText() GSON.fromJsonArray(json)?.let { - GreenDaoManager.getInstance().session.searchHistoryDao.insertOrReplaceInTx(it) + DbManager.getInstance().session.searchHistoryDao.insertOrReplaceInTx(it) } } catch (e: Exception) { e.printStackTrace() @@ -78,7 +78,7 @@ object Restore { val file = FileUtils.getFile(path + File.separator + "myBookMark.json") val json = file.readText() GSON.fromJsonArray(json)?.let { - GreenDaoManager.getInstance().session.bookMarkDao.insertOrReplaceInTx(it) + DbManager.getInstance().session.bookMarkDao.insertOrReplaceInTx(it) } } catch (e: Exception) { e.printStackTrace() @@ -87,7 +87,7 @@ object Restore { val file = FileUtils.getFile(path + File.separator + "myBookGroup.json") val json = file.readText() GSON.fromJsonArray(json)?.let { - GreenDaoManager.getInstance().session.bookGroupDao.insertOrReplaceInTx(it) + DbManager.getInstance().session.bookGroupDao.insertOrReplaceInTx(it) } } catch (e: Exception) { e.printStackTrace() @@ -96,7 +96,7 @@ object Restore { val file = FileUtils.getFile(path + File.separator + "replaceRule.json") val json = file.readText() GSON.fromJsonArray(json)?.let { - GreenDaoManager.getInstance().session.replaceRuleBeanDao.insertOrReplaceInTx(it) + DbManager.getInstance().session.replaceRuleBeanDao.insertOrReplaceInTx(it) } } catch (e: Exception) { e.printStackTrace() @@ -105,7 +105,7 @@ object Restore { val file = FileUtils.getFile(path + File.separator + "bookSource.json") val json = file.readText() GSON.fromJsonArray(json)?.let { - GreenDaoManager.getInstance().session.bookSourceDao.insertOrReplaceInTx(it) + DbManager.getInstance().session.bookSourceDao.insertOrReplaceInTx(it) } } catch (e: Exception) { e.printStackTrace() diff --git a/app/src/main/java/xyz/fycz/myreader/model/third/content/BookContent.java b/app/src/main/java/xyz/fycz/myreader/model/third/content/BookContent.java index 1574a51..c889bd6 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third/content/BookContent.java +++ b/app/src/main/java/xyz/fycz/myreader/model/third/content/BookContent.java @@ -11,7 +11,7 @@ import java.util.regex.Matcher; import io.reactivex.Observable; import xyz.fycz.myreader.entity.StrResponse; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.rule.BookSource; @@ -77,7 +77,7 @@ public class BookContent { if (nextChapterBean != null) { nextChapter = nextChapterBean; } else { - nextChapter = GreenDaoManager.getDaoSession().getChapterDao().queryBuilder() + nextChapter = DbManager.getDaoSession().getChapterDao().queryBuilder() .where(ChapterDao.Properties.Url.eq(chapterBean.getUrl()), ChapterDao.Properties.Number.eq(chapterBean.getNumber() + 1)) .build().unique(); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java index 3e28a13..7b0fff5 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java @@ -397,10 +397,16 @@ public class BookDetailedActivity extends BaseActivity { binding.ih.bookDetailTvAuthor.setText(mBook.getAuthor()); if (StringHelper.isEmpty(mBook.getImgUrl())) { mBook.setImgUrl(""); + } else { + if (!App.isDestroy(this)) { + binding.ih.bookDetailIvCover.load(NetworkUtils.getAbsoluteURL(mReadCrawler.getNameSpace(), mBook.getImgUrl()), mBook.getName(), mBook.getAuthor()); + } } initTagList(); if (StringHelper.isEmpty(mBook.getDesc())) binding.ic.bookDetailTvDesc.setText(""); + else + binding.ic.bookDetailTvDesc.setText(String.format("\t\t\t\t%s", mBook.getDesc())); BookSource source = BookSourceManager.getBookSourceByStr(mBook.getSource()); binding.ih.bookDetailSource.setText(String.format("书源:%s", source.getSourceName())); ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(source); @@ -413,7 +419,7 @@ public class BookDetailedActivity extends BaseActivity { if (!App.isDestroy(BookDetailedActivity.this)) { mHandler.sendMessage(mHandler.obtainMessage(4)); } - if (thirdSource){ + if (thirdSource) { initChapters(false); } } @@ -421,7 +427,7 @@ public class BookDetailedActivity extends BaseActivity { @Override public void onError(Throwable e) { ToastUtils.showError("书籍详情加载失败!"); - if (thirdSource){ + if (thirdSource) { initChapters(false); } if (App.isDebug()) e.printStackTrace(); @@ -500,7 +506,7 @@ public class BookDetailedActivity extends BaseActivity { } } - private Observable saveChapters(List chapters, boolean isChangeSource){ + private Observable saveChapters(List chapters, boolean isChangeSource) { return Observable.create(emitter -> { mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle()); if (isCollected) { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java index 97e72cf..414543c 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java @@ -161,7 +161,7 @@ public class SplashActivity extends BaseActivity { } else { App.getHandler().postDelayed(() -> { binding.tvSkip.setVisibility(View.VISIBLE); - }, 3000); + }, 2000); AdUtils.checkHasAd() .subscribe(new MySingleObserver() { @Override diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookSourceAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookSourceAdapter.java index ff5c509..6baf78e 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookSourceAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookSourceAdapter.java @@ -3,20 +3,12 @@ package xyz.fycz.myreader.ui.adapter; import android.os.AsyncTask; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentActivity; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import xyz.fycz.myreader.base.adapter.BaseListAdapter; import xyz.fycz.myreader.base.adapter.IViewHolder; -import xyz.fycz.myreader.greendao.GreenDaoManager; -import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.ui.adapter.helper.ItemTouchCallback; import xyz.fycz.myreader.ui.adapter.holder.BookSourceHolder; @@ -46,7 +38,7 @@ public class BookSourceAdapter extends BaseSourceAdapter { for (int i = 1; i <= mList.size(); i++) { mList.get(i - 1).setOrderNum(i); } - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mList); + DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mList); }); return true; } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java index 1092915..28037ba 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java @@ -7,7 +7,7 @@ import java.util.HashMap; import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.adapter.ViewHolderImpl; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.util.ToastUtils; @@ -46,12 +46,12 @@ public class LocalSourceHolder extends ViewHolderImpl { tvEnable.setOnClickListener(v -> { data.setEnable(true); banOrUse(data); - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(data); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(data); }); tvDisable.setOnClickListener(v -> { data.setEnable(false); banOrUse(data); - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(data); + DbManager.getDaoSession().getBookSourceDao().insertOrReplace(data); }); tvCheck.setOnClickListener(v -> ToastUtils.showInfo("校验功能即将上线")); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java index 8ce448b..2b55bc7 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java @@ -89,6 +89,8 @@ public class SearchBookHolder extends ViewHolderImpl { if (!App.isDestroy((Activity) getContext())) { ivBookImg.load(NetworkUtils.getAbsoluteURL(rc.getNameSpace(), data.getImgUrl()), data.getName(), data.getAuthor()); } + }else { + data.setImgUrl(""); } KeyWordUtils.setKeyWord(tvBookName, data.getName(), keyWord); if (!StringHelper.isEmpty(data.getAuthor())) { @@ -97,9 +99,13 @@ public class SearchBookHolder extends ViewHolderImpl { initTagList(data); if (!StringHelper.isEmpty(data.getLastChapter())) { tvNewestChapter.setText(getContext().getString(R.string.newest_chapter, data.getLastChapter())); + }else { + data.setLastChapter(""); } if (!StringHelper.isEmpty(data.getDesc())) { tvDesc.setText(String.format("简介:%s", data.getDesc())); + }else { + data.setDesc(""); } tvSource.setText(getContext().getString(R.string.source_title_num, source.getSourceName(), bookCount)); App.getHandler().postDelayed(() -> { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java index 98f16d7..10b0ed9 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java @@ -2,7 +2,6 @@ package xyz.fycz.myreader.ui.fragment; import android.annotation.SuppressLint; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.Gravity; @@ -31,7 +30,7 @@ import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.FragmentImportSourceBinding; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; @@ -211,7 +210,7 @@ public class DIYSourceFragment extends BaseFragment { List sourceBeanList; if (isSearch) { if (sourceActivity.getSearchView().getQuery().toString().equals("enabled")) { - sourceBeanList = GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + sourceBeanList = DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceEName.isNull()) .where(BookSourceDao.Properties.Enable.eq(1)) .orderRaw(BookSourceManager.getBookSourceSort()) @@ -219,7 +218,7 @@ public class DIYSourceFragment extends BaseFragment { .list(); } else { String term = "%" + sourceActivity.getSearchView().getQuery() + "%"; - sourceBeanList = GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + sourceBeanList = DbManager.getDaoSession().getBookSourceDao().queryBuilder() .where(BookSourceDao.Properties.SourceEName.isNull()) .whereOr(BookSourceDao.Properties.SourceName.like(term), BookSourceDao.Properties.SourceGroup.like(term), @@ -385,7 +384,7 @@ public class DIYSourceFragment extends BaseFragment { for (BookSource source : mBookSources) { source.setEnable(!source.getEnable()); } - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mBookSources); + DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mBookSources); mAdapter.notifyDataSetChanged(); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java index 233af9f..a9e2c94 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java @@ -16,7 +16,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.databinding.FragmentLocalSourceBinding; -import xyz.fycz.myreader.greendao.GreenDaoManager; +import xyz.fycz.myreader.greendao.DbManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.activity.BookSourceActivity; @@ -105,7 +105,7 @@ public class LocalSourceFragment extends BaseFragment { source.setEnable(isEnable); } Single.create((SingleOnSubscribe) emitter -> { - GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources); + DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources); emitter.onSuccess(true); }).compose(RxUtils::toSimpleSingle) .subscribe(new MySingleObserver() { diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java index 427b4f8..456713e 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java @@ -123,9 +123,9 @@ public class AdUtils { public static void initAd() { if (!hasInitAd) { hasInitAd = true; - DdSdkHelper.init("", "", "", - "", "", - "", "", + DdSdkHelper.init("1234", "216", "51716a16fbdf50905704b6575b1b3b60", + "142364", "35ce0efe5f3cc960b116db227498e238", + "8167", "85bd159309c3da1b", App.getApplication(), App.isDebug()); } } diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java index e10d679..a7bed32 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java @@ -19,6 +19,8 @@ import io.reactivex.Observable; import okhttp3.*; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.entity.StrResponse; +import xyz.fycz.myreader.greendao.DbManager; +import xyz.fycz.myreader.greendao.entity.CookieBean; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.model.third.analyzeRule.AnalyzeUrl; @@ -216,7 +218,7 @@ public class OkHttpUtils { WebView webView = new WebView(App.getmContext()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setUserAgentString(analyzeUrl.getHeaderMap().get("User-Agent")); - //CookieManager cookieManager = CookieManager.getInstance(); + CookieManager cookieManager = CookieManager.getInstance(); Runnable retryRunnable = new Runnable() { @Override public void run() { @@ -245,8 +247,8 @@ public class OkHttpUtils { webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { - /*DbHelper.getDaoSession().getCookieBeanDao() - .insertOrReplace(new CookieBean(tag, cookieManager.getCookie(webView.getUrl())));*/ + DbManager.getDaoSession().getCookieBeanDao() + .insertOrReplace(new CookieBean(tag, cookieManager.getCookie(webView.getUrl()))); handler.postDelayed(retryRunnable, 1000); } }); @@ -264,6 +266,28 @@ public class OkHttpUtils { }); } + public static Observable setCookie(StrResponse response, String tag) { + return Observable.create(e -> { + if (!response.getResponse().headers("Set-Cookie").isEmpty()) { + StringBuilder cookieBuilder = new StringBuilder(); + for (String s : response.getResponse().headers("Set-Cookie")) { + String[] x = s.split(";"); + for (String y : x) { + if (!TextUtils.isEmpty(y)) { + cookieBuilder.append(y).append(";"); + } + } + } + String cookie = cookieBuilder.toString(); + if (!TextUtils.isEmpty(cookie)) { + DbManager.getDaoSession().getCookieBeanDao().insertOrReplace(new CookieBean(tag, cookie)); + } + } + e.onNext(response); + e.onComplete(); + }); + } + private static class Web { private String content; private String js = "document.documentElement.outerHTML"; diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java b/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java index d006181..1dec9fd 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java @@ -40,7 +40,7 @@ public class CommonApi { */ public static Observable> getBookChapters(Book book, final ReadCrawler rc) { if (rc instanceof ThirdCrawler) { - return getBookChaptersByTC(book, (ThirdCrawler) rc); + return ThirdSourceApi.getBookChaptersByTC(book, (ThirdCrawler) rc); } String url = book.getChapterUrl(); String charset = rc.getCharset(); @@ -52,29 +52,6 @@ public class CommonApi { }); } - private static Observable> getBookChaptersByTC(Book book, ThirdCrawler rc) { - BookSource source = rc.getSource(); - BookChapterList bookChapterList = new BookChapterList(source.getSourceUrl(), source, true); - /*if (!TextUtils.isEmpty(bookShelfBean.getBookInfoBean().getChapterListHtml())) { - return bookChapterList.analyzeChapterList(bookShelfBean.getBookInfoBean().getChapterListHtml(), bookShelfBean, headerMap); - }*/ - try { - AnalyzeUrl analyzeUrl = new AnalyzeUrl(book.getChapterUrl(), null, book.getInfoUrl()); - return OkHttpUtils.getStrResponse(analyzeUrl) - //.flatMap(response -> setCookie(response, tag)) - .flatMap(response -> bookChapterList.analyzeChapterList(response.body(), book, null)) - .flatMap(chapters -> Observable.create(emitter -> { - for (int i = 0; i < chapters.size(); i++) { - Chapter chapter = chapters.get(i); - chapter.setNumber(i); - } - emitter.onNext(chapters); - emitter.onComplete(); - })); - } catch (Exception e) { - return Observable.error(new Throwable(String.format("url错误:%s", book.getChapterUrl()))); - } - } /** * 获取章节正文 @@ -83,7 +60,7 @@ public class CommonApi { public static Observable getChapterContent(Chapter chapter, Book book, final ReadCrawler rc) { if (rc instanceof ThirdCrawler) { - return getChapterContentByTC(chapter, book, (ThirdCrawler) rc); + return ThirdSourceApi.getChapterContentByTC(chapter, book, (ThirdCrawler) rc); } String url = chapter.getUrl(); String charset = rc.getCharset(); @@ -95,41 +72,6 @@ public class CommonApi { }); } - private static Observable getChapterContentByTC(Chapter chapter, Book book, ThirdCrawler rc) { - BookSource source = rc.getSource(); - BookContent bookContent = new BookContent(source.getSourceUrl(), source); - /*if (Objects.equals(chapterBean.getDurChapterUrl(), bookShelfBean.getBookInfoBean().getChapterUrl()) - && !TextUtils.isEmpty(bookShelfBean.getBookInfoBean().getChapterListHtml())) { - return bookContent.analyzeBookContent(bookShelfBean.getBookInfoBean().getChapterListHtml(), chapterBean, nextChapterBean, bookShelfBean, headerMap); - }*/ - try { - AnalyzeUrl analyzeUrl = new AnalyzeUrl(chapter.getUrl(), null, book.getChapterUrl()); - String contentRule = source.getContentRule().getContent(); - if (contentRule.startsWith("$") && !contentRule.startsWith("$.")) { - //动态网页第一个js放到webView里执行 - contentRule = contentRule.substring(1); - String js = null; - Matcher jsMatcher = JS_PATTERN.matcher(contentRule); - if (jsMatcher.find()) { - js = jsMatcher.group(); - if (js.startsWith("")) { - js = js.substring(4, js.lastIndexOf("<")); - } else { - js = js.substring(4); - } - } - return OkHttpUtils.getAjaxString(analyzeUrl, source.getSourceUrl(), js) - .flatMap(response -> bookContent.analyzeBookContent(response, chapter, null, book, null)); - } else { - return OkHttpUtils.getStrResponse(analyzeUrl) - //.flatMap(response -> setCookie(response, tag)) - .flatMap(response -> bookContent.analyzeBookContent(response, chapter, null, book, null)); - } - } catch (Exception e) { - return Observable.error(new Throwable(String.format("url错误:%s", chapter.getUrl()))); - } - } - /** * 搜索小说 @@ -138,7 +80,7 @@ public class CommonApi { */ public static Observable> search(String key, final ReadCrawler rc) { if (rc instanceof ThirdCrawler) { - return searchByTC(key, (ThirdCrawler) rc); + return ThirdSourceApi.searchByTC(key, (ThirdCrawler) rc); } String charset = "utf-8"; if (rc instanceof TianLaiReadCrawler) { @@ -180,28 +122,7 @@ public class CommonApi { return url.replace("{key}", key); } - /** - * 第三方书源搜索 - * - * @param key - * @param rc - * @return - */ - public static Observable> searchByTC(String key, final ThirdCrawler rc) { - try { - BookSource source = rc.getSource(); - AnalyzeUrl analyzeUrl = new AnalyzeUrl(source.getSearchRule().getSearchUrl(), - key, 1, null, source.getSourceUrl()); - BookList bookList = new BookList(source.getSourceUrl(), source.getSourceName(), source, false); - return OkHttpUtils.getStrResponse(analyzeUrl).flatMap(bookList::analyzeSearchBook) - .flatMap((Function, ObservableSource>>) books -> Observable.create((ObservableOnSubscribe>) emitter -> { - emitter.onNext(rc.getBooks(books)); - emitter.onComplete(); - })); - } catch (Exception e) { - return Observable.error(e); - } - } + /** * 获取小说详细信息 @@ -210,7 +131,7 @@ public class CommonApi { */ public static Observable getBookInfo(final Book book, final BookInfoCrawler bic) { if (bic instanceof ThirdCrawler){ - return getBookInfoByTC(book, (ThirdCrawler) bic); + return ThirdSourceApi.getBookInfoByTC(book, (ThirdCrawler) bic); } String url; url = book.getInfoUrl(); @@ -223,21 +144,7 @@ public class CommonApi { }); } - private static Observable getBookInfoByTC(Book book, ThirdCrawler rc) { - BookSource source = rc.getSource(); - BookInfo bookInfo = new BookInfo(source.getSourceUrl(), source.getSourceName(), source); - /*if (!TextUtils.isEmpty(book.getBookInfoBean().getBookInfoHtml())) { - return bookInfo.analyzeBookInfo(book.getBookInfoBean().getBookInfoHtml(), bookShelfBean); - }*/ - try { - AnalyzeUrl analyzeUrl = new AnalyzeUrl(book.getInfoUrl(), null, source.getSourceUrl()); - return OkHttpUtils.getStrResponse(analyzeUrl) - //.flatMap(response -> setCookie(response, tag)) - .flatMap(response -> bookInfo.analyzeBookInfo(response.body(), book)); - } catch (Exception e) { - return Observable.error(new Throwable(String.format("url错误:%s", book.getInfoUrl()))); - } - } + /** * 通过api获取蓝奏云可下载直链 diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java b/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java new file mode 100644 index 0000000..84b8a07 --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java @@ -0,0 +1,143 @@ +package xyz.fycz.myreader.webapi; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; + +import io.reactivex.Observable; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.ObservableSource; +import io.reactivex.functions.Function; +import xyz.fycz.myreader.entity.SearchBookBean; +import xyz.fycz.myreader.greendao.DbManager; +import xyz.fycz.myreader.greendao.entity.Book; +import xyz.fycz.myreader.greendao.entity.Chapter; +import xyz.fycz.myreader.greendao.entity.CookieBean; +import xyz.fycz.myreader.greendao.entity.rule.BookSource; +import xyz.fycz.myreader.model.mulvalmap.ConMVMap; +import xyz.fycz.myreader.model.third.analyzeRule.AnalyzeUrl; +import xyz.fycz.myreader.model.third.content.BookChapterList; +import xyz.fycz.myreader.model.third.content.BookContent; +import xyz.fycz.myreader.model.third.content.BookInfo; +import xyz.fycz.myreader.model.third.content.BookList; +import xyz.fycz.myreader.util.utils.OkHttpUtils; +import xyz.fycz.myreader.webapi.crawler.source.ThirdCrawler; + +import static xyz.fycz.myreader.common.APPCONST.JS_PATTERN; + +/** + * @author fengyue + * @date 2021/5/15 9:56 + */ +public class ThirdSourceApi { + + /** + * 第三方书源搜索 + * + * @param key + * @param rc + * @return + */ + public static Observable> searchByTC(String key, final ThirdCrawler rc) { + try { + BookSource source = rc.getSource(); + AnalyzeUrl analyzeUrl = new AnalyzeUrl(source.getSearchRule().getSearchUrl(), + key, 1, getCookies(source), source.getSourceUrl()); + BookList bookList = new BookList(source.getSourceUrl(), source.getSourceName(), source, false); + return OkHttpUtils.getStrResponse(analyzeUrl).flatMap(bookList::analyzeSearchBook) + .flatMap((Function, ObservableSource>>) books -> Observable.create((ObservableOnSubscribe>) emitter -> { + emitter.onNext(rc.getBooks(books)); + emitter.onComplete(); + })); + } catch (Exception e) { + return Observable.error(e); + } + } + + protected static Observable getBookInfoByTC(Book book, ThirdCrawler rc) { + BookSource source = rc.getSource(); + BookInfo bookInfo = new BookInfo(source.getSourceUrl(), source.getSourceName(), source); + /*if (!TextUtils.isEmpty(book.getBookInfoBean().getBookInfoHtml())) { + return bookInfo.analyzeBookInfo(book.getBookInfoBean().getBookInfoHtml(), bookShelfBean); + }*/ + try { + AnalyzeUrl analyzeUrl = new AnalyzeUrl(book.getInfoUrl(), getCookies(source), source.getSourceUrl()); + return OkHttpUtils.getStrResponse(analyzeUrl) + .flatMap(response -> OkHttpUtils.setCookie(response, source.getSourceUrl())) + .flatMap(response -> bookInfo.analyzeBookInfo(response.body(), book)); + } catch (Exception e) { + return Observable.error(new Throwable(String.format("url错误:%s", book.getInfoUrl()))); + } + } + + protected static Observable> getBookChaptersByTC(Book book, ThirdCrawler rc) { + BookSource source = rc.getSource(); + BookChapterList bookChapterList = new BookChapterList(source.getSourceUrl(), source, true); + /*if (!TextUtils.isEmpty(bookShelfBean.getBookInfoBean().getChapterListHtml())) { + return bookChapterList.analyzeChapterList(bookShelfBean.getBookInfoBean().getChapterListHtml(), bookShelfBean, headerMap); + }*/ + try { + AnalyzeUrl analyzeUrl = new AnalyzeUrl(book.getChapterUrl(), getCookies(source), book.getInfoUrl()); + return OkHttpUtils.getStrResponse(analyzeUrl) + .flatMap(response -> OkHttpUtils.setCookie(response, source.getSourceUrl())) + .flatMap(response -> bookChapterList.analyzeChapterList(response.body(), book, getCookies(source))) + .flatMap(chapters -> Observable.create(emitter -> { + for (int i = 0; i < chapters.size(); i++) { + Chapter chapter = chapters.get(i); + chapter.setNumber(i); + } + emitter.onNext(chapters); + emitter.onComplete(); + })); + } catch (Exception e) { + return Observable.error(new Throwable(String.format("url错误:%s", book.getChapterUrl()))); + } + } + + protected static Observable getChapterContentByTC(Chapter chapter, Book book, ThirdCrawler rc) { + BookSource source = rc.getSource(); + BookContent bookContent = new BookContent(source.getSourceUrl(), source); + /*if (Objects.equals(chapterBean.getDurChapterUrl(), bookShelfBean.getBookInfoBean().getChapterUrl()) + && !TextUtils.isEmpty(bookShelfBean.getBookInfoBean().getChapterListHtml())) { + return bookContent.analyzeBookContent(bookShelfBean.getBookInfoBean().getChapterListHtml(), chapterBean, nextChapterBean, bookShelfBean, headerMap); + }*/ + try { + AnalyzeUrl analyzeUrl = new AnalyzeUrl(chapter.getUrl(), getCookies(source), book.getChapterUrl()); + String contentRule = source.getContentRule().getContent(); + if (contentRule.startsWith("$") && !contentRule.startsWith("$.")) { + //动态网页第一个js放到webView里执行 + contentRule = contentRule.substring(1); + String js = null; + Matcher jsMatcher = JS_PATTERN.matcher(contentRule); + if (jsMatcher.find()) { + js = jsMatcher.group(); + if (js.startsWith("")) { + js = js.substring(4, js.lastIndexOf("<")); + } else { + js = js.substring(4); + } + } + return OkHttpUtils.getAjaxString(analyzeUrl, source.getSourceUrl(), js) + .flatMap(response -> bookContent.analyzeBookContent(response, chapter, null, book, getCookies(source))); + } else { + return OkHttpUtils.getStrResponse(analyzeUrl) + .flatMap(response -> OkHttpUtils.setCookie(response, source.getSourceUrl())) + .flatMap(response -> bookContent.analyzeBookContent(response, chapter, null, book, getCookies(source))); + } + } catch (Exception e) { + return Observable.error(new Throwable(String.format("url错误:%s", chapter.getUrl()))); + } + } + + private static Map getCookies(BookSource bookSource){ + Map cookieMap = new HashMap<>(); + if (bookSource != null){ + CookieBean cookie = DbManager.getDaoSession().getCookieBeanDao().load(bookSource.getSourceUrl()); + if (cookie != null) { + cookieMap.put("Cookie", cookie.getCookie()); + } + } + return cookieMap; + } +} diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseReadCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseReadCrawler.java index f4fabd6..2f462b6 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseReadCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseReadCrawler.java @@ -1,9 +1,12 @@ package xyz.fycz.myreader.webapi.crawler.base; import java.util.ArrayList; +import java.util.List; import java.util.Map; +import io.reactivex.Observable; import xyz.fycz.myreader.entity.SearchBookBean; +import xyz.fycz.myreader.entity.StrResponse; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.model.mulvalmap.ConMVMap; @@ -33,4 +36,19 @@ public abstract class BaseReadCrawler implements ReadCrawler { public String getContentFormHtml(String html) { return null; } + + @Override + public Observable> getBooksFromStrResponse(StrResponse response) { + return null; + } + + @Override + public Observable> getChaptersFromStrResponse(StrResponse response) { + return null; + } + + @Override + public Observable getContentFormStrResponse(StrResponse response) { + return null; + } } diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/ReadCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/ReadCrawler.java index 44e2305..2b6dfad 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/ReadCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/ReadCrawler.java @@ -1,11 +1,14 @@ package xyz.fycz.myreader.webapi.crawler.base; +import io.reactivex.Observable; import xyz.fycz.myreader.entity.SearchBookBean; +import xyz.fycz.myreader.entity.StrResponse; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.model.mulvalmap.ConMVMap; import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -20,7 +23,14 @@ public interface ReadCrawler { String getNameSpace(); // 书源主页地址 Boolean isPost(); // 是否以post请求搜索 Map getHeaders();// 自定义请求头,可添加cookie等 + + // 旧版本 ConMVMap getBooksFromSearchHtml(String html); // 搜索书籍规则 ArrayList getChaptersFromHtml(String html); // 获取书籍章节列表规则 String getContentFormHtml(String html); // 获取书籍内容规则 + + // 新版本 + Observable> getBooksFromStrResponse(StrResponse response); // 搜索书籍规则 + Observable> getChaptersFromStrResponse(StrResponse response); // 获取书籍章节列表规则 + Observable getContentFormStrResponse(StrResponse response); // 获取书籍内容规则 } diff --git a/app/src/main/res/menu/menu_source_edit.xml b/app/src/main/res/menu/menu_source_edit.xml index 1c9c551..8b333cd 100644 --- a/app/src/main/res/menu/menu_source_edit.xml +++ b/app/src/main/res/menu/menu_source_edit.xml @@ -1,25 +1,36 @@ - + android:title="@string/save" + app:showAsAction="always" /> - + android:title="@string/debug" + app:showAsAction="always"> - - - - + + + + + + \ No newline at end of file