diff --git a/app/build.gradle b/app/build.gradle index 071ecaf..871e746 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -208,7 +208,7 @@ dependencies { } greendao { - schemaVersion 24 + schemaVersion 26 daoPackage 'xyz.fycz.myreader.greendao.gen' // targetGenDir 'src/main/java' } diff --git a/app/src/main/java/xyz/fycz/myreader/application/App.java b/app/src/main/java/xyz/fycz/myreader/application/App.java index 71d713b..514b0ae 100644 --- a/app/src/main/java/xyz/fycz/myreader/application/App.java +++ b/app/src/main/java/xyz/fycz/myreader/application/App.java @@ -48,7 +48,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.URLCONST; import xyz.fycz.myreader.entity.Setting; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.activity.MainActivity; import xyz.fycz.myreader.ui.dialog.APPDownloadTip; import xyz.fycz.myreader.ui.dialog.DialogCreator; diff --git a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java index 171e40f..4b8c0b0 100644 --- a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java +++ b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java @@ -44,6 +44,7 @@ public class APPCONST { public static final String MATCHER = "Matcher"; public static final String XPATH = "Xpath"; public static final String JSON_PATH = "JsonPath"; + public static final String THIRD_SOURCE = "ThirdSource"; public static final String BOOK = "book"; public static final String TITLE = "title"; diff --git a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSource3Bean.java b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSource3Bean.java index 89ff0a8..37187ec 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSource3Bean.java +++ b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSource3Bean.java @@ -263,4 +263,8 @@ public class BookSource3Bean { userAgent // httpUserAgent ); } + + public String getBookSourceComment() { + return bookSourceComment; + } } diff --git a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSourceBean.java b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSourceBean.java index a0c7ec1..9d2ef39 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSourceBean.java +++ b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/BookSourceBean.java @@ -22,19 +22,14 @@ import static android.text.TextUtils.isEmpty; * Created by GKF on 2017/12/14. * 书源信息 */ -@Entity public class BookSourceBean implements Cloneable { - @Id private String bookSourceUrl; private String bookSourceName; private String bookSourceGroup; private String bookSourceType; private String loginUrl; private Long lastUpdateTime; - @OrderBy private int serialNumber; - @OrderBy - @NotNull private int weight = 0; private boolean enable; //发现规则 @@ -78,10 +73,8 @@ public class BookSourceBean implements Cloneable { private String ruleBookContentReplace; private String httpUserAgent; - @Transient private transient ArrayList groupList; - @Generated(hash = 243497779) public BookSourceBean(String bookSourceUrl, String bookSourceName, String bookSourceGroup, String bookSourceType, String loginUrl, Long lastUpdateTime, int serialNumber, int weight, boolean enable, String ruleFindUrl, String ruleFindList, String ruleFindName, String ruleFindAuthor, String ruleFindKind, String ruleFindIntroduce, String ruleFindLastChapter, String ruleFindCoverUrl, String ruleFindNoteUrl, String ruleSearchUrl, String ruleSearchList, String ruleSearchName, String ruleSearchAuthor, String ruleSearchKind, String ruleSearchIntroduce, String ruleSearchLastChapter, String ruleSearchCoverUrl, String ruleSearchNoteUrl, String ruleBookUrlPattern, 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 new file mode 100644 index 0000000..b5ec3fe --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/entity/thirdsource/ThirdSourceUtil.java @@ -0,0 +1,100 @@ +package xyz.fycz.myreader.entity.thirdsource; + +import java.util.ArrayList; +import java.util.List; + +import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.greendao.entity.rule.BookSource; +import xyz.fycz.myreader.greendao.entity.rule.ContentRule; +import xyz.fycz.myreader.greendao.entity.rule.FindRule; +import xyz.fycz.myreader.greendao.entity.rule.InfoRule; +import xyz.fycz.myreader.greendao.entity.rule.SearchRule; +import xyz.fycz.myreader.greendao.entity.rule.TocRule; + +/** + * @author fengyue + * @date 2021/5/14 9:24 + */ +public class ThirdSourceUtil { + public static BookSource source2ToSource(BookSourceBean bean) { + BookSource bookSource = new BookSource(); + bookSource.setSourceUrl(bean.getBookSourceUrl()); + bookSource.setSourceName(bean.getBookSourceName()); + bookSource.setSourceGroup(bean.getBookSourceGroup()); + bookSource.setSourceType(APPCONST.THIRD_SOURCE); + bookSource.setLastUpdateTime(bean.getLastUpdateTime()); + bookSource.setOrderNum(bean.getSerialNumber()); + bookSource.setWeight(bean.getWeight()); + bookSource.setEnable(bean.getEnable()); + + SearchRule searchRule = new SearchRule(); + searchRule.setSearchUrl(bean.getRuleSearchUrl()); + searchRule.setList(bean.getRuleSearchList()); + searchRule.setName(bean.getRuleSearchName()); + searchRule.setAuthor(bean.getRuleSearchAuthor()); + searchRule.setType(bean.getRuleSearchKind()); + searchRule.setDesc(bean.getRuleSearchIntroduce()); + searchRule.setLastChapter(bean.getRuleSearchLastChapter()); + searchRule.setImgUrl(bean.getRuleSearchCoverUrl()); + searchRule.setTocUrl(bean.getRuleSearchNoteUrl()); + searchRule.setRelatedWithInfo(true); + bookSource.setSearchRule(searchRule); + + InfoRule infoRule = new InfoRule(); + infoRule.setName(bean.getRuleBookName()); + infoRule.setAuthor(bean.getRuleBookAuthor()); + infoRule.setType(bean.getRuleBookKind()); + infoRule.setDesc(bean.getRuleIntroduce()); + infoRule.setLastChapter(bean.getRuleBookLastChapter()); + infoRule.setImgUrl(bean.getRuleCoverUrl()); + infoRule.setTocUrl(bean.getRuleChapterUrl()); + bookSource.setInfoRule(infoRule); + + TocRule tocRule = new TocRule(); + tocRule.setChapterList(bean.getRuleChapterList()); + tocRule.setChapterName(bean.getRuleChapterName()); + tocRule.setChapterUrl(bean.getRuleContentUrl()); + tocRule.setTocUrlNext(bean.getRuleChapterUrlNext()); + bookSource.setTocRule(tocRule); + + ContentRule contentRule = new ContentRule(); + contentRule.setContent(bean.getRuleBookContent()); + contentRule.setContentUrlNext(bean.getRuleContentUrlNext()); + bookSource.setContentRule(contentRule); + + FindRule findRule = new FindRule(); + findRule.setUrl(bean.getRuleFindUrl()); + findRule.setBookList(bean.getRuleFindList()); + findRule.setName(bean.getRuleFindName()); + findRule.setAuthor(bean.getRuleFindAuthor()); + findRule.setType(bean.getRuleFindKind()); + findRule.setDesc(bean.getRuleFindIntroduce()); + findRule.setLastChapter(bean.getRuleFindLastChapter()); + findRule.setImgUrl(bean.getRuleFindCoverUrl()); + findRule.setTocUrl(bean.getRuleFindNoteUrl()); + bookSource.setFindRule(findRule); + return bookSource; + } + + public static BookSource source3ToSource(BookSource3Bean bean) { + BookSource bookSource = source2ToSource(bean.toBookSourceBean()); + bookSource.setSourceComment(bean.getBookSourceComment()); + return bookSource; + } + + public static List source2sToSources(List beans){ + List sources = new ArrayList<>(); + for (BookSourceBean bean : beans){ + sources.add(source2ToSource(bean)); + } + return sources; + } + + public static List source3sToSources(List beans){ + List sources = new ArrayList<>(); + for (BookSource3Bean bean : beans){ + sources.add(source3ToSource(bean)); + } + return sources; + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java index 66c452b..078eb66 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java @@ -1,6 +1,8 @@ package xyz.fycz.myreader.greendao.entity; +import android.text.TextUtils; + import androidx.annotation.Nullable; import com.google.gson.Gson; @@ -13,8 +15,12 @@ import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.util.SharedPreUtils; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; +import static xyz.fycz.myreader.common.APPCONST.MAP_STRING; + /** * 书 * Created by fengyue on 2020/08/23. @@ -70,13 +76,18 @@ public class Book implements Serializable { private long lastReadTime; - @Generated(hash = 1963023743) + private String variable; + + @Transient + private Map variableMap; + + @Generated(hash = 1284526947) public Book(String id, String name, String chapterUrl, String infoUrl, String imgUrl, String desc, String author, String type, String updateDate, String wordCount, String status, String newestChapterId, String newestChapterTitle, String newestChapterUrl, String historyChapterId, int histtoryChapterNum, int sortCode, int noReadNum, int chapterTotalNum, int lastReadPosition, String source, boolean isCloseUpdate, boolean isDownLoadAll, String groupId, int groupSort, - String tag, Boolean replaceEnable, long lastReadTime) { + String tag, Boolean replaceEnable, long lastReadTime, String variable) { this.id = id; this.name = name; this.chapterUrl = chapterUrl; @@ -105,6 +116,7 @@ public class Book implements Serializable { this.tag = tag; this.replaceEnable = replaceEnable; this.lastReadTime = lastReadTime; + this.variable = variable; } @@ -340,5 +352,28 @@ public class Book implements Serializable { public void setStatus(String status) { this.status = status; } + public void putVariable(String key, String value) { + if (variableMap == null) { + variableMap = new HashMap<>(); + } + variableMap.put(key, value); + variable = new Gson().toJson(variableMap); + } + public Map getVariableMap() { + if (variableMap == null && !TextUtils.isEmpty(variable)) { + variableMap = new Gson().fromJson(variable, MAP_STRING); + } + return variableMap; + } + + + public String getVariable() { + return this.variable; + } + + + public void setVariable(String variable) { + this.variable = variable; + } } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/FindRule.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/FindRule.java index f7d2195..a9b21be 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/FindRule.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/FindRule.java @@ -14,6 +14,7 @@ import static xyz.fycz.myreader.util.utils.StringUtils.stringEquals; * @date 2021/2/10 8:57 */ public class FindRule implements Parcelable { + private String url; private String bookList; private String name; private String author; @@ -30,6 +31,7 @@ public class FindRule implements Parcelable { } protected FindRule(Parcel in) { + url = in.readString(); bookList = in.readString(); name = in.readString(); author = in.readString(); @@ -45,6 +47,7 @@ public class FindRule implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeString(url); dest.writeString(bookList); dest.writeString(name); dest.writeString(author); @@ -75,6 +78,14 @@ public class FindRule implements Parcelable { } }; + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + public String getBookList() { return bookList; } @@ -169,7 +180,8 @@ public class FindRule implements Parcelable { if (o == null) o = new FindRule(); if (getClass() != o.getClass()) return false; FindRule findRule = (FindRule) o; - return stringEquals(bookList, findRule.bookList) && + return stringEquals(url, findRule.url) && + stringEquals(bookList, findRule.bookList) && stringEquals(name, findRule.name) && stringEquals(author, findRule.author) && stringEquals(type, findRule.type) && diff --git a/app/src/main/java/xyz/fycz/myreader/model/analyzeRule/AnalyzeRule.java b/app/src/main/java/xyz/fycz/myreader/model/analyzeRule/AnalyzeRule.java index 9b3a2a0..0d2ebac 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/analyzeRule/AnalyzeRule.java +++ b/app/src/main/java/xyz/fycz/myreader/model/analyzeRule/AnalyzeRule.java @@ -1,8 +1,34 @@ package xyz.fycz.myreader.model.analyzeRule; +import android.annotation.SuppressLint; + import androidx.annotation.Keep; +import com.google.gson.Gson; + +import org.jsoup.nodes.Entities; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.script.SimpleBindings; + +import xyz.fycz.myreader.greendao.entity.Book; +import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.help.JsExtensions; +import xyz.fycz.myreader.util.utils.NetworkUtils; +import xyz.fycz.myreader.util.utils.StringUtils; + +import static xyz.fycz.myreader.common.APPCONST.EXP_PATTERN; +import static xyz.fycz.myreader.common.APPCONST.JS_PATTERN; +import static xyz.fycz.myreader.common.APPCONST.MAP_STRING; +import static xyz.fycz.myreader.common.APPCONST.SCRIPT_ENGINE; +import static xyz.fycz.myreader.util.StringHelper.isEmpty; +import static xyz.fycz.myreader.util.utils.NetworkUtils.headerPattern; /** @@ -12,10 +38,10 @@ import xyz.fycz.myreader.util.help.JsExtensions; @Keep @SuppressWarnings({"unused", "WeakerAccess"}) public class AnalyzeRule implements JsExtensions { - /*private static final Pattern putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE); + private static final Pattern putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE); private static final Pattern getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE); - private BaseBookBean book; + private Book book; private Object object; private Boolean isJSON = false; private String baseUrl = null; @@ -28,11 +54,11 @@ public class AnalyzeRule implements JsExtensions { private boolean objectChangedJS = false; private boolean objectChangedJP = false; - public AnalyzeRule(BaseBookBean bookBean) { + public AnalyzeRule(Book bookBean) { book = bookBean; } - public void setBook(BaseBookBean book) { + public void setBook(Book book) { this.book = book; } @@ -61,9 +87,9 @@ public class AnalyzeRule implements JsExtensions { return this.baseUrl; } - *//** + /** * 获取XPath解析类 - *//* + */ private AnalyzeByXPath getAnalyzeByXPath(Object o) { if (o != object) { return new AnalyzeByXPath().parse(o); @@ -80,9 +106,9 @@ public class AnalyzeRule implements JsExtensions { return analyzeByXPath; } - *//** + /** * 获取JSOUP解析类 - *//* + */ private AnalyzeByJSoup getAnalyzeByJSoup(Object o) { if (o != object) { return new AnalyzeByJSoup().parse(o); @@ -99,9 +125,9 @@ public class AnalyzeRule implements JsExtensions { return analyzeByJSoup; } - *//** + /** * 获取JSON解析类 - *//* + */ private AnalyzeByJSonPath getAnalyzeByJSonPath(Object o) { if (o != object) { return new AnalyzeByJSonPath().parse(o); @@ -118,9 +144,9 @@ public class AnalyzeRule implements JsExtensions { return analyzeByJSonPath; } - *//** + /** * 获取文本列表 - *//* + */ public List getStringList(String rule) throws Exception { return getStringList(rule, false); } @@ -180,9 +206,9 @@ public class AnalyzeRule implements JsExtensions { return (List) result; } - *//** + /** * 获取文本 - *//* + */ public String getString(String rule) throws Exception { return getString(rule, false); } @@ -235,9 +261,9 @@ public class AnalyzeRule implements JsExtensions { } } - *//** + /** * 获取Element - *//* + */ public Object getElement(String ruleStr) throws Exception { List ruleList = splitSourceRule(ruleStr); Object result = object; @@ -262,9 +288,9 @@ public class AnalyzeRule implements JsExtensions { return result; } - *//** + /** * 获取列表 - *//* + */ @SuppressWarnings("unchecked") public List getElements(String ruleStr) throws Exception { List ruleList = splitSourceRule(ruleStr); @@ -294,9 +320,9 @@ public class AnalyzeRule implements JsExtensions { return (List) result; } - *//** + /** * 保存变量 - *//* + */ private void putRule(Map map) throws Exception { for (Map.Entry entry : map.entrySet()) { if (book != null) { @@ -305,9 +331,9 @@ public class AnalyzeRule implements JsExtensions { } } - *//** + /** * 分离并执行put规则 - *//* + */ private String splitPutRule(String ruleStr) throws Exception { Matcher putMatcher = putPattern.matcher(ruleStr); while (putMatcher.find()) { @@ -318,9 +344,9 @@ public class AnalyzeRule implements JsExtensions { return ruleStr; } - *//** + /** * 替换@get - *//* + */ public String replaceGet(String ruleStr) { Matcher getMatcher = getPattern.matcher(ruleStr); while (getMatcher.find()) { @@ -334,9 +360,9 @@ public class AnalyzeRule implements JsExtensions { return ruleStr; } - *//** + /** * 正则替换 - *//* + */ private String replaceRegex(String result, SourceRule rule) { if (!isEmpty(rule.replaceRegex)) { if (rule.replaceFirst) { @@ -354,9 +380,9 @@ public class AnalyzeRule implements JsExtensions { return result; } - *//** + /** * 替换JS - *//* + */ @SuppressLint("DefaultLocale") private String replaceJs(String ruleStr) throws Exception { if (ruleStr.contains("{{") && ruleStr.contains("}}")) { @@ -379,9 +405,9 @@ public class AnalyzeRule implements JsExtensions { return ruleStr; } - *//** + /** * 分解规则生成规则列表 - *//* + */ public List splitSourceRule(String ruleStr) throws Exception { List ruleList = new ArrayList<>(); if (isEmpty(ruleStr)) return ruleList; @@ -429,9 +455,9 @@ public class AnalyzeRule implements JsExtensions { return ruleList; } - *//** + /** * 规则类 - *//* + */ public static class SourceRule { Mode mode; String rule; @@ -501,15 +527,15 @@ public class AnalyzeRule implements JsExtensions { return book.getVariableMap().get(key); } - *//** + /** * 执行JS - *//* + */ private Object evalJS(String jsStr, Object result) throws Exception { SimpleBindings bindings = new SimpleBindings(); bindings.put("java", this); bindings.put("result", result); bindings.put("baseUrl", baseUrl); return SCRIPT_ENGINE.eval(jsStr, bindings); - }*/ + } } diff --git a/app/src/main/java/xyz/fycz/myreader/model/source/BaseAnalyzer.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BaseAnalyzer.java similarity index 99% rename from app/src/main/java/xyz/fycz/myreader/model/source/BaseAnalyzer.java rename to app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BaseAnalyzer.java index 36656c1..52b5fd8 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/source/BaseAnalyzer.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BaseAnalyzer.java @@ -1,4 +1,4 @@ -package xyz.fycz.myreader.model.source; +package xyz.fycz.myreader.model.sourceAnalyzer; import android.util.Log; diff --git a/app/src/main/java/xyz/fycz/myreader/model/source/BookSourceManager.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java similarity index 78% rename from app/src/main/java/xyz/fycz/myreader/model/source/BookSourceManager.java rename to app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java index 4f2dddc..1aa9344 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/source/BookSourceManager.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java @@ -1,4 +1,4 @@ -package xyz.fycz.myreader.model.source; +package xyz.fycz.myreader.model.sourceAnalyzer; import android.database.Cursor; import android.text.TextUtils; @@ -6,7 +6,6 @@ import android.util.Log; import androidx.annotation.Nullable; -import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -19,16 +18,18 @@ 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.entity.rule.BookSource; import xyz.fycz.myreader.greendao.gen.BookSourceDao; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.FileUtils; +import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.GsonUtils; -import xyz.fycz.myreader.util.utils.MeUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.RxUtils; @@ -37,6 +38,7 @@ import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; public class BookSourceManager { + public static final int SOURCE_LENGTH = 500; public static List getEnabledBookSource() { return GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() @@ -326,43 +328,81 @@ public class BookSourceManager { } private static Observable> importBookSourceFromJson(String json) { - return Observable.create(e -> { + return Observable.create(emitter -> { List successImportSources = new ArrayList<>(); - if (StringUtils.isJsonArray(json)) { - try { - List bookSources = GsonUtils.parseJArray(json, BookSource.class); - for (BookSource bookSource : bookSources) { - if (bookSource.containsGroup("删除")) { - GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() - .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())) - .buildDelete().executeDeleteWithoutDetachingEntities(); - } else { - if (addBookSource(bookSource)) { - successImportSources.add(bookSource); - } + List bookSources = importSources(json); + if (bookSources != null) { + for (BookSource bookSource : bookSources) { + if (bookSource.containsGroup("删除")) { + GreenDaoManager.getDaoSession().getBookSourceDao().queryBuilder() + .where(BookSourceDao.Properties.SourceUrl.eq(bookSource.getSourceUrl())) + .buildDelete().executeDeleteWithoutDetachingEntities(); + } else { + if (addBookSource(bookSource)) { + successImportSources.add(bookSource); } } - e.onNext(successImportSources); - e.onComplete(); - return; - } catch (Exception ignored) { } + emitter.onNext(successImportSources); + emitter.onComplete(); + return; } - if (StringUtils.isJsonObject(json)) { - try { - BookSource bookSource = GsonUtils.parseJObject(json, BookSource.class); - if (addBookSource(bookSource)) - successImportSources.add(bookSource); - e.onNext(successImportSources); - e.onComplete(); - return; - } catch (Exception ignored) { - } - } - e.onError(new Throwable("格式不对")); + emitter.onError(new Throwable("格式不对")); }); } + private static List importSources(String json) { + if (StringUtils.isJsonArray(json)) { + try { + List sources = GsonUtils.parseJArray(json, BookSource.class); + String sourcesJson = GsonExtensionsKt.getGSON().toJson(sources); + if (sources.size() > 0 && sourcesJson.length() > sources.size() * SOURCE_LENGTH){ + return sources; + } + + List source2s = GsonUtils.parseJArray(json, BookSourceBean.class); + String source2sJson = GsonExtensionsKt.getGSON().toJson(source2s); + if (source2s.size() > 0 && source2sJson.length() > source2s.size() * SOURCE_LENGTH){ + return ThirdSourceUtil.source2sToSources(source2s); + } + List source3s = GsonUtils.parseJArray(json, BookSource3Bean.class); + String source3sJson = GsonExtensionsKt.getGSON().toJson(source3s); + if (source3s.size() > 0 && source3sJson.length() > source3s.size() * SOURCE_LENGTH){ + return ThirdSourceUtil.source3sToSources(source3s); + } + }catch (Exception e){ + e.printStackTrace(); + } + } else if (StringUtils.isJsonObject(json)) { + try { + List sources = new ArrayList<>(); + + BookSource source = GsonUtils.parseJObject(json, BookSource.class); + String sourceJson = GsonExtensionsKt.getGSON().toJson(source); + if (!StringHelper.isEmpty(sourceJson) && sourceJson.length() > SOURCE_LENGTH){ + sources.add(source); + return sources; + } + + BookSourceBean source2 = GsonUtils.parseJObject(json, BookSourceBean.class); + String source2Json = GsonExtensionsKt.getGSON().toJson(source2); + if (!StringHelper.isEmpty(source2Json) && source2Json.length() > SOURCE_LENGTH){ + sources.add(ThirdSourceUtil.source2ToSource(source2)); + return sources; + } + + BookSource3Bean source3 = GsonUtils.parseJObject(json, BookSource3Bean.class); + String source3Json = GsonExtensionsKt.getGSON().toJson(source3); + if (!StringHelper.isEmpty(source3Json) && source3Json.length() > SOURCE_LENGTH){ + sources.add(ThirdSourceUtil.source3ToSource(source3)); + return sources; + } + }catch (Exception e){ + e.printStackTrace(); + } + } + return null; + } public static void initDefaultSources() { Log.d("initDefaultSources", "execute"); @@ -383,11 +423,6 @@ public class BookSourceManager { String referenceSources = FileUtils.readAssertFile(App.getmContext(), "ReferenceSources.json"); Observable> observable = BookSourceManager.importBookSourceFromJson(referenceSources); - observable.subscribe(new MyObserver>() { - @Override - public void onNext(@NonNull List sources) { - - } - }); + observable.subscribe(); } } diff --git a/app/src/main/java/xyz/fycz/myreader/model/source/JsonPathAnalyzer.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/JsonPathAnalyzer.java similarity index 98% rename from app/src/main/java/xyz/fycz/myreader/model/source/JsonPathAnalyzer.java rename to app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/JsonPathAnalyzer.java index 5800bab..7001d4d 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/source/JsonPathAnalyzer.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/JsonPathAnalyzer.java @@ -1,4 +1,4 @@ -package xyz.fycz.myreader.model.source; +package xyz.fycz.myreader.model.sourceAnalyzer; import com.google.gson.JsonArray; import com.google.gson.JsonElement; diff --git a/app/src/main/java/xyz/fycz/myreader/model/source/MatcherAnalyzer.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/MatcherAnalyzer.java similarity index 99% rename from app/src/main/java/xyz/fycz/myreader/model/source/MatcherAnalyzer.java rename to app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/MatcherAnalyzer.java index 9126261..d828e66 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/source/MatcherAnalyzer.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/MatcherAnalyzer.java @@ -1,4 +1,4 @@ -package xyz.fycz.myreader.model.source; +package xyz.fycz.myreader.model.sourceAnalyzer; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/ThirdAnalyzer.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/ThirdAnalyzer.java new file mode 100644 index 0000000..07c5578 --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/ThirdAnalyzer.java @@ -0,0 +1,8 @@ +package xyz.fycz.myreader.model.sourceAnalyzer; + +/** + * @author fengyue + * @date 2021/5/14 9:13 + */ +public class ThirdAnalyzer { +} diff --git a/app/src/main/java/xyz/fycz/myreader/model/source/XpathAnalyzer.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/XpathAnalyzer.java similarity index 98% rename from app/src/main/java/xyz/fycz/myreader/model/source/XpathAnalyzer.java rename to app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/XpathAnalyzer.java index 3bd106c..3c569c1 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/source/XpathAnalyzer.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/XpathAnalyzer.java @@ -1,4 +1,4 @@ -package xyz.fycz.myreader.model.source; +package xyz.fycz.myreader.model.sourceAnalyzer; import org.seimicrawler.xpath.JXDocument; import org.seimicrawler.xpath.JXNode; 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 8c5049b..be96b43 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 @@ -58,7 +58,7 @@ import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.greendao.service.ChapterService; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.adapter.BookTagAdapter; import xyz.fycz.myreader.ui.adapter.DetailCatalogAdapter; import xyz.fycz.myreader.ui.dialog.BookGroupDialog; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java index d23a8de..31dc37e 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java @@ -15,7 +15,6 @@ import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityBookInfoEditBinding; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.service.BookService; -import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.UriFileUtil; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java index 123b1fd..8d34454 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java @@ -20,21 +20,17 @@ import androidx.fragment.app.FragmentTransaction; import java.io.File; import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.BaseFragment; -import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityMoreSettingBinding; import xyz.fycz.myreader.entity.Setting; import xyz.fycz.myreader.greendao.entity.Book; -import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.service.BookService; -import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MultiChoiceDialog; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java index 8563ca5..d1c809c 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java @@ -49,7 +49,7 @@ import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.service.SearchHistoryService; import xyz.fycz.myreader.model.SearchEngine; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.adapter.SearchBookAdapter; import xyz.fycz.myreader.ui.adapter.SearchHistoryAdapter; import xyz.fycz.myreader.ui.dialog.DialogCreator; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java index f43a235..67ca03d 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java @@ -5,8 +5,6 @@ import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import androidx.appcompat.widget.Toolbar; @@ -18,7 +16,6 @@ import java.net.URLEncoder; import java.util.List; import xyz.fycz.myreader.R; -import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivitySourceEditBinding; @@ -26,8 +23,7 @@ import xyz.fycz.myreader.entity.sourcedebug.DebugEntity; import xyz.fycz.myreader.entity.sourceedit.EditEntity; import xyz.fycz.myreader.entity.sourceedit.EditEntityUtil; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.greendao.entity.rule.SearchRule; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.adapter.SourceEditAdapter; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; @@ -115,9 +111,12 @@ public class SourceEditActivity extends BaseActivity { case APPCONST.XPATH: sourceType = 1; break; - case APPCONST.JSON_PATH: + case APPCONST.JSON_PATH: sourceType = 2; break; + case APPCONST.THIRD_SOURCE: + sourceType = 3; + break; } binding.sSourceType.setSelection(sourceType); } @@ -193,7 +192,7 @@ public class SourceEditActivity extends BaseActivity { e.printStackTrace(); } debugEntity.setUrl(source.getSearchRule().getSearchUrl().replace("{key}", text)); - }else { + } else { debugEntity.setUrl(text); } }, (dialog, which) -> { @@ -255,7 +254,7 @@ public class SourceEditActivity extends BaseActivity { BookSource source = entityUtil.getSource(this.source, sourceEntities); source.setEnable(binding.cbSourceEnable.isChecked()); String sourceType = APPCONST.MATCHER; - switch (binding.sSourceType.getSelectedItemPosition()){ + switch (binding.sSourceType.getSelectedItemPosition()) { case 0: sourceType = APPCONST.MATCHER; break; @@ -265,6 +264,9 @@ public class SourceEditActivity extends BaseActivity { case 2: sourceType = APPCONST.JSON_PATH; break; + case 3: + sourceType = APPCONST.THIRD_SOURCE; + break; } source.setSourceType(sourceType); source.setSearchRule(entityUtil.getSearchRule(searchEntities)); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java index 1c914c2..32d4da3 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java @@ -16,8 +16,6 @@ import java.util.ArrayList; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java index 6d647fd..e767908 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java @@ -14,8 +14,6 @@ import java.util.ArrayList; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookSourceHolder.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookSourceHolder.java index c510829..71450b8 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookSourceHolder.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookSourceHolder.java @@ -8,13 +8,9 @@ import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentActivity; -import java.io.File; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import io.reactivex.Observable; import io.reactivex.ObservableOnSubscribe; @@ -26,13 +22,10 @@ import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.common.APPCONST; -import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.ReplaceRuleManager; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.activity.SourceEditActivity; import xyz.fycz.myreader.ui.adapter.BookSourceAdapter; -import xyz.fycz.myreader.ui.dialog.ReplaceDialog; import xyz.fycz.myreader.util.ShareUtils; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookStoreBookHolder.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookStoreBookHolder.java index de0b953..157d6f8 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookStoreBookHolder.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/BookStoreBookHolder.java @@ -9,7 +9,7 @@ import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; 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 ff97bac..1092915 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 @@ -1,7 +1,6 @@ package xyz.fycz.myreader.ui.adapter.holder; import android.widget.CheckBox; -import android.widget.RelativeLayout; import android.widget.TextView; import java.util.HashMap; @@ -10,8 +9,6 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; -import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; /** 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 65e5f4e..2773cb4 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 @@ -2,16 +2,9 @@ package xyz.fycz.myreader.ui.adapter.holder; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Intent; -import android.text.TextUtils; import android.util.Log; -import android.view.View; import android.widget.TextView; -import androidx.core.content.ContextCompat; - -import com.zhy.view.flowlayout.FlowLayout; -import com.zhy.view.flowlayout.TagAdapter; import com.zhy.view.flowlayout.TagFlowLayout; import java.util.ArrayList; @@ -20,17 +13,14 @@ import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.base.adapter.ViewHolderImpl; -import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.model.SearchEngine; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.BookSourceManager; -import xyz.fycz.myreader.ui.activity.BookDetailedActivity; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.adapter.BookTagAdapter; import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.KeyWordUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java index 17aab74..9a5d67f 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java @@ -6,7 +6,7 @@ import android.widget.TextView; import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.adapter.ViewHolderImpl; import xyz.fycz.myreader.greendao.entity.Book; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; /** * @author fengyue diff --git a/app/src/main/java/xyz/fycz/myreader/ui/dialog/ReplaceDialog.java b/app/src/main/java/xyz/fycz/myreader/ui/dialog/ReplaceDialog.java index e5cf28c..d4f90c1 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/dialog/ReplaceDialog.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/dialog/ReplaceDialog.java @@ -26,7 +26,7 @@ import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.ReplaceRuleBean; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.service.BookService; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.model.ReplaceRuleManager; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.ToastUtils; 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 aa459df..c2bb111 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 @@ -8,7 +8,6 @@ import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuInflater; -import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -24,7 +23,6 @@ import java.util.List; import io.reactivex.Observable; import io.reactivex.Single; -import io.reactivex.SingleEmitter; import io.reactivex.SingleOnSubscribe; import io.reactivex.annotations.NonNull; import xyz.fycz.myreader.R; @@ -34,11 +32,9 @@ 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.entity.ReplaceRuleBean; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.gen.BookSourceDao; -import xyz.fycz.myreader.model.ReplaceRuleManager; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.activity.BookSourceActivity; import xyz.fycz.myreader.ui.activity.SourceEditActivity; import xyz.fycz.myreader.ui.adapter.BookSourceAdapter; @@ -46,7 +42,6 @@ import xyz.fycz.myreader.ui.adapter.helper.ItemTouchCallback; import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.util.ShareUtils; -import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.ClipBoardUtil; import xyz.fycz.myreader.util.utils.FileUtils; 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 db6c73f..233af9f 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 @@ -10,7 +10,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import java.util.List; import io.reactivex.Single; -import io.reactivex.SingleEmitter; import io.reactivex.SingleOnSubscribe; import io.reactivex.annotations.NonNull; import xyz.fycz.myreader.R; @@ -19,7 +18,7 @@ import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.databinding.FragmentLocalSourceBinding; import xyz.fycz.myreader.greendao.GreenDaoManager; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.ui.activity.BookSourceActivity; import xyz.fycz.myreader.ui.adapter.LocalSourceAdapter; import xyz.fycz.myreader.util.ToastUtils; diff --git a/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java b/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java index ecf2125..e216341 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java +++ b/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java @@ -9,7 +9,12 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import xyz.fycz.myreader.util.help.SSLSocketClient; +import io.reactivex.Observable; +import io.reactivex.ObservableOnSubscribe; +import okhttp3.MediaType; +import okhttp3.RequestBody; +import xyz.fycz.myreader.model.analyzeRule.AnalyzeUrl; +import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.StringUtils; @SuppressWarnings({"unused", "WeakerAccess"}) @@ -18,16 +23,40 @@ public interface JsExtensions { /** * js实现跨域访问,不能删 */ - /*default String ajax(String urlStr) { + default String ajax(String urlStr) { try { AnalyzeUrl analyzeUrl = new AnalyzeUrl(urlStr); - Response response = BaseModelImpl.getInstance().getResponseO(analyzeUrl) - .blockingFirst(); - return response.body(); + String res = Observable.create((ObservableOnSubscribe) emitter -> { + StringBuilder sb = new StringBuilder(); + for (String key : analyzeUrl.getQueryMap().keySet()){ + sb.append(key).append("=").append(analyzeUrl.getQueryMap().get(key)); + sb.append("&"); + } + sb.deleteCharAt(sb.lastIndexOf("&")); + String body = sb.toString(); + switch (analyzeUrl.getUrlMode()){ + case GET: + String url = analyzeUrl.getUrl() + "?" + body; + emitter.onNext(OkHttpUtils.getHtml(url, analyzeUrl.getCharCode(), + analyzeUrl.getHeaderMap())); + break; + case POST: + MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); + RequestBody requestBody = RequestBody.create(mediaType, body); + emitter.onNext(OkHttpUtils.getHtml(analyzeUrl.getUrl(), requestBody, + analyzeUrl.getCharCode(), analyzeUrl.getHeaderMap())); + break; + default: + emitter.onNext(OkHttpUtils.getHtml(analyzeUrl.getUrl(), + analyzeUrl.getCharCode(), analyzeUrl.getHeaderMap())); + break; + } + }).blockingFirst(); + return res; } catch (Exception e) { return e.getLocalizedMessage(); } - }*/ + } /** * js实现解码,不能删 diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java index 5511b30..82f09c5 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java @@ -7,7 +7,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.enums.LocalBookSource; import xyz.fycz.myreader.greendao.entity.rule.BookSource; -import xyz.fycz.myreader.model.source.BookSourceManager; +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; @@ -26,6 +26,7 @@ import java.util.ResourceBundle; import static xyz.fycz.myreader.common.APPCONST.JSON_PATH; import static xyz.fycz.myreader.common.APPCONST.MATCHER; +import static xyz.fycz.myreader.common.APPCONST.THIRD_SOURCE; import static xyz.fycz.myreader.common.APPCONST.XPATH; /** @@ -192,6 +193,9 @@ public class ReadCrawlerUtil { case JSON_PATH: crawler = new JsonPathCrawler(source); break; + case THIRD_SOURCE: + crawler = new JsonPathCrawler(source); + break; } if (source.getSearchRule().isRelatedWithInfo() || isInfo) { return crawler; diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseSourceCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseSourceCrawler.java index 951f17c..ca402a5 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseSourceCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/base/BaseSourceCrawler.java @@ -20,8 +20,8 @@ import xyz.fycz.myreader.greendao.entity.rule.InfoRule; import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.greendao.entity.rule.TocRule; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.BaseAnalyzer; -import xyz.fycz.myreader.model.source.MatcherAnalyzer; +import xyz.fycz.myreader.model.sourceAnalyzer.BaseAnalyzer; +import xyz.fycz.myreader.model.sourceAnalyzer.MatcherAnalyzer; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils; diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/JsonPathCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/JsonPathCrawler.java index 405f3c2..337bd40 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/JsonPathCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/JsonPathCrawler.java @@ -3,7 +3,6 @@ package xyz.fycz.myreader.webapi.crawler.source; import com.jayway.jsonpath.ReadContext; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -12,13 +11,9 @@ import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.SearchRule; -import xyz.fycz.myreader.greendao.entity.rule.TocRule; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.JsonPathAnalyzer; +import xyz.fycz.myreader.model.sourceAnalyzer.JsonPathAnalyzer; import xyz.fycz.myreader.util.StringHelper; -import xyz.fycz.myreader.util.utils.NetworkUtils; -import xyz.fycz.myreader.util.utils.OkHttpUtils; -import xyz.fycz.myreader.util.utils.StringUtils; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; /** diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/MatcherCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/MatcherCrawler.java index 8eeeb6b..ef5752a 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/MatcherCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/MatcherCrawler.java @@ -1,6 +1,5 @@ package xyz.fycz.myreader.webapi.crawler.source; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -9,10 +8,9 @@ import xyz.fycz.myreader.greendao.entity.Book; import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.MatcherAnalyzer; +import xyz.fycz.myreader.model.sourceAnalyzer.MatcherAnalyzer; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.util.utils.NetworkUtils; -import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; /** diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/XpathCrawler.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/XpathCrawler.java index d8e4569..d549cf8 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/XpathCrawler.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/source/XpathCrawler.java @@ -11,7 +11,7 @@ import xyz.fycz.myreader.greendao.entity.Chapter; import xyz.fycz.myreader.greendao.entity.rule.BookSource; import xyz.fycz.myreader.greendao.entity.rule.SearchRule; import xyz.fycz.myreader.model.mulvalmap.ConcurrentMultiValueMap; -import xyz.fycz.myreader.model.source.XpathAnalyzer; +import xyz.fycz.myreader.model.sourceAnalyzer.XpathAnalyzer; import xyz.fycz.myreader.util.StringHelper; import xyz.fycz.myreader.webapi.crawler.base.BaseSourceCrawler; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5172749..8816731 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -563,5 +563,6 @@ Matcher Xpath JsonPath + 第三方 diff --git a/app/src/test/java/Test.java b/app/src/test/java/Test.java index 533654c..25b6a1d 100644 --- a/app/src/test/java/Test.java +++ b/app/src/test/java/Test.java @@ -1,9 +1,3 @@ -import android.util.Log; - -import com.liulishuo.filedownloader.BaseDownloadTask; -import com.liulishuo.filedownloader.FileDownloadLargeFileListener; -import com.liulishuo.filedownloader.FileDownloader; - import org.seimicrawler.xpath.JXDocument; import java.io.File; @@ -13,14 +7,10 @@ import java.util.Arrays; import java.util.List; import xyz.fycz.myreader.ai.MatrixUtil; -import xyz.fycz.myreader.model.source.BaseAnalyzer; -import xyz.fycz.myreader.model.source.MatcherAnalyzer; -import xyz.fycz.myreader.ui.dialog.UpdateDialog; +import xyz.fycz.myreader.model.sourceAnalyzer.BaseAnalyzer; import xyz.fycz.myreader.util.utils.FileUtils; -import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.GsonUtils; import xyz.fycz.myreader.util.utils.NetworkUtils; -import xyz.fycz.myreader.webapi.CommonApi; /** * @author fengyue