pull/21/head
fengyuecanzhu 3 years ago
parent df2cd9ae2b
commit ddf12a7120
  1. 4
      app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java
  2. 3
      app/src/main/java/xyz/fycz/myreader/ui/adapter/holder/SourceExchangeHolder.java
  3. 25
      app/src/main/java/xyz/fycz/myreader/ui/dialog/SourceExchangeDialog.java
  4. 14
      app/src/main/java/xyz/fycz/myreader/webapi/BookApi.java
  5. 7
      app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt
  6. 6
      app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java

@ -143,7 +143,7 @@ public class SearchEngine {
searchSiteIndex++;
if (searchSiteIndex < mSourceList.size()) {
ReadCrawler crawler = mSourceList.get(searchSiteIndex);
BookApi.search(keyword, crawler)
BookApi.search(keyword, crawler, executorService)
.subscribeOn(scheduler)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ConMVMap<SearchBookBean, Book>>() {
@ -191,7 +191,7 @@ public class SearchEngine {
if (searchSiteIndex < mSourceList.size()) {
ReadCrawler crawler = mSourceList.get(searchSiteIndex);
String searchKey = title;
BookApi.search(searchKey, crawler)
BookApi.search(searchKey, crawler, executorService)
.subscribeOn(scheduler)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ConMVMap<SearchBookBean, Book>>() {

@ -43,7 +43,8 @@ public class SourceExchangeHolder extends ViewHolderImpl<Book> {
sourceTvTitle.setText(BookSourceManager.getSourceNameByStr(data.getSource()));
sourceTvChapter.setText(data.getNewestChapterTitle());
if ((data.getInfoUrl() != null && data.getInfoUrl().equals(dialog.getmShelfBook().getInfoUrl())||
data.getChapterUrl() != null && data.getChapterUrl().equals(dialog.getmShelfBook().getChapterUrl()))) {
data.getChapterUrl() != null && data.getChapterUrl().equals(dialog.getmShelfBook().getChapterUrl()))&&
(data.getSource() != null && data.getSource().equals(dialog.getmShelfBook().getSource()))) {
sourceIv.setVisibility(View.VISIBLE);
dialog.setSourceIndex(pos);
} else {

@ -64,15 +64,16 @@ public class SourceExchangeDialog extends Dialog {
this.mShelfBook = mShelfBook;
}
public void setABooks(List<Book> aBooks){
public void setABooks(List<Book> aBooks) {
this.aBooks = aBooks;
}
public void setSourceIndex(int sourceIndex){
public void setSourceIndex(int sourceIndex) {
this.sourceIndex = sourceIndex;
}
public int getSourceIndex() {
if (sourceIndex == -1){
if (sourceIndex == -1) {
for (int i = 0; i < aBooks.size(); i++) {
Book book = aBooks.get(i);
if (book.getSource().equals(mShelfBook.getSource())) {
@ -84,7 +85,7 @@ public class SourceExchangeDialog extends Dialog {
return sourceIndex == -1 ? 0 : sourceIndex;
}
public boolean hasCurBookSource(){
public boolean hasCurBookSource() {
return getSourceIndex() == sourceIndex;
}
@ -92,7 +93,9 @@ public class SourceExchangeDialog extends Dialog {
this.listener = listener;
}
public List<Book> getaBooks(){return aBooks;}
public List<Book> getaBooks() {
return aBooks;
}
public Book getmShelfBook() {
return mShelfBook;
@ -115,7 +118,7 @@ public class SourceExchangeDialog extends Dialog {
if (aBooks.size() == 0) {
searchEngine.search(mShelfBook.getName(), mShelfBook.getAuthor());
binding.rpb.setIsAutoLoading(true);
}else {
} else {
if (mAdapter.getItemCount() == 0) {
mAdapter.addItems(aBooks);
}
@ -182,7 +185,7 @@ public class SourceExchangeDialog extends Dialog {
if (TextUtils.isEmpty(sourceSearchStr)) {
mAdapter.addItem(bean);
} else {
if (BookSourceManager.getSourceNameByStr(bean.getSource()).contains(sourceSearchStr)){
if (BookSourceManager.getSourceNameByStr(bean.getSource()).contains(sourceSearchStr)) {
mAdapter.addItem(bean);
}
}
@ -205,8 +208,10 @@ public class SourceExchangeDialog extends Dialog {
searchEngine.stopSearch();
return;
}
if ((mShelfBook.getInfoUrl() != null && mShelfBook.getInfoUrl().equals(newBook.getInfoUrl())||
mShelfBook.getChapterUrl() != null && mShelfBook.getChapterUrl().equals(newBook.getChapterUrl()))) return;
if ((mShelfBook.getInfoUrl() != null && mShelfBook.getInfoUrl().equals(newBook.getInfoUrl()) ||
mShelfBook.getChapterUrl() != null && mShelfBook.getChapterUrl().equals(newBook.getChapterUrl())) &&
(mShelfBook.getSource() != null && mShelfBook.getSource().equals(newBook.getSource())))
return;
mShelfBook = newBook;
listener.onSourceChanged(newBook, pos);
mAdapter.getItem(pos).setNewestChapterId("true");
@ -245,7 +250,7 @@ public class SourceExchangeDialog extends Dialog {
});
}
public void stopSearch(){
public void stopSearch() {
if (searchEngine != null) {
searchEngine.stopSearch();
}

@ -5,6 +5,7 @@ import java.net.URLEncoder;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
@ -30,14 +31,20 @@ import static xyz.fycz.myreader.util.utils.OkHttpUtils.getCookies;
public class BookApi {
/**
* 搜索小说
*
* @param key
*/
public static Observable<ConMVMap<SearchBookBean, Book>> search(String key, final ReadCrawler rc) {
return search(key, rc, null);
}
public static Observable<ConMVMap<SearchBookBean, Book>> search(String key, final ReadCrawler rc, ExecutorService searchPool) {
if (rc instanceof ThirdCrawler) {
return ThirdSourceApi.searchByTC(key, (ThirdCrawler) rc);
return ThirdSourceApi.searchByTC(key, (ThirdCrawler) rc, searchPool);
}
String charset = "utf-8";
if (rc instanceof TianLaiReadCrawler) {
@ -147,10 +154,11 @@ public class BookApi {
public static Observable<List<Book>> findBooks(FindKind kind, FindCrawler findCrawler, int page) {
if (findCrawler instanceof ThirdFindCrawler){
if (findCrawler instanceof ThirdFindCrawler) {
return ThirdSourceApi.findBook(kind.getUrl(), (ThirdFindCrawler) findCrawler, page);
}
if (kind.getMaxPage() > 0 && page > kind.getMaxPage()) return Observable.just(Collections.EMPTY_LIST);
if (kind.getMaxPage() > 0 && page > kind.getMaxPage())
return Observable.just(Collections.EMPTY_LIST);
String url = kind.getUrl().replace("{page}", page + "");
return Observable.create((ObservableOnSubscribe<StrResponse>) emitter -> {
emitter.onNext(OkHttpUtils.getStrResponse(url, null, null));

@ -3,6 +3,8 @@ package xyz.fycz.myreader.webapi
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import io.reactivex.Observable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher
import xyz.fycz.myreader.application.App
import xyz.fycz.myreader.entity.SearchBookBean
import xyz.fycz.myreader.greendao.entity.Book
@ -12,6 +14,7 @@ import xyz.fycz.myreader.model.third3.NoStackTraceException
import xyz.fycz.myreader.model.third3.webBook.WebBook
import xyz.fycz.myreader.webapi.crawler.source.Third3Crawler
import xyz.fycz.myreader.webapi.crawler.source.find.Third3FindCrawler
import java.util.concurrent.ExecutorService
/**
* @author fengyue
@ -22,7 +25,8 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) {
fun searchByT3C(
key: String,
rc: Third3Crawler
rc: Third3Crawler,
searchPool: ExecutorService? = null
): Observable<ConMVMap<SearchBookBean, Book>> {
return Observable.create { emitter ->
WebBook.searchBook(
@ -30,6 +34,7 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) {
rc.source,
key,
1,
searchPool?.asCoroutineDispatcher() ?: Dispatchers.IO
).timeout(30000L)
.onSuccess {
emitter.onNext(rc.getBooks(it))

@ -5,6 +5,7 @@ import android.text.TextUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.regex.Matcher;
import io.reactivex.Observable;
@ -45,8 +46,11 @@ public class ThirdSourceApi {
* @return
*/
protected static Observable<ConMVMap<SearchBookBean, Book>> searchByTC(String key, final ThirdCrawler rc) {
return searchByTC(key, rc, null);
}
protected static Observable<ConMVMap<SearchBookBean, Book>> searchByTC(String key, final ThirdCrawler rc, ExecutorService searchPool) {
if (rc instanceof Third3Crawler) {
return Third3SourceApi.INSTANCE.searchByT3C(key, (Third3Crawler) rc);
return Third3SourceApi.INSTANCE.searchByT3C(key, (Third3Crawler) rc, searchPool);
}
try {
Map<String, String> headers = rc.getHeaders();

Loading…
Cancel
Save