From 6e77f4ae72f51a933d37d9718e4e19395484c8c7 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sun, 23 Jan 2022 19:15:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=AF=BC=E5=85=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8=E8=93=9D=E5=A5=8F=E4=BA=91=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sourceAnalyzer/BookSourceManager.java | 15 +++++++++++++- .../myreader/ui/activity/AboutActivity.java | 12 ++--------- .../ui/fragment/DIYSourceFragment.java | 2 +- .../myreader/util/utils/ClipBoardUtil.java | 20 ++++++++++++------- .../xyz/fycz/myreader/webapi/LanZouApi.kt | 17 +++++++++++++++- .../fycz/myreader/webapi/Third3SourceApi.kt | 2 +- 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java index 8a0eac3..7e7839f 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java +++ b/app/src/main/java/xyz/fycz/myreader/model/sourceAnalyzer/BookSourceManager.java @@ -4,6 +4,8 @@ import android.database.Cursor; import android.text.TextUtils; import android.util.Log; +import androidx.annotation.NonNull; + import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -11,8 +13,10 @@ import java.util.List; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableSource; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; +import io.reactivex.functions.Function; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.entity.thirdsource.BookSource3Bean; @@ -34,6 +38,7 @@ import xyz.fycz.myreader.util.utils.NetworkUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.RxUtils; import xyz.fycz.myreader.util.utils.StringUtils; +import xyz.fycz.myreader.webapi.LanZouApi; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; @@ -192,7 +197,7 @@ public class BookSourceManager { DbManager.getDaoSession().getBookSourceDao().deleteInTx(sources); } - public static boolean isBookSourceExist(BookSource source){ + public static boolean isBookSourceExist(BookSource source) { if (source == null) return false; return DbManager.getDaoSession().getBookSourceDao().load(source.getSourceUrl()) != null; } @@ -320,6 +325,14 @@ public class BookSourceManager { } else if (new File(string).isFile()) { return importSource(FileUtils.readText(string)); } + if (string.contains("lanzou")) { + return LanZouApi.INSTANCE.getUrl(string) + .flatMap((Function>) s -> Observable.create(emitter -> { + emitter.onNext(OkHttpUtils.getHtml(s)); + emitter.onComplete(); + })).flatMap(BookSourceManager::importBookSourceFromJson) + .compose(RxUtils::toSimpleSingle); + } if (NetworkUtils.isUrl(string)) { String finalString = string; return Observable.create((ObservableEmitter e) -> e.onNext(OkHttpUtils.getHtml(finalString))) diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java index 7377d84..8b84b95 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java @@ -119,16 +119,8 @@ public class AboutActivity extends BaseActivity { String[] str = new String[1]; MyAlertDialog.createInputDia(this, getString(R.string.lan_zou_parse), "格式:链接+逗号+密码(没有密码就不用填)", "", true, - 100, text -> str[0] = text.replaceAll("\\s", ""), (dialog, which) -> { - String url, pwd = ""; - if (str[0].contains(",") || str[0].contains(",") || str[0].contains("密码:")) { - String[] strs = str[0].split(",|,|密码:"); - url = strs[0]; - pwd = strs[1]; - } else { - url = str[0]; - } - LanZouApi.INSTANCE.getUrl(url, pwd) + 100, text -> str[0] = text, (dialog, which) -> { + LanZouApi.INSTANCE.getUrl(str[0]) .compose(RxUtils::toSimpleSingle) .subscribe(new MyObserver() { @Override 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 236861b..dee88ce 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 @@ -257,7 +257,7 @@ public class DIYSourceFragment extends BaseFragment { @Override public void onError(Throwable e) { - ToastUtils.showError("书源格式错误,请导入正确的书源"); + ToastUtils.showError("书源格式错误,请导入正确的书源\n" + e.getLocalizedMessage()); dialog.dismiss(); } }); diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/ClipBoardUtil.java b/app/src/main/java/xyz/fycz/myreader/util/utils/ClipBoardUtil.java index af2ea87..69010f8 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/ClipBoardUtil.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/ClipBoardUtil.java @@ -10,6 +10,8 @@ import android.content.ClipboardManager; import android.content.Context; import android.text.TextUtils; +import xyz.fycz.myreader.util.ToastUtils; + /** * 剪切板读写工具 */ @@ -20,15 +22,19 @@ public class ClipBoardUtil { * @return */ public static String paste(Context context) { - ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - if (manager != null) { - if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) { - CharSequence addedText = manager.getPrimaryClip().getItemAt(0).getText(); - String addedTextString = String.valueOf(addedText); - if (!TextUtils.isEmpty(addedTextString)) { - return addedTextString; + try { + ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + if (manager != null) { + if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) { + CharSequence addedText = manager.getPrimaryClip().getItemAt(0).getText(); + String addedTextString = String.valueOf(addedText); + if (!TextUtils.isEmpty(addedTextString)) { + return addedTextString; + } } } + } catch (Exception e) { + ToastUtils.showError("" + e.getLocalizedMessage()); } return ""; } diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt b/app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt index 264405d..189dba6 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt +++ b/app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt @@ -10,6 +10,7 @@ import xyz.fycz.myreader.util.help.StringHelper import xyz.fycz.myreader.util.utils.GSON import xyz.fycz.myreader.util.utils.OkHttpUtils import xyz.fycz.myreader.util.utils.fromJsonObject +import xyz.fycz.myreader.util.utils.splitNotBlank import java.net.HttpURLConnection import java.net.URL import java.util.* @@ -19,13 +20,27 @@ import java.util.* * @date 2022/1/22 18:50 */ object LanZouApi { + + fun getUrl(url: String): Observable { + url.replace("\\s".toRegex(), "").let { + val regex = ",|,|密码:".toRegex() + if (it.contains(regex)) { + it.split(regex).let { arr -> + return getUrl(arr[0], arr[1]) + } + } else { + return getUrl(it, "") + } + } + } + /** * 通过api获取蓝奏云可下载直链 * * @param url * @param password */ - fun getUrl(url: String, password: String = ""): Observable { + private fun getUrl(url: String, password: String = ""): Observable { return Observable.create { val html = OkHttpUtils.getHtml(url) val url2 = if (password.isEmpty()) { diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt b/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt index 16bfff6..08a6cc9 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt +++ b/app/src/main/java/xyz/fycz/myreader/webapi/Third3SourceApi.kt @@ -101,7 +101,7 @@ object Third3SourceApi : AndroidViewModel(App.getApplication()) { fun findBook(url: String, fc: Third3FindCrawler, page: Int): Observable> { return Observable.create { emitter -> - if (!url.contains("{{page}}") && page > 1){ + if (!url.contains("page") && page > 1){ emitter.onError(NoStackTraceException("没有下一页")) return@create }