优化书源结构

pull/5/head
fengyuecanzhu 4 years ago
parent acd099f97f
commit 6f22ed7185
  1. 2
      app/build.gradle
  2. 1
      app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java
  3. 10
      app/src/main/java/xyz/fycz/myreader/greendao/DbManager.java
  4. 70
      app/src/main/java/xyz/fycz/myreader/greendao/entity/CookieBean.java
  5. 22
      app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java
  6. 12
      app/src/main/java/xyz/fycz/myreader/greendao/service/BaseService.java
  7. 10
      app/src/main/java/xyz/fycz/myreader/greendao/service/BookGroupService.java
  8. 23
      app/src/main/java/xyz/fycz/myreader/greendao/service/BookMarkService.java
  9. 20
      app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java
  10. 11
      app/src/main/java/xyz/fycz/myreader/greendao/service/ChapterService.java
  11. 4
      app/src/main/java/xyz/fycz/myreader/greendao/service/SearchHistoryService.java
  12. 2
      app/src/main/java/xyz/fycz/myreader/greendao/util/MySQLiteOpenHelper.java
  13. 35
      app/src/main/java/xyz/fycz/myreader/model/ReplaceRuleManager.java
  14. 54
      app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java
  15. 10
      app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt
  16. 14
      app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt
  17. 4
      app/src/main/java/xyz/fycz/myreader/model/third/content/BookContent.java
  18. 12
      app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java
  19. 2
      app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
  20. 12
      app/src/main/java/xyz/fycz/myreader/ui/adapter/BookSourceAdapter.java
  21. 6
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/LocalSourceHolder.java
  22. 6
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SearchBookHolder.java
  23. 9
      app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java
  24. 4
      app/src/main/java/xyz/fycz/myreader/ui/fragment/LocalSourceFragment.java
  25. 6
      app/src/main/java/xyz/fycz/myreader/util/utils/AdUtils.java
  26. 30
      app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java
  27. 105
      app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java
  28. 143
      app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java
  29. 18
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseReadCrawler.java
  30. 10
      app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/ReadCrawler.java
  31. 39
      app/src/main/res/menu/menu_source_edit.xml

@ -208,7 +208,7 @@ dependencies {
} }
greendao { greendao {
schemaVersion 26 schemaVersion 27
daoPackage 'xyz.fycz.myreader.greendao.gen' daoPackage 'xyz.fycz.myreader.greendao.gen'
// targetGenDir 'src/main/java' // targetGenDir 'src/main/java'
} }

