From 1e30cf0629acbf1e0955c6a8ec8573f39c79fbe1 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Fri, 14 May 2021 20:07:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E4=B9=A6=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/sourcedebug/DebugEntity.java | 11 ++++++++++ .../xyz/fycz/myreader/model/SearchEngine.java | 20 ++----------------- .../ui/activity/BookDetailedActivity.java | 12 ++++++++--- .../ui/activity/SourceEditActivity.java | 20 +++++++++++++++++++ .../xyz/fycz/myreader/webapi/CommonApi.java | 14 +++++++++++-- .../fycz/myreader/widget/page/PageLoader.java | 2 +- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/entity/sourcedebug/DebugEntity.java b/app/src/main/java/xyz/fycz/myreader/entity/sourcedebug/DebugEntity.java index 96c4b47..305de02 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/sourcedebug/DebugEntity.java +++ b/app/src/main/java/xyz/fycz/myreader/entity/sourcedebug/DebugEntity.java @@ -18,6 +18,7 @@ public class DebugEntity implements Parcelable { private int debugMode; private BookSource bookSource; private String url; + private String key; private String parseResult; private String html; @@ -28,6 +29,7 @@ public class DebugEntity implements Parcelable { debugMode = in.readInt(); bookSource = in.readParcelable(BookSource.class.getClassLoader()); url = in.readString(); + key = in.readString(); parseResult = in.readString(); html = in.readString(); } @@ -37,6 +39,7 @@ public class DebugEntity implements Parcelable { dest.writeInt(debugMode); dest.writeParcelable(bookSource, flags); dest.writeString(url); + dest.writeString(key); dest.writeString(parseResult); dest.writeString(html); } @@ -82,6 +85,14 @@ public class DebugEntity implements Parcelable { this.url = url; } + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + public String getParseResult() { return parseResult; } diff --git a/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java b/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java index 40d9e0f..c282310 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java +++ b/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java @@ -137,15 +137,7 @@ public class SearchEngine { searchSiteIndex++; if (searchSiteIndex < mSourceList.size()) { ReadCrawler crawler = mSourceList.get(searchSiteIndex); - String searchKey = keyword; - if (crawler.getSearchCharset() != null && crawler.getSearchCharset().toLowerCase().equals("gbk")) { - try { - searchKey = URLEncoder.encode(keyword, crawler.getSearchCharset()); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - CommonApi.search(searchKey, crawler) + CommonApi.search(keyword, crawler) .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer>() { @@ -191,15 +183,7 @@ public class SearchEngine { searchSiteIndex++; if (searchSiteIndex < mSourceList.size()) { ReadCrawler crawler = mSourceList.get(searchSiteIndex); - String searchKey = title; - if (crawler.getSearchCharset().toLowerCase().equals("gbk")) { - try { - searchKey = URLEncoder.encode(title, crawler.getSearchCharset()); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - CommonApi.search(searchKey, crawler) + CommonApi.search(title, crawler) .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer>() { 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 8d3e5e3..b8e6fc1 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 @@ -106,6 +106,7 @@ public class BookDetailedActivity extends BaseActivity { private BookGroupDialog mBookGroupDia; private List tagList = new ArrayList<>(); private Disposable chaptersDis; + private boolean thirdSource; @SuppressLint("HandlerLeak") private Handler mHandler = new Handler() { @@ -174,6 +175,7 @@ public class BookDetailedActivity extends BaseActivity { } mBookGroupDia = new BookGroupDialog(this); mReadCrawler = ReadCrawlerUtil.getReadCrawler(mBook.getSource()); + thirdSource = mReadCrawler instanceof ThirdCrawler; } private void initTagList() { @@ -208,7 +210,7 @@ public class BookDetailedActivity extends BaseActivity { binding.ic.bookDetailRvCatalog.setLayoutManager(new LinearLayoutManager(this)); binding.ic.bookDetailRvCatalog.setAdapter(mCatalogAdapter); - initChapters(false); + if (!thirdSource) initChapters(false); mCatalogAdapter.setOnItemClickListener((view, pos) -> { mBook.setHisttoryChapterNum(mChapters.size() - pos - 1); @@ -401,7 +403,7 @@ public class BookDetailedActivity extends BaseActivity { BookSource source = BookSourceManager.getBookSourceByStr(mBook.getSource()); binding.ih.bookDetailSource.setText(String.format("书源:%s", source.getSourceName())); ReadCrawler rc = ReadCrawlerUtil.getReadCrawler(source); - if (rc instanceof BookInfoCrawler && StringHelper.isEmpty(mBook.getImgUrl())) { + if ((rc instanceof BookInfoCrawler && StringHelper.isEmpty(mBook.getImgUrl())) || thirdSource) { binding.pbLoading.setVisibility(View.VISIBLE); BookInfoCrawler bic = (BookInfoCrawler) rc; CommonApi.getBookInfo(mBook, bic).compose(RxUtils::toSimpleSingle).subscribe(new MyObserver() { @@ -410,6 +412,9 @@ public class BookDetailedActivity extends BaseActivity { if (!App.isDestroy(BookDetailedActivity.this)) { mHandler.sendMessage(mHandler.obtainMessage(4)); } + if (thirdSource){ + initChapters(false); + } } @Override @@ -477,7 +482,8 @@ public class BookDetailedActivity extends BaseActivity { @Override public void onError(Throwable e) { binding.pbLoading.setVisibility(View.GONE); - ToastUtils.showError("最新章节加载失败!"); + mCatalogAdapter.clear(); + ToastUtils.showError("最新章节加载失败,请尝试重新加载!"); if (App.isDebug()) e.printStackTrace(); } }); 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 67ca03d..d0365a5 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,6 +5,8 @@ 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; @@ -138,6 +140,17 @@ public class SourceEditActivity extends BaseActivity { @Override public void onTabReselected(TabLayout.Tab tab) { + } + }); + binding.sSourceType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + invalidateOptionsMenu(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } }); } @@ -148,6 +161,13 @@ public class SourceEditActivity extends BaseActivity { return true; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem debug = menu.findItem(R.id.action_debug); + debug.setVisible(!APPCONST.THIRD_SOURCE.equals(getSource().getSourceType())); + return super.onPrepareOptionsMenu(menu); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_save) { diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java b/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java index ad7e1c5..eb823eb 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/CommonApi.java @@ -2,6 +2,8 @@ package xyz.fycz.myreader.webapi; import android.text.TextUtils; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; @@ -149,19 +151,27 @@ public class CommonApi { } else { charset = rc.getCharset(); } + if (rc.getSearchCharset() != null && rc.getSearchCharset().toLowerCase().equals("gbk")) { + try { + key = URLEncoder.encode(key, rc.getSearchCharset()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } String finalCharset = charset; + String finalKey = key; return Observable.create(emitter -> { try { if (rc.isPost()) { String url = rc.getSearchLink(); String[] urlInfo = url.split(","); url = urlInfo[0]; - String body = makeSearchUrl(urlInfo[1], key); + String body = makeSearchUrl(urlInfo[1], finalKey); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); RequestBody requestBody = RequestBody.create(mediaType, body); emitter.onNext(rc.getBooksFromSearchHtml(OkHttpUtils.getHtml(url, requestBody, finalCharset, rc.getHeaders()))); } else { - emitter.onNext(rc.getBooksFromSearchHtml(OkHttpUtils.getHtml(makeSearchUrl(rc.getSearchLink(), key), finalCharset, rc.getHeaders()))); + emitter.onNext(rc.getBooksFromSearchHtml(OkHttpUtils.getHtml(makeSearchUrl(rc.getSearchLink(), finalKey), finalCharset, rc.getHeaders()))); } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java index 6ba81ee..9efa66e 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java @@ -1673,7 +1673,7 @@ public abstract class PageLoader { } // 重置段落 if (!showTitle) { - paragraph = StringUtils.trim(paragraph); + paragraph = StringUtils.trim(paragraph.replace("\t", "")); // 如果只有换行符,那么就不执行 if (paragraph.equals("")) continue; paragraph = indent + paragraph + "\n";