@ -22,6 +22,7 @@ public class ThirdSourceUtil {
bookSource.setSourceName(bean.getBookSourceName()); bookSource.setSourceName(bean.getBookSourceName());
bookSource.setSourceGroup(bean.getBookSourceGroup()); bookSource.setSourceGroup(bean.getBookSourceGroup());
bookSource.setSourceType(APPCONST.THIRD_SOURCE); bookSource.setSourceType(APPCONST.THIRD_SOURCE);
bookSource.setLoginUrl(bean.getLoginUrl());
bookSource.setLastUpdateTime(bean.getLastUpdateTime()); bookSource.setLastUpdateTime(bean.getLastUpdateTime());
bookSource.setOrderNum(bean.getSerialNumber()); bookSource.setOrderNum(bean.getSerialNumber());
bookSource.setWeight(bean.getWeight()); bookSource.setWeight(bean.getWeight());

@ -8,21 +8,21 @@ import xyz.fycz.myreader.greendao.util.MySQLiteOpenHelper;
public class GreenDaoManager { public class DbManager {
private static GreenDaoManager instance; private static DbManager instance;
private static DaoMaster daoMaster; private static DaoMaster daoMaster;
private DaoSession mDaoSession; private DaoSession mDaoSession;
private static MySQLiteOpenHelper mySQLiteOpenHelper; private static MySQLiteOpenHelper mySQLiteOpenHelper;
public static GreenDaoManager getInstance() { public static DbManager getInstance() {
if (instance == null) { if (instance == null) {
instance = new GreenDaoManager(); instance = new DbManager();
} }
return instance; return instance;
} }
public GreenDaoManager(){ public DbManager(){
mySQLiteOpenHelper = new MySQLiteOpenHelper(App.getmContext(), "read" , null); mySQLiteOpenHelper = new MySQLiteOpenHelper(App.getmContext(), "read" , null);
daoMaster = new DaoMaster(mySQLiteOpenHelper.getWritableDatabase()); daoMaster = new DaoMaster(mySQLiteOpenHelper.getWritableDatabase());
mDaoSession = daoMaster.newSession(); mDaoSession = daoMaster.newSession();

@ -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<CookieBean> CREATOR = new Creator<CookieBean>() {
@Override
public CookieBean createFromParcel(Parcel in) {
return new CookieBean(in);
}
@Override
public CookieBean[] newArray(int size) {
return new CookieBean[size];
}
};
}

@ -43,6 +43,7 @@ public class BookSource implements Parcelable, Cloneable {
private String sourceCharset; private String sourceCharset;
private String sourceType; private String sourceType;
private String sourceHeaders; private String sourceHeaders;
private String loginUrl;
private String sourceComment; private String sourceComment;
private Long lastUpdateTime; private Long lastUpdateTime;
@ -72,11 +73,12 @@ public class BookSource implements Parcelable, Cloneable {
@Convert(converter = FindRuleConvert.class, columnType = String.class) @Convert(converter = FindRuleConvert.class, columnType = String.class)
private FindRule findRule; private FindRule findRule;
@Generated(hash = 1082429073) @Generated(hash = 277037260)
public BookSource(String sourceUrl, String sourceEName, String sourceName, String sourceGroup, public BookSource(String sourceUrl, String sourceEName, String sourceName, String sourceGroup,
String sourceCharset, String sourceType, String sourceHeaders, String sourceComment, String sourceCharset, String sourceType, String sourceHeaders, String loginUrl,
Long lastUpdateTime, int orderNum, int weight, boolean enable, SearchRule searchRule, String sourceComment, Long lastUpdateTime, int orderNum, int weight, boolean enable,
InfoRule infoRule, TocRule tocRule, ContentRule contentRule, FindRule findRule) { SearchRule searchRule, InfoRule infoRule, TocRule tocRule, ContentRule contentRule,
FindRule findRule) {
this.sourceUrl = sourceUrl; this.sourceUrl = sourceUrl;
this.sourceEName = sourceEName; this.sourceEName = sourceEName;
this.sourceName = sourceName; this.sourceName = sourceName;
@ -84,6 +86,7 @@ public class BookSource implements Parcelable, Cloneable {
this.sourceCharset = sourceCharset; this.sourceCharset = sourceCharset;
this.sourceType = sourceType; this.sourceType = sourceType;
this.sourceHeaders = sourceHeaders; this.sourceHeaders = sourceHeaders;
this.loginUrl = loginUrl;
this.sourceComment = sourceComment; this.sourceComment = sourceComment;
this.lastUpdateTime = lastUpdateTime; this.lastUpdateTime = lastUpdateTime;
this.orderNum = orderNum; this.orderNum = orderNum;
@ -109,6 +112,7 @@ public class BookSource implements Parcelable, Cloneable {
sourceCharset = in.readString(); sourceCharset = in.readString();
sourceType = in.readString(); sourceType = in.readString();
sourceHeaders = in.readString(); sourceHeaders = in.readString();
loginUrl = in.readString();
sourceComment = in.readString(); sourceComment = in.readString();
if (in.readByte() == 0) { if (in.readByte() == 0) {
lastUpdateTime = null; lastUpdateTime = null;
@ -134,6 +138,7 @@ public class BookSource implements Parcelable, Cloneable {
dest.writeString(sourceCharset); dest.writeString(sourceCharset);
dest.writeString(sourceType); dest.writeString(sourceType);
dest.writeString(sourceHeaders); dest.writeString(sourceHeaders);
dest.writeString(loginUrl);
dest.writeString(sourceComment); dest.writeString(sourceComment);
if (lastUpdateTime == null) { if (lastUpdateTime == null) {
dest.writeByte((byte) 0); dest.writeByte((byte) 0);
@ -181,6 +186,7 @@ public class BookSource implements Parcelable, Cloneable {
stringEquals(sourceCharset, source.sourceCharset) && stringEquals(sourceCharset, source.sourceCharset) &&
stringEquals(sourceType, source.sourceType) && stringEquals(sourceType, source.sourceType) &&
stringEquals(sourceHeaders, source.sourceHeaders) && stringEquals(sourceHeaders, source.sourceHeaders) &&
stringEquals(loginUrl, source.loginUrl) &&
stringEquals(sourceComment, source.sourceComment) && stringEquals(sourceComment, source.sourceComment) &&
Objects.equals(searchRule, source.searchRule) && Objects.equals(searchRule, source.searchRule) &&
Objects.equals(infoRule, source.infoRule) && Objects.equals(infoRule, source.infoRule) &&
@ -383,4 +389,12 @@ public class BookSource implements Parcelable, Cloneable {
public void setSourceHeaders(String sourceHeaders) { public void setSourceHeaders(String sourceHeaders) {
this.sourceHeaders = sourceHeaders; this.sourceHeaders = sourceHeaders;
} }
public String getLoginUrl() {
return this.loginUrl;
}
public void setLoginUrl(String loginUrl) {
this.loginUrl = loginUrl;
}
} }

@ -3,23 +3,23 @@ package xyz.fycz.myreader.greendao.service;
import android.database.Cursor; import android.database.Cursor;
import xyz.fycz.myreader.greendao.gen.DaoSession; import xyz.fycz.myreader.greendao.gen.DaoSession;
import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.DbManager;
public class BaseService { public class BaseService {
public void addEntity(Object entity){ public void addEntity(Object entity){
DaoSession daoSession = GreenDaoManager.getInstance().getSession(); DaoSession daoSession = DbManager.getInstance().getSession();
daoSession.insert(entity); daoSession.insert(entity);
} }
public void updateEntity(Object entity){ public void updateEntity(Object entity){
DaoSession daoSession = GreenDaoManager.getInstance().getSession(); DaoSession daoSession = DbManager.getInstance().getSession();
daoSession.update(entity); daoSession.update(entity);
} }
public void deleteEntity(Object entity){ public void deleteEntity(Object entity){
DaoSession daoSession = GreenDaoManager.getInstance().getSession(); DaoSession daoSession = DbManager.getInstance().getSession();
daoSession.delete(entity); daoSession.delete(entity);
} }
@ -33,7 +33,7 @@ public class BaseService {
Cursor cursor = null; Cursor cursor = null;
try { try {
DaoSession daoSession = GreenDaoManager.getInstance().getSession(); DaoSession daoSession = DbManager.getInstance().getSession();
cursor = daoSession.getDatabase().rawQuery(sql, selectionArgs); cursor = daoSession.getDatabase().rawQuery(sql, selectionArgs);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -48,7 +48,7 @@ public class BaseService {
* @param selectionArgs * @param selectionArgs
*/ */
public void rawQuery(String sql, String[] 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); Cursor cursor = daoSession.getDatabase().rawQuery(sql, selectionArgs);
} }

@ -2,7 +2,7 @@ package xyz.fycz.myreader.greendao.service;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; 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.entity.BookGroup;
import xyz.fycz.myreader.greendao.gen.BookGroupDao; import xyz.fycz.myreader.greendao.gen.BookGroupDao;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
@ -33,7 +33,7 @@ public class BookGroupService extends BaseService{
* @return * @return
*/ */
public List<BookGroup> getAllGroups(){ public List<BookGroup> getAllGroups(){
return GreenDaoManager.getInstance().getSession().getBookGroupDao() return DbManager.getInstance().getSession().getBookGroupDao()
.queryBuilder() .queryBuilder()
.orderAsc(BookGroupDao.Properties.Num) .orderAsc(BookGroupDao.Properties.Num)
.list(); .list();
@ -45,7 +45,7 @@ public class BookGroupService extends BaseService{
* @return * @return
*/ */
public BookGroup getGroupById(String groupId){ public BookGroup getGroupById(String groupId){
return GreenDaoManager.getInstance().getSession().getBookGroupDao() return DbManager.getInstance().getSession().getBookGroupDao()
.queryBuilder() .queryBuilder()
.where(BookGroupDao.Properties.Id.eq(groupId)) .where(BookGroupDao.Properties.Id.eq(groupId))
.unique(); .unique();
@ -70,7 +70,7 @@ public class BookGroupService extends BaseService{
} }
public void deleteGroupById(String id){ public void deleteGroupById(String id){
GreenDaoManager.getInstance().getSession().getBookGroupDao().deleteByKey(id); DbManager.getInstance().getSession().getBookGroupDao().deleteByKey(id);
} }
public void createPrivateGroup(){ public void createPrivateGroup(){
@ -97,7 +97,7 @@ public class BookGroupService extends BaseService{
} }
private int countBookGroup(){ private int countBookGroup(){
return (int) GreenDaoManager.getInstance().getSession().getBookGroupDao() return (int) DbManager.getInstance().getSession().getBookGroupDao()
.queryBuilder() .queryBuilder()
.count(); .count();
} }

@ -1,20 +1,11 @@
package xyz.fycz.myreader.greendao.service; package xyz.fycz.myreader.greendao.service;
import android.database.Cursor; import xyz.fycz.myreader.greendao.DbManager;
import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.BookMark; 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.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 xyz.fycz.myreader.util.StringHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@ -38,7 +29,7 @@ public class BookMarkService extends BaseService {
* @return * @return
*/ */
public BookMark getBookById(String id) { public BookMark getBookById(String id) {
BookMarkDao bookMarkDao = GreenDaoManager.getInstance().getSession().getBookMarkDao(); BookMarkDao bookMarkDao = DbManager.getInstance().getSession().getBookMarkDao();
return bookMarkDao.load(id); return bookMarkDao.load(id);
} }
@ -48,7 +39,7 @@ public class BookMarkService extends BaseService {
* @return * @return
*/ */
public BookMark findBookMarkByTitle(String title){ public BookMark findBookMarkByTitle(String title){
return GreenDaoManager.getInstance().getSession().getBookMarkDao() return DbManager.getInstance().getSession().getBookMarkDao()
.queryBuilder() .queryBuilder()
.where(BookMarkDao.Properties.Title.eq(title)) .where(BookMarkDao.Properties.Title.eq(title))
.unique(); .unique();
@ -62,7 +53,7 @@ public class BookMarkService extends BaseService {
if (bookId == null) { if (bookId == null) {
return new ArrayList<>(); return new ArrayList<>();
} }
return GreenDaoManager.getInstance().getSession().getBookMarkDao() return DbManager.getInstance().getSession().getBookMarkDao()
.queryBuilder() .queryBuilder()
.where(BookMarkDao.Properties.BookId.eq(bookId)) .where(BookMarkDao.Properties.BookId.eq(bookId))
.orderAsc(BookMarkDao.Properties.Number) .orderAsc(BookMarkDao.Properties.Number)
@ -86,7 +77,7 @@ public class BookMarkService extends BaseService {
* @param bookId * @param bookId
*/ */
public void deleteBookALLBookMarkById(String bookId) { public void deleteBookALLBookMarkById(String bookId) {
GreenDaoManager.getInstance().getSession().getBookMarkDao() DbManager.getInstance().getSession().getBookMarkDao()
.queryBuilder() .queryBuilder()
.where(BookMarkDao.Properties.BookId.eq(bookId)) .where(BookMarkDao.Properties.BookId.eq(bookId))
.buildDelete() .buildDelete()
@ -108,7 +99,7 @@ public class BookMarkService extends BaseService {
* @param id * @param id
*/ */
public void deleteBookMarkById(String id){ public void deleteBookMarkById(String id){
BookMarkDao bookMarkDao = GreenDaoManager.getInstance().getSession().getBookMarkDao(); BookMarkDao bookMarkDao = DbManager.getInstance().getSession().getBookMarkDao();
bookMarkDao.deleteByKey(id); bookMarkDao.deleteByKey(id);
} }
@ -136,7 +127,7 @@ public class BookMarkService extends BaseService {
e.printStackTrace(); e.printStackTrace();
}*/ }*/
return (int) GreenDaoManager.getInstance().getSession().getBookMarkDao() return (int) DbManager.getInstance().getSession().getBookMarkDao()
.queryBuilder() .queryBuilder()
.where(BookMarkDao.Properties.BookId.eq(bookId)) .where(BookMarkDao.Properties.BookId.eq(bookId))
.count(); .count();

@ -13,7 +13,7 @@ import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.gen.BookDao; import xyz.fycz.myreader.greendao.gen.BookDao;
import xyz.fycz.myreader.util.*; 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.greendao.entity.Book;
import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.util.utils.StringUtils;
@ -57,7 +57,7 @@ public class BookService extends BaseService {
* @return * @return
*/ */
public Book getBookById(String id) { public Book getBookById(String id) {
BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); BookDao bookDao = DbManager.getInstance().getSession().getBookDao();
return bookDao.load(id); return bookDao.load(id);
} }
@ -67,7 +67,7 @@ public class BookService extends BaseService {
* @return * @return
*/ */
public List<Book> getAllBooks() { public List<Book> getAllBooks() {
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.orderAsc(BookDao.Properties.SortCode) .orderAsc(BookDao.Properties.SortCode)
.list(); .list();
@ -97,7 +97,7 @@ public class BookService extends BaseService {
if (StringHelper.isEmpty(groupId)){ if (StringHelper.isEmpty(groupId)){
return getAllBooksNoHide(); return getAllBooksNoHide();
} }
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.where(BookDao.Properties.GroupId.eq(groupId)) .where(BookDao.Properties.GroupId.eq(groupId))
.orderAsc(BookDao.Properties.GroupSort) .orderAsc(BookDao.Properties.GroupSort)
@ -148,13 +148,13 @@ public class BookService extends BaseService {
*/ */
public Book findBookByAuthorAndName(String bookName, String author) { public Book findBookByAuthorAndName(String bookName, String author) {
try { try {
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author)) .where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author))
.unique(); .unique();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author)) .where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author))
.list().get(0); .list().get(0);
@ -169,13 +169,13 @@ public class BookService extends BaseService {
*/ */
public Book findBookByPath(String path) { public Book findBookByPath(String path) {
try { try {
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.where(BookDao.Properties.ChapterUrl.eq(path)) .where(BookDao.Properties.ChapterUrl.eq(path))
.unique(); .unique();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return GreenDaoManager.getInstance().getSession().getBookDao() return DbManager.getInstance().getSession().getBookDao()
.queryBuilder() .queryBuilder()
.where(BookDao.Properties.ChapterUrl.eq(path)) .where(BookDao.Properties.ChapterUrl.eq(path))
.list().get(0); .list().get(0);
@ -188,7 +188,7 @@ public class BookService extends BaseService {
* @param id * @param id
*/ */
public void deleteBookById(String id) { public void deleteBookById(String id) {
BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); BookDao bookDao = DbManager.getInstance().getSession().getBookDao();
bookDao.deleteByKey(id); bookDao.deleteByKey(id);
mChapterService.deleteBookALLChapterById(id); mChapterService.deleteBookALLChapterById(id);
mBookMarkService.deleteBookALLBookMarkById(id); mBookMarkService.deleteBookALLBookMarkById(id);
@ -249,7 +249,7 @@ public class BookService extends BaseService {
* @param books * @param books
*/ */
public void updateBooks(List<Book> books) { public void updateBooks(List<Book> books) {
BookDao bookDao = GreenDaoManager.getInstance().getSession().getBookDao(); BookDao bookDao = DbManager.getInstance().getSession().getBookDao();
bookDao.updateInTx(books); bookDao.updateInTx(books);
} }

@ -2,13 +2,12 @@ package xyz.fycz.myreader.greendao.service;
import android.database.Cursor; import android.database.Cursor;
import android.util.Log;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.gen.ChapterDao; import xyz.fycz.myreader.greendao.gen.ChapterDao;
import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.IOUtils;
import xyz.fycz.myreader.util.StringHelper; 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 xyz.fycz.myreader.util.utils.FileUtils;
import java.io.*; import java.io.*;
@ -60,7 +59,7 @@ public class ChapterService extends BaseService {
* @return * @return
*/ */
public Chapter getChapterById(String id) { public Chapter getChapterById(String id) {
ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao();
return chapterDao.load(id); return chapterDao.load(id);
} }
@ -119,7 +118,7 @@ public class ChapterService extends BaseService {
* @param bookId * @param bookId
*/ */
public void deleteBookALLChapterById(String bookId) { public void deleteBookALLChapterById(String bookId) {
GreenDaoManager.getInstance().getSession().getChapterDao() DbManager.getInstance().getSession().getChapterDao()
.queryBuilder() .queryBuilder()
.where(ChapterDao.Properties.BookId.eq(bookId)) .where(ChapterDao.Properties.BookId.eq(bookId))
.buildDelete() .buildDelete()
@ -131,7 +130,7 @@ public class ChapterService extends BaseService {
* 更新章节 * 更新章节
*/ */
public void updateChapter(Chapter chapter) { public void updateChapter(Chapter chapter) {
ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao();
chapterDao.update(chapter); chapterDao.update(chapter);
} }
@ -172,7 +171,7 @@ public class ChapterService extends BaseService {
* 批量添加章节 * 批量添加章节
*/ */
public void addChapters(List<Chapter> chapters) { public void addChapters(List<Chapter> chapters) {
ChapterDao chapterDao = GreenDaoManager.getInstance().getSession().getChapterDao(); ChapterDao chapterDao = DbManager.getInstance().getSession().getChapterDao();
chapterDao.insertInTx(chapters); chapterDao.insertInTx(chapters);
} }

@ -6,7 +6,7 @@ import xyz.fycz.myreader.greendao.entity.SearchHistory;
import xyz.fycz.myreader.greendao.gen.SearchHistoryDao; import xyz.fycz.myreader.greendao.gen.SearchHistoryDao;
import xyz.fycz.myreader.util.DateHelper; import xyz.fycz.myreader.util.DateHelper;
import xyz.fycz.myreader.util.StringHelper; 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.ArrayList;
import java.util.Date; import java.util.Date;
@ -77,7 +77,7 @@ public class SearchHistoryService extends BaseService {
* 清空历史记录 * 清空历史记录
*/ */
public void clearHistory(){ public void clearHistory(){
SearchHistoryDao searchHistoryDao = GreenDaoManager.getInstance().getSession().getSearchHistoryDao(); SearchHistoryDao searchHistoryDao = DbManager.getInstance().getSession().getSearchHistoryDao();
searchHistoryDao.deleteAll(); searchHistoryDao.deleteAll();
} }

@ -38,7 +38,7 @@ public class MySQLiteOpenHelper extends DaoMaster.OpenHelper {
}, },
BookDao.class, ChapterDao.class, SearchHistoryDao.class, BookDao.class, ChapterDao.class, SearchHistoryDao.class,
BookMarkDao.class, BookGroupDao.class, ReplaceRuleBeanDao.class, BookMarkDao.class, BookGroupDao.class, ReplaceRuleBeanDao.class,
BookSourceDao.class BookSourceDao.class, CookieBeanDao.class
); );
} }

@ -8,14 +8,11 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe; import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull; import xyz.fycz.myreader.greendao.DbManager;
import xyz.fycz.myreader.greendao.GreenDaoManager;
import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; 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.greendao.gen.ReplaceRuleBeanDao;
import xyz.fycz.myreader.util.utils.GsonUtils; import xyz.fycz.myreader.util.utils.GsonUtils;
import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.NetworkUtils;
@ -33,7 +30,7 @@ public class ReplaceRuleManager {
public static List<ReplaceRuleBean> getEnabled() { public static List<ReplaceRuleBean> getEnabled() {
if (replaceRuleBeansEnabled == null) { if (replaceRuleBeansEnabled == null) {
replaceRuleBeansEnabled = GreenDaoManager.getDaoSession() replaceRuleBeansEnabled = DbManager.getDaoSession()
.getReplaceRuleBeanDao().queryBuilder() .getReplaceRuleBeanDao().queryBuilder()
.where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .where(ReplaceRuleBeanDao.Properties.Enable.eq(true))
.orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber)
@ -54,11 +51,11 @@ public class ReplaceRuleManager {
int sn = replaceRuleBean.getSerialNumber(); int sn = replaceRuleBean.getSerialNumber();
if (sn == 0) { if (sn == 0) {
sn = (int) (GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1); sn = (int) (DbManager.getDaoSession().getReplaceRuleBeanDao().queryBuilder().count() + 1);
replaceRuleBean.setSerialNumber(sn); replaceRuleBean.setSerialNumber(sn);
} }
List<ReplaceRuleBean> list = GreenDaoManager.getDaoSession() List<ReplaceRuleBean> list = DbManager.getDaoSession()
.getReplaceRuleBeanDao().queryBuilder() .getReplaceRuleBeanDao().queryBuilder()
.where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .where(ReplaceRuleBeanDao.Properties.Enable.eq(true))
.where(ReplaceRuleBeanDao.Properties.ReplaceSummary.eq(replaceRuleBean.getReplaceSummary())) .where(ReplaceRuleBeanDao.Properties.ReplaceSummary.eq(replaceRuleBean.getReplaceSummary()))
@ -79,9 +76,9 @@ public class ReplaceRuleManager {
return Single.create((SingleOnSubscribe<Boolean>) emitter -> { return Single.create((SingleOnSubscribe<Boolean>) emitter -> {
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean); DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(replaceRuleBean);
for (ReplaceRuleBean li : list) { for (ReplaceRuleBean li : list) {
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().delete(li); DbManager.getDaoSession().getReplaceRuleBeanDao().delete(li);
} }
refreshDataS(); refreshDataS();
emitter.onSuccess(true); emitter.onSuccess(true);
@ -130,14 +127,14 @@ public class ReplaceRuleManager {
return buffer.toString().trim(); return buffer.toString().trim();
} }
public static Single<List<ReplaceRuleBean>> getAll() { public static Single<List<ReplaceRuleBean>> getAll() {
return Single.create((SingleOnSubscribe<List<ReplaceRuleBean>>) emitter -> emitter.onSuccess(GreenDaoManager.getDaoSession() return Single.create((SingleOnSubscribe<List<ReplaceRuleBean>>) emitter -> emitter.onSuccess(DbManager.getDaoSession()
.getReplaceRuleBeanDao().queryBuilder() .getReplaceRuleBeanDao().queryBuilder()
.orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber)
.list())).compose(RxUtils::toSimpleSingle); .list())).compose(RxUtils::toSimpleSingle);
} }
public static List<ReplaceRuleBean> getAllRules() { public static List<ReplaceRuleBean> getAllRules() {
return GreenDaoManager.getDaoSession() return DbManager.getDaoSession()
.getReplaceRuleBeanDao().queryBuilder() .getReplaceRuleBeanDao().queryBuilder()
.orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber)
.list(); .list();
@ -146,29 +143,29 @@ public class ReplaceRuleManager {
public static Single<Boolean> saveData(ReplaceRuleBean replaceRuleBean) { public static Single<Boolean> saveData(ReplaceRuleBean replaceRuleBean) {
return Single.create((SingleOnSubscribe<Boolean>) emitter -> { return Single.create((SingleOnSubscribe<Boolean>) emitter -> {
if (replaceRuleBean.getSerialNumber() == 0) { 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(); refreshDataS();
emitter.onSuccess(true); emitter.onSuccess(true);
}).compose(RxUtils::toSimpleSingle); }).compose(RxUtils::toSimpleSingle);
} }
public static void delData(ReplaceRuleBean replaceRuleBean) { public static void delData(ReplaceRuleBean replaceRuleBean) {
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().delete(replaceRuleBean); DbManager.getDaoSession().getReplaceRuleBeanDao().delete(replaceRuleBean);
refreshDataS(); refreshDataS();
} }
public static void addDataS(List<ReplaceRuleBean> replaceRuleBeans) { public static void addDataS(List<ReplaceRuleBean> replaceRuleBeans) {
if (replaceRuleBeans != null && replaceRuleBeans.size() > 0) { if (replaceRuleBeans != null && replaceRuleBeans.size() > 0) {
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(replaceRuleBeans); DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(replaceRuleBeans);
refreshDataS(); refreshDataS();
} }
} }
public static void delDataS(List<ReplaceRuleBean> replaceRuleBeans) { public static void delDataS(List<ReplaceRuleBean> replaceRuleBeans) {
if (replaceRuleBeans == null) return; if (replaceRuleBeans == null) return;
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().deleteInTx(replaceRuleBeans); DbManager.getDaoSession().getReplaceRuleBeanDao().deleteInTx(replaceRuleBeans);
refreshDataS(); refreshDataS();
} }
@ -179,14 +176,14 @@ public class ReplaceRuleManager {
beans.get(i).setSerialNumber(i + 1); beans.get(i).setSerialNumber(i + 1);
} }
bean.setSerialNumber(0); bean.setSerialNumber(0);
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(beans); DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplaceInTx(beans);
GreenDaoManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(bean); DbManager.getDaoSession().getReplaceRuleBeanDao().insertOrReplace(bean);
e.onSuccess(true); e.onSuccess(true);
}).compose(RxUtils::toSimpleSingle); }).compose(RxUtils::toSimpleSingle);
} }
private static void refreshDataS() { private static void refreshDataS() {
replaceRuleBeansEnabled = GreenDaoManager.getDaoSession() replaceRuleBeansEnabled = DbManager.getDaoSession()
.getReplaceRuleBeanDao().queryBuilder() .getReplaceRuleBeanDao().queryBuilder()
.where(ReplaceRuleBeanDao.Properties.Enable.eq(true)) .where(ReplaceRuleBeanDao.Properties.Enable.eq(true))
.orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber) .orderAsc(ReplaceRuleBeanDao.Properties.SerialNumber)

@ -14,15 +14,13 @@ import io.reactivex.Observable;
import io.reactivex.ObservableEmitter; import io.reactivex.ObservableEmitter;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe; import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.application.App; 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.BookSource3Bean;
import xyz.fycz.myreader.entity.thirdsource.BookSourceBean; import xyz.fycz.myreader.entity.thirdsource.BookSourceBean;
import xyz.fycz.myreader.entity.thirdsource.ThirdSourceUtil; import xyz.fycz.myreader.entity.thirdsource.ThirdSourceUtil;
import xyz.fycz.myreader.enums.LocalBookSource; 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.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.greendao.gen.BookSourceDao;
import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.SharedPreUtils;
@ -41,7 +39,7 @@ public class BookSourceManager {
public static final int SOURCE_LENGTH = 500; public static final int SOURCE_LENGTH = 500;
public static List<BookSource> getEnabledBookSource() { public static List<BookSource> getEnabledBookSource() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.Enable.eq(true)) .where(BookSourceDao.Properties.Enable.eq(true))
.orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC") .orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC")
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
@ -49,27 +47,27 @@ public class BookSourceManager {
} }
public static List<BookSource> getAllBookSource() { public static List<BookSource> getAllBookSource() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.orderRaw(getBookSourceSort()) .orderRaw(getBookSourceSort())
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
.list(); .list();
} }
public static List<BookSource> getEnabledBookSourceByOrderNum() { public static List<BookSource> getEnabledBookSourceByOrderNum() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.Enable.eq(true)) .where(BookSourceDao.Properties.Enable.eq(true))
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
.list(); .list();
} }
public static List<BookSource> getAllBookSourceByOrderNum() { public static List<BookSource> getAllBookSourceByOrderNum() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
.list(); .list();
} }
public static List<BookSource> getEnableSourceByGroup(String group) { public static List<BookSource> getEnableSourceByGroup(String group) {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.Enable.eq(true)) .where(BookSourceDao.Properties.Enable.eq(true))
.where(BookSourceDao.Properties.SourceGroup.like("%" + group + "%")) .where(BookSourceDao.Properties.SourceGroup.like("%" + group + "%"))
.orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC") .orderRaw(BookSourceDao.Properties.Weight.columnName + " DESC")
@ -98,7 +96,7 @@ public class BookSourceManager {
*/ */
public static BookSource getBookSourceByUrl(String url) { public static BookSource getBookSourceByUrl(String url) {
if (url == null) return getDefaultSource(); if (url == null) return getDefaultSource();
BookSource source = GreenDaoManager.getDaoSession().getBookSourceDao().load(url); BookSource source = DbManager.getDaoSession().getBookSourceDao().load(url);
if (source == null) return getDefaultSource(); if (source == null) return getDefaultSource();
return source; return source;
} }
@ -113,7 +111,7 @@ public class BookSourceManager {
public static BookSource getBookSourceByEName(String ename) { public static BookSource getBookSourceByEName(String ename) {
if (ename == null) return getDefaultSource(); if (ename == null) return getDefaultSource();
if ("local".equals(ename)) return getLocalSource(); if ("local".equals(ename)) return getLocalSource();
BookSource source = GreenDaoManager.getDaoSession().getBookSourceDao(). BookSource source = DbManager.getDaoSession().getBookSourceDao().
queryBuilder() queryBuilder()
.where(BookSourceDao.Properties.SourceEName.eq(ename)) .where(BookSourceDao.Properties.SourceEName.eq(ename))
.unique(); .unique();
@ -163,7 +161,7 @@ public class BookSourceManager {
* @return * @return
*/ */
public static List<BookSource> getAllLocalSource() { public static List<BookSource> getAllLocalSource() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.SourceEName.isNotNull()) .where(BookSourceDao.Properties.SourceEName.isNotNull())
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
.list(); .list();
@ -175,7 +173,7 @@ public class BookSourceManager {
* @return * @return
*/ */
public static List<BookSource> getAllNoLocalSource() { public static List<BookSource> getAllNoLocalSource() {
return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() return DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.SourceEName.isNull()) .where(BookSourceDao.Properties.SourceEName.isNull())
.orderAsc(BookSourceDao.Properties.OrderNum) .orderAsc(BookSourceDao.Properties.OrderNum)
.list(); .list();
@ -188,12 +186,12 @@ public class BookSourceManager {
*/ */
public static void removeBookSource(BookSource source) { public static void removeBookSource(BookSource source) {
if (source == null) return; if (source == null) return;
GreenDaoManager.getDaoSession().getBookSourceDao().delete(source); DbManager.getDaoSession().getBookSourceDao().delete(source);
} }
public static void removeBookSources(List<BookSource> sources) { public static void removeBookSources(List<BookSource> sources) {
if (sources == null) return; 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("/")) { if (bookSource.getSourceUrl().endsWith("/")) {
bookSource.setSourceUrl(bookSource.getSourceUrl().replaceAll("/+$", "")); 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(); .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())).unique();
if (temp != null) { if (temp != null) {
bookSource.setOrderNum(temp.getOrderNum()); bookSource.setOrderNum(temp.getOrderNum());
} else { } 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; return true;
} }
public static Single<Boolean> saveData(BookSource bookSource) { public static Single<Boolean> saveData(BookSource bookSource) {
return Single.create((SingleOnSubscribe<Boolean>) emitter -> { return Single.create((SingleOnSubscribe<Boolean>) emitter -> {
if (bookSource.getOrderNum() == 0) { 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); emitter.onSuccess(true);
}).compose(RxUtils::toSimpleSingle); }).compose(RxUtils::toSimpleSingle);
} }
@ -245,10 +243,10 @@ public class BookSourceManager {
return Single.create((SingleOnSubscribe<Boolean>) emitter -> { return Single.create((SingleOnSubscribe<Boolean>) emitter -> {
for (BookSource source : sources) { for (BookSource source : sources) {
if (source.getOrderNum() == 0) { 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); emitter.onSuccess(true);
}).compose(RxUtils::toSimpleSingle); }).compose(RxUtils::toSimpleSingle);
} }
@ -260,8 +258,8 @@ public class BookSourceManager {
List.get(i).setOrderNum(i + 1); List.get(i).setOrderNum(i + 1);
} }
source.setOrderNum(0); source.setOrderNum(0);
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(List); DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(List);
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(source); DbManager.getDaoSession().getBookSourceDao().insertOrReplace(source);
e.onSuccess(true); e.onSuccess(true);
}).compose(RxUtils::toSimpleSingle); }).compose(RxUtils::toSimpleSingle);
} }
@ -272,7 +270,7 @@ public class BookSourceManager {
+ BookSourceDao.Properties.SourceGroup.columnName + BookSourceDao.Properties.SourceGroup.columnName
+ " FROM " + BookSourceDao.TABLENAME + " FROM " + BookSourceDao.TABLENAME
+ " WHERE " + BookSourceDao.Properties.Enable.name + " = 1"; + " 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; if (!cursor.moveToFirst()) return groupList;
do { do {
String group = cursor.getString(0); String group = cursor.getString(0);
@ -290,7 +288,7 @@ public class BookSourceManager {
public static List<String> getNoLocalGroupList() { public static List<String> getNoLocalGroupList() {
List<String> groupList = new ArrayList<>(); List<String> groupList = new ArrayList<>();
String sql = "SELECT DISTINCT " + BookSourceDao.Properties.SourceGroup.columnName + " FROM " + BookSourceDao.TABLENAME; 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; if (!cursor.moveToFirst()) return groupList;
do { do {
String group = cursor.getString(0); String group = cursor.getString(0);
@ -334,7 +332,7 @@ public class BookSourceManager {
if (bookSources != null) { if (bookSources != null) {
for (BookSource bookSource : bookSources) { for (BookSource bookSource : bookSources) {
if (bookSource.containsGroup("删除")) { if (bookSource.containsGroup("删除")) {
GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())) .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl()))
.buildDelete().executeDeleteWithoutDetachingEntities(); .buildDelete().executeDeleteWithoutDetachingEntities();
} else { } else {
@ -406,7 +404,7 @@ public class BookSourceManager {
public static void initDefaultSources() { public static void initDefaultSources() {
Log.d("initDefaultSources", "execute"); Log.d("initDefaultSources", "execute");
GreenDaoManager.getDaoSession().getBookSourceDao().deleteAll(); DbManager.getDaoSession().getBookSourceDao().deleteAll();
String searchSource = SharedPreUtils.getInstance().getString(App.getmContext().getString(R.string.searchSource)); String searchSource = SharedPreUtils.getInstance().getString(App.getmContext().getString(R.string.searchSource));
boolean isEmpty = StringHelper.isEmpty(searchSource); boolean isEmpty = StringHelper.isEmpty(searchSource);
for (LocalBookSource source : LocalBookSource.values()) { for (LocalBookSource source : LocalBookSource.values()) {
@ -418,7 +416,7 @@ public class BookSourceManager {
source1.setEnable(isEmpty || searchSource.contains(source.toString())); source1.setEnable(isEmpty || searchSource.contains(source.toString()));
source1.setSourceUrl(ReadCrawlerUtil.getReadCrawlerClz(source.toString())); source1.setSourceUrl(ReadCrawlerUtil.getReadCrawlerClz(source.toString()));
source1.setOrderNum(0); source1.setOrderNum(0);
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(source1); DbManager.getDaoSession().getBookSourceDao().insertOrReplace(source1);
} }
String referenceSources = FileUtils.readAssertFile(App.getmContext(), String referenceSources = FileUtils.readAssertFile(App.getmContext(),
"ReferenceSources.json"); "ReferenceSources.json");

@ -12,7 +12,7 @@ import xyz.fycz.myreader.application.App
import xyz.fycz.myreader.application.SysManager import xyz.fycz.myreader.application.SysManager
import xyz.fycz.myreader.base.observer.MySingleObserver import xyz.fycz.myreader.base.observer.MySingleObserver
import xyz.fycz.myreader.common.APPCONST 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.BookService
import xyz.fycz.myreader.greendao.service.SearchHistoryService import xyz.fycz.myreader.greendao.service.SearchHistoryService
import xyz.fycz.myreader.util.SharedPreUtils import xyz.fycz.myreader.util.SharedPreUtils
@ -74,28 +74,28 @@ object Backup {
.writeText(json) .writeText(json)
} }
} }
GreenDaoManager.getInstance().session.bookMarkDao.queryBuilder().list().let { DbManager.getInstance().session.bookMarkDao.queryBuilder().list().let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val json = GSON.toJson(it) val json = GSON.toJson(it)
FileUtils.getFile(backupPath + File.separator + "myBookMark.json") FileUtils.getFile(backupPath + File.separator + "myBookMark.json")
.writeText(json) .writeText(json)
} }
} }
GreenDaoManager.getInstance().session.bookGroupDao.queryBuilder().list().let { DbManager.getInstance().session.bookGroupDao.queryBuilder().list().let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val json = GSON.toJson(it) val json = GSON.toJson(it)
FileUtils.getFile(backupPath + File.separator + "myBookGroup.json") FileUtils.getFile(backupPath + File.separator + "myBookGroup.json")
.writeText(json) .writeText(json)
} }
} }
GreenDaoManager.getInstance().session.replaceRuleBeanDao.queryBuilder().list().let { DbManager.getInstance().session.replaceRuleBeanDao.queryBuilder().list().let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val json = GSON.toJson(it) val json = GSON.toJson(it)
FileUtils.getFile(backupPath + File.separator + "replaceRule.json") FileUtils.getFile(backupPath + File.separator + "replaceRule.json")
.writeText(json) .writeText(json)
} }
} }
GreenDaoManager.getInstance().session.bookSourceDao.queryBuilder().list().let { DbManager.getInstance().session.bookSourceDao.queryBuilder().list().let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val json = GSON.toJson(it) val json = GSON.toJson(it)
FileUtils.getFile(backupPath + File.separator + "bookSource.json") FileUtils.getFile(backupPath + File.separator + "bookSource.json")

@ -12,7 +12,7 @@ import xyz.fycz.myreader.application.SysManager
import xyz.fycz.myreader.base.observer.MySingleObserver import xyz.fycz.myreader.base.observer.MySingleObserver
import xyz.fycz.myreader.entity.ReadStyle import xyz.fycz.myreader.entity.ReadStyle
import xyz.fycz.myreader.entity.Setting 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.*
import xyz.fycz.myreader.greendao.entity.rule.BookSource import xyz.fycz.myreader.greendao.entity.rule.BookSource
import xyz.fycz.myreader.util.SharedPreUtils import xyz.fycz.myreader.util.SharedPreUtils
@ -60,7 +60,7 @@ object Restore {
if (bookshelf.bookInfoBean.noteUrl != null) { if (bookshelf.bookInfoBean.noteUrl != null) {
DbHelper.getDaoSession().bookInfoBeanDao.insertOrReplace(bookshelf.bookInfoBean) DbHelper.getDaoSession().bookInfoBeanDao.insertOrReplace(bookshelf.bookInfoBean)
}*/ }*/
GreenDaoManager.getInstance().session.bookDao.insertOrReplace(bookshelf) DbManager.getInstance().session.bookDao.insertOrReplace(bookshelf)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -69,7 +69,7 @@ object Restore {
val file = FileUtils.getFile(path + File.separator + "mySearchHistory.json") val file = FileUtils.getFile(path + File.separator + "mySearchHistory.json")
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<SearchHistory>(json)?.let { GSON.fromJsonArray<SearchHistory>(json)?.let {
GreenDaoManager.getInstance().session.searchHistoryDao.insertOrReplaceInTx(it) DbManager.getInstance().session.searchHistoryDao.insertOrReplaceInTx(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -78,7 +78,7 @@ object Restore {
val file = FileUtils.getFile(path + File.separator + "myBookMark.json") val file = FileUtils.getFile(path + File.separator + "myBookMark.json")
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<BookMark>(json)?.let { GSON.fromJsonArray<BookMark>(json)?.let {
GreenDaoManager.getInstance().session.bookMarkDao.insertOrReplaceInTx(it) DbManager.getInstance().session.bookMarkDao.insertOrReplaceInTx(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -87,7 +87,7 @@ object Restore {
val file = FileUtils.getFile(path + File.separator + "myBookGroup.json") val file = FileUtils.getFile(path + File.separator + "myBookGroup.json")
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<BookGroup>(json)?.let { GSON.fromJsonArray<BookGroup>(json)?.let {
GreenDaoManager.getInstance().session.bookGroupDao.insertOrReplaceInTx(it) DbManager.getInstance().session.bookGroupDao.insertOrReplaceInTx(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -96,7 +96,7 @@ object Restore {
val file = FileUtils.getFile(path + File.separator + "replaceRule.json") val file = FileUtils.getFile(path + File.separator + "replaceRule.json")
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<ReplaceRuleBean>(json)?.let { GSON.fromJsonArray<ReplaceRuleBean>(json)?.let {
GreenDaoManager.getInstance().session.replaceRuleBeanDao.insertOrReplaceInTx(it) DbManager.getInstance().session.replaceRuleBeanDao.insertOrReplaceInTx(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -105,7 +105,7 @@ object Restore {
val file = FileUtils.getFile(path + File.separator + "bookSource.json") val file = FileUtils.getFile(path + File.separator + "bookSource.json")
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<BookSource>(json)?.let { GSON.fromJsonArray<BookSource>(json)?.let {
GreenDaoManager.getInstance().session.bookSourceDao.insertOrReplaceInTx(it) DbManager.getInstance().session.bookSourceDao.insertOrReplaceInTx(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()

@ -11,7 +11,7 @@ import java.util.regex.Matcher;
import io.reactivex.Observable; import io.reactivex.Observable;
import xyz.fycz.myreader.entity.StrResponse; 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.Book;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource;
@ -77,7 +77,7 @@ public class BookContent {
if (nextChapterBean != null) { if (nextChapterBean != null) {
nextChapter = nextChapterBean; nextChapter = nextChapterBean;
} else { } else {
nextChapter = GreenDaoManager.getDaoSession().getChapterDao().queryBuilder() nextChapter = DbManager.getDaoSession().getChapterDao().queryBuilder()
.where(ChapterDao.Properties.Url.eq(chapterBean.getUrl()), .where(ChapterDao.Properties.Url.eq(chapterBean.getUrl()),
ChapterDao.Properties.Number.eq(chapterBean.getNumber() + 1)) ChapterDao.Properties.Number.eq(chapterBean.getNumber() + 1))
.build().unique(); .build().unique();

@ -397,10 +397,16 @@ public class BookDetailedActivity extends BaseActivity {
binding.ih.bookDetailTvAuthor.setText(mBook.getAuthor()); binding.ih.bookDetailTvAuthor.setText(mBook.getAuthor());
if (StringHelper.isEmpty(mBook.getImgUrl())) { if (StringHelper.isEmpty(mBook.getImgUrl())) {
mBook.setImgUrl(""); mBook.setImgUrl("");
} else {
if (!App.isDestroy(this)) {
binding.ih.bookDetailIvCover.load(NetworkUtils.getAbsoluteURL(mReadCrawler.getNameSpace(), mBook.getImgUrl()), mBook.getName(), mBook.getAuthor());
}
} }
initTagList(); initTagList();
if (StringHelper.isEmpty(mBook.getDesc())) if (StringHelper.isEmpty(mBook.getDesc()))
binding.ic.bookDetailTvDesc.setText(""); binding.ic.bookDetailTvDesc.setText("");
else
binding.ic.bookDetailTvDesc.setText(String.format("\t\t\t\t%s", mBook.getDesc()));
BookSource source = BookSourceManager.getBookSourceByStr(mBook.getSource()); BookSource source = BookSourceManager.getBookSourceByStr(mBook.getSource());
binding.ih.bookDetailSource.setText(String.format("书源:%s", source.getSourceName())); binding.ih.bookDetailSource.setText(String.format("书源:%s", source.getSourceName()));
ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(source); ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(source);
@ -413,7 +419,7 @@ public class BookDetailedActivity extends BaseActivity {
if (!App.isDestroy(BookDetailedActivity.this)) { if (!App.isDestroy(BookDetailedActivity.this)) {
mHandler.sendMessage(mHandler.obtainMessage(4)); mHandler.sendMessage(mHandler.obtainMessage(4));
} }
if (thirdSource){ if (thirdSource) {
initChapters(false); initChapters(false);
} }
} }
@ -421,7 +427,7 @@ public class BookDetailedActivity extends BaseActivity {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
ToastUtils.showError("书籍详情加载失败!"); ToastUtils.showError("书籍详情加载失败!");
if (thirdSource){ if (thirdSource) {
initChapters(false); initChapters(false);
} }
if (App.isDebug()) e.printStackTrace(); if (App.isDebug()) e.printStackTrace();
@ -500,7 +506,7 @@ public class BookDetailedActivity extends BaseActivity {
} }
} }
private Observable<Boolean> saveChapters(List<Chapter> chapters, boolean isChangeSource){ private Observable<Boolean> saveChapters(List<Chapter> chapters, boolean isChangeSource) {
return Observable.create(emitter -> { return Observable.create(emitter -> {
mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle()); mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle());
if (isCollected) { if (isCollected) {

@ -161,7 +161,7 @@ public class SplashActivity extends BaseActivity {
} else { } else {
App.getHandler().postDelayed(() -> { App.getHandler().postDelayed(() -> {
binding.tvSkip.setVisibility(View.VISIBLE); binding.tvSkip.setVisibility(View.VISIBLE);
}, 3000); }, 2000);
AdUtils.checkHasAd() AdUtils.checkHasAd()
.subscribe(new MySingleObserver<Boolean>() { .subscribe(new MySingleObserver<Boolean>() {
@Override @Override

@ -3,20 +3,12 @@ package xyz.fycz.myreader.ui.adapter;
import android.os.AsyncTask; import android.os.AsyncTask;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import java.util.ArrayList;
import java.util.Collections; 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.base.adapter.IViewHolder;
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.entity.rule.BookSource;
import xyz.fycz.myreader.ui.adapter.helper.ItemTouchCallback; import xyz.fycz.myreader.ui.adapter.helper.ItemTouchCallback;
import xyz.fycz.myreader.ui.adapter.holder.BookSourceHolder; 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++) { for (int i = 1; i <= mList.size(); i++) {
mList.get(i - 1).setOrderNum(i); mList.get(i - 1).setOrderNum(i);
} }
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mList); DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mList);
}); });
return true; return true;
} }

@ -7,7 +7,7 @@ import java.util.HashMap;
import xyz.fycz.myreader.R; import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.adapter.ViewHolderImpl; 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.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.ToastUtils;
@ -46,12 +46,12 @@ public class LocalSourceHolder extends ViewHolderImpl<BookSource> {
tvEnable.setOnClickListener(v -> { tvEnable.setOnClickListener(v -> {
data.setEnable(true); data.setEnable(true);
banOrUse(data); banOrUse(data);
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(data); DbManager.getDaoSession().getBookSourceDao().insertOrReplace(data);
}); });
tvDisable.setOnClickListener(v -> { tvDisable.setOnClickListener(v -> {
data.setEnable(false); data.setEnable(false);
banOrUse(data); banOrUse(data);
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplace(data); DbManager.getDaoSession().getBookSourceDao().insertOrReplace(data);
}); });
tvCheck.setOnClickListener(v -> ToastUtils.showInfo("校验功能即将上线")); tvCheck.setOnClickListener(v -> ToastUtils.showInfo("校验功能即将上线"));
} }

@ -89,6 +89,8 @@ public class SearchBookHolder extends ViewHolderImpl<SearchBookBean> {
if (!App.isDestroy((Activity) getContext())) { if (!App.isDestroy((Activity) getContext())) {
ivBookImg.load(NetworkUtils.getAbsoluteURL(rc.getNameSpace(), data.getImgUrl()), data.getName(), data.getAuthor()); ivBookImg.load(NetworkUtils.getAbsoluteURL(rc.getNameSpace(), data.getImgUrl()), data.getName(), data.getAuthor());
} }
}else {
data.setImgUrl("");
} }
KeyWordUtils.setKeyWord(tvBookName, data.getName(), keyWord); KeyWordUtils.setKeyWord(tvBookName, data.getName(), keyWord);
if (!StringHelper.isEmpty(data.getAuthor())) { if (!StringHelper.isEmpty(data.getAuthor())) {
@ -97,9 +99,13 @@ public class SearchBookHolder extends ViewHolderImpl<SearchBookBean> {
initTagList(data); initTagList(data);
if (!StringHelper.isEmpty(data.getLastChapter())) { if (!StringHelper.isEmpty(data.getLastChapter())) {
tvNewestChapter.setText(getContext().getString(R.string.newest_chapter, data.getLastChapter())); tvNewestChapter.setText(getContext().getString(R.string.newest_chapter, data.getLastChapter()));
}else {
data.setLastChapter("");
} }
if (!StringHelper.isEmpty(data.getDesc())) { if (!StringHelper.isEmpty(data.getDesc())) {
tvDesc.setText(String.format("简介:%s", data.getDesc())); tvDesc.setText(String.format("简介:%s", data.getDesc()));
}else {
data.setDesc("");
} }
tvSource.setText(getContext().getString(R.string.source_title_num, source.getSourceName(), bookCount)); tvSource.setText(getContext().getString(R.string.source_title_num, source.getSourceName(), bookCount));
App.getHandler().postDelayed(() -> { App.getHandler().postDelayed(() -> {

@ -2,7 +2,6 @@ package xyz.fycz.myreader.ui.fragment;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Gravity; 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.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.FragmentImportSourceBinding; 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.entity.rule.BookSource;
import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.greendao.gen.BookSourceDao;
import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
@ -211,7 +210,7 @@ public class DIYSourceFragment extends BaseFragment {
List<BookSource> sourceBeanList; List<BookSource> sourceBeanList;
if (isSearch) { if (isSearch) {
if (sourceActivity.getSearchView().getQuery().toString().equals("enabled")) { 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.SourceEName.isNull())
.where(BookSourceDao.Properties.Enable.eq(1)) .where(BookSourceDao.Properties.Enable.eq(1))
.orderRaw(BookSourceManager.getBookSourceSort()) .orderRaw(BookSourceManager.getBookSourceSort())
@ -219,7 +218,7 @@ public class DIYSourceFragment extends BaseFragment {
.list(); .list();
} else { } else {
String term = "%" + sourceActivity.getSearchView().getQuery() + "%"; String term = "%" + sourceActivity.getSearchView().getQuery() + "%";
sourceBeanList = GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() sourceBeanList = DbManager.getDaoSession().getBookSourceDao().queryBuilder()
.where(BookSourceDao.Properties.SourceEName.isNull()) .where(BookSourceDao.Properties.SourceEName.isNull())
.whereOr(BookSourceDao.Properties.SourceName.like(term), .whereOr(BookSourceDao.Properties.SourceName.like(term),
BookSourceDao.Properties.SourceGroup.like(term), BookSourceDao.Properties.SourceGroup.like(term),
@ -385,7 +384,7 @@ public class DIYSourceFragment extends BaseFragment {
for (BookSource source : mBookSources) { for (BookSource source : mBookSources) {
source.setEnable(!source.getEnable()); source.setEnable(!source.getEnable());
} }
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mBookSources); DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(mBookSources);
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
} }

@ -16,7 +16,7 @@ import xyz.fycz.myreader.R;
import xyz.fycz.myreader.base.BaseFragment; import xyz.fycz.myreader.base.BaseFragment;
import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.databinding.FragmentLocalSourceBinding; 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.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager;
import xyz.fycz.myreader.ui.activity.BookSourceActivity; import xyz.fycz.myreader.ui.activity.BookSourceActivity;
@ -105,7 +105,7 @@ public class LocalSourceFragment extends BaseFragment {
source.setEnable(isEnable); source.setEnable(isEnable);
} }
Single.create((SingleOnSubscribe<Boolean>) emitter -> { Single.create((SingleOnSubscribe<Boolean>) emitter -> {
GreenDaoManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources); DbManager.getDaoSession().getBookSourceDao().insertOrReplaceInTx(sources);
emitter.onSuccess(true); emitter.onSuccess(true);
}).compose(RxUtils::toSimpleSingle) }).compose(RxUtils::toSimpleSingle)
.subscribe(new MySingleObserver<Boolean>() { .subscribe(new MySingleObserver<Boolean>() {

@ -123,9 +123,9 @@ public class AdUtils {
public static void initAd() { public static void initAd() {
if (!hasInitAd) { if (!hasInitAd) {
hasInitAd = true; hasInitAd = true;
DdSdkHelper.init("", "", "", DdSdkHelper.init("1234", "216", "51716a16fbdf50905704b6575b1b3b60",
"", "", "142364", "35ce0efe5f3cc960b116db227498e238",
"", "", "8167", "85bd159309c3da1b",
App.getApplication(), App.isDebug()); App.getApplication(), App.isDebug());
} }
} }

@ -19,6 +19,8 @@ import io.reactivex.Observable;
import okhttp3.*; import okhttp3.*;
import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.entity.StrResponse; 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.greendao.entity.rule.BookSource;
import xyz.fycz.myreader.model.third.analyzeRule.AnalyzeUrl; import xyz.fycz.myreader.model.third.analyzeRule.AnalyzeUrl;
@ -216,7 +218,7 @@ public class OkHttpUtils {
WebView webView = new WebView(App.getmContext()); WebView webView = new WebView(App.getmContext());
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUserAgentString(analyzeUrl.getHeaderMap().get("User-Agent")); webView.getSettings().setUserAgentString(analyzeUrl.getHeaderMap().get("User-Agent"));
//CookieManager cookieManager = CookieManager.getInstance(); CookieManager cookieManager = CookieManager.getInstance();
Runnable retryRunnable = new Runnable() { Runnable retryRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -245,8 +247,8 @@ public class OkHttpUtils {
webView.setWebViewClient(new WebViewClient() { webView.setWebViewClient(new WebViewClient() {
@Override @Override
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
/*DbHelper.getDaoSession().getCookieBeanDao() DbManager.getDaoSession().getCookieBeanDao()
.insertOrReplace(new CookieBean(tag, cookieManager.getCookie(webView.getUrl())));*/ .insertOrReplace(new CookieBean(tag, cookieManager.getCookie(webView.getUrl())));
handler.postDelayed(retryRunnable, 1000); handler.postDelayed(retryRunnable, 1000);
} }
}); });
@ -264,6 +266,28 @@ public class OkHttpUtils {
}); });
} }
public static Observable<StrResponse> 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 static class Web {
private String content; private String content;
private String js = "document.documentElement.outerHTML"; private String js = "document.documentElement.outerHTML";

@ -40,7 +40,7 @@ public class CommonApi {
*/ */
public static Observable<List<Chapter>> getBookChapters(Book book, final ReadCrawler rc) { public static Observable<List<Chapter>> getBookChapters(Book book, final ReadCrawler rc) {
if (rc instanceof ThirdCrawler) { if (rc instanceof ThirdCrawler) {
return getBookChaptersByTC(book, (ThirdCrawler) rc); return ThirdSourceApi.getBookChaptersByTC(book, (ThirdCrawler) rc);
} }
String url = book.getChapterUrl(); String url = book.getChapterUrl();
String charset = rc.getCharset(); String charset = rc.getCharset();
@ -52,29 +52,6 @@ public class CommonApi {
}); });
} }
private static Observable<List<Chapter>> 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<String> getChapterContent(Chapter chapter, Book book, final ReadCrawler rc) { public static Observable<String> getChapterContent(Chapter chapter, Book book, final ReadCrawler rc) {
if (rc instanceof ThirdCrawler) { if (rc instanceof ThirdCrawler) {
return getChapterContentByTC(chapter, book, (ThirdCrawler) rc); return ThirdSourceApi.getChapterContentByTC(chapter, book, (ThirdCrawler) rc);
} }
String url = chapter.getUrl(); String url = chapter.getUrl();
String charset = rc.getCharset(); String charset = rc.getCharset();
@ -95,41 +72,6 @@ public class CommonApi {
}); });
} }
private static Observable<String> 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 = 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<ConMVMap<SearchBookBean, Book>> search(String key, final ReadCrawler rc) { public static Observable<ConMVMap<SearchBookBean, Book>> search(String key, final ReadCrawler rc) {
if (rc instanceof ThirdCrawler) { if (rc instanceof ThirdCrawler) {
return searchByTC(key, (ThirdCrawler) rc); return ThirdSourceApi.searchByTC(key, (ThirdCrawler) rc);
} }
String charset = "utf-8"; String charset = "utf-8";
if (rc instanceof TianLaiReadCrawler) { if (rc instanceof TianLaiReadCrawler) {
@ -180,28 +122,7 @@ public class CommonApi {
return url.replace("{key}", key); return url.replace("{key}", key);
} }
/**
* 第三方书源搜索
*
* @param key
* @param rc
* @return
*/
public static Observable<ConMVMap<SearchBookBean, Book>> 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<List<Book>, ObservableSource<ConMVMap<SearchBookBean, Book>>>) books -> Observable.create((ObservableOnSubscribe<ConMVMap<SearchBookBean, Book>>) 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<Book> getBookInfo(final Book book, final BookInfoCrawler bic) { public static Observable<Book> getBookInfo(final Book book, final BookInfoCrawler bic) {
if (bic instanceof ThirdCrawler){ if (bic instanceof ThirdCrawler){
return getBookInfoByTC(book, (ThirdCrawler) bic); return ThirdSourceApi.getBookInfoByTC(book, (ThirdCrawler) bic);
} }
String url; String url;
url = book.getInfoUrl(); url = book.getInfoUrl();
@ -223,21 +144,7 @@ public class CommonApi {
}); });
} }
private static Observable<Book> 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获取蓝奏云可下载直链 * 通过api获取蓝奏云可下载直链

@ -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<ConMVMap<SearchBookBean, Book>> 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<List<Book>, ObservableSource<ConMVMap<SearchBookBean, Book>>>) books -> Observable.create((ObservableOnSubscribe<ConMVMap<SearchBookBean, Book>>) emitter -> {
emitter.onNext(rc.getBooks(books));
emitter.onComplete();
}));
} catch (Exception e) {
return Observable.error(e);
}
}
protected static Observable<Book> 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<List<Chapter>> 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<String> 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 = 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<String, String> getCookies(BookSource bookSource){
Map<String, String> cookieMap = new HashMap<>();
if (bookSource != null){
CookieBean cookie = DbManager.getDaoSession().getCookieBeanDao().load(bookSource.getSourceUrl());
if (cookie != null) {
cookieMap.put("Cookie", cookie.getCookie());
}
}
return cookieMap;
}
}

@ -1,9 +1,12 @@
package xyz.fycz.myreader.webapi.crawler.base; package xyz.fycz.myreader.webapi.crawler.base;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import io.reactivex.Observable;
import xyz.fycz.myreader.entity.SearchBookBean; 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.Book;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.model.mulvalmap.ConMVMap; import xyz.fycz.myreader.model.mulvalmap.ConMVMap;
@ -33,4 +36,19 @@ public abstract class BaseReadCrawler implements ReadCrawler {
public String getContentFormHtml(String html) { public String getContentFormHtml(String html) {
return null; return null;
} }
@Override
public Observable<ConMVMap<SearchBookBean, Book>> getBooksFromStrResponse(StrResponse response) {
return null;
}
@Override
public Observable<List<Chapter>> getChaptersFromStrResponse(StrResponse response) {
return null;
}
@Override
public Observable<String> getContentFormStrResponse(StrResponse response) {
return null;
}
} }

@ -1,11 +1,14 @@
package xyz.fycz.myreader.webapi.crawler.base; package xyz.fycz.myreader.webapi.crawler.base;
import io.reactivex.Observable;
import xyz.fycz.myreader.entity.SearchBookBean; 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.Book;
import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.Chapter;
import xyz.fycz.myreader.model.mulvalmap.ConMVMap; import xyz.fycz.myreader.model.mulvalmap.ConMVMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -20,7 +23,14 @@ public interface ReadCrawler {
String getNameSpace(); // 书源主页地址 String getNameSpace(); // 书源主页地址
Boolean isPost(); // 是否以post请求搜索 Boolean isPost(); // 是否以post请求搜索
Map<String, String> getHeaders();// 自定义请求头,可添加cookie等 Map<String, String> getHeaders();// 自定义请求头,可添加cookie等
// 旧版本
ConMVMap<SearchBookBean, Book> getBooksFromSearchHtml(String html); // 搜索书籍规则 ConMVMap<SearchBookBean, Book> getBooksFromSearchHtml(String html); // 搜索书籍规则
ArrayList<Chapter> getChaptersFromHtml(String html); // 获取书籍章节列表规则 ArrayList<Chapter> getChaptersFromHtml(String html); // 获取书籍章节列表规则
String getContentFormHtml(String html); // 获取书籍内容规则 String getContentFormHtml(String html); // 获取书籍内容规则
// 新版本
Observable<ConMVMap<SearchBookBean, Book>> getBooksFromStrResponse(StrResponse response); // 搜索书籍规则
Observable<List<Chapter>> getChaptersFromStrResponse(StrResponse response); // 获取书籍章节列表规则
Observable<String> getContentFormStrResponse(StrResponse response); // 获取书籍内容规则
} }

@ -1,25 +1,36 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_save" <item
android:id="@+id/action_save"
android:icon="@drawable/ic_save" android:icon="@drawable/ic_save"
app:showAsAction="always" android:title="@string/save"
android:title="@string/save"/> app:showAsAction="always" />
<item android:id="@+id/action_debug" <item
android:id="@+id/action_debug"
android:icon="@drawable/ic_debug" android:icon="@drawable/ic_debug"
app:showAsAction="always" android:title="@string/debug"
android:title="@string/debug"> app:showAsAction="always">
<menu> <menu>
<item android:id="@+id/action_debug_search" <item
android:title="@string/debug_search"/> android:id="@+id/action_debug_search"
<item android:id="@+id/action_debug_info" android:title="@string/debug_search" />
android:title="@string/debug_info"/> <item
<item android:id="@+id/action_debug_toc" android:id="@+id/action_debug_info"
android:title="@string/debug_toc"/> android:title="@string/debug_info" />
<item android:id="@+id/action_debug_content" <item
android:title="@string/debug_content"/> android:id="@+id/action_debug_toc"
android:title="@string/debug_toc" />
<item
android:id="@+id/action_debug_content"
android:title="@string/debug_content" />
</menu> </menu>
</item> </item>
<item
android:id="@+id/action_login"
android:title="@string/text_login"
app:showAsAction="never" />
</menu> </menu>
Loading…
Cancel
Save