diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java index a24f9c1..d878691 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java @@ -425,14 +425,21 @@ public class BookSource extends BaseSource implements Parcelable, Cloneable { this.concurrentRate = concurrentRate; } + @Nullable @Override - public String getHeader() { - return sourceHeaders; + public String getConcurrentRateKt() { + return concurrentRate; } + @Nullable @Override - public void setHeader(@Nullable String header) { - this.sourceHeaders = header; + public String getLoginUrlKt() { + return loginUrl; + } + + @Override + public String getHeader() { + return sourceHeaders; } @NonNull diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt index baca4fe..f4f3027 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt @@ -17,10 +17,16 @@ import javax.script.SimpleBindings @Suppress("unused") abstract class BaseSource : JsExtensions { - open var concurrentRate: String? = null // 并发率 - open var loginUrl: String? = null // 登录地址 - //var loginUi: String? // 登录UI - open var header: String? = null // 请求头 + //var concurrentRate: String? // 并发率 + //var loginUrl: String? // 登录地址 + //var loginUi: String? // 登录UI + //var header: String? // 请求头 + + open fun getConcurrentRateKt(): String? = null // 并发率 + + open fun getLoginUrlKt(): String? = null // 登录地址 + + open fun getHeader(): String? = null // 请求头 open fun getTag(): String = "" @@ -31,7 +37,7 @@ abstract class BaseSource : JsExtensions { }*/ fun getLoginJs(): String? { - val loginJs = loginUrl + val loginJs = getLoginUrlKt() return when { loginJs == null -> null loginJs.startsWith("@js:") -> loginJs.substring(4) @@ -52,7 +58,7 @@ abstract class BaseSource : JsExtensions { */ fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap().apply { this[APPCONST.UA_NAME] = APPCONST.DEFAULT_USER_AGENT - header?.let { + getHeader()?.let { GSON.fromJsonObject>( when { it.startsWith("@js:", true) -> diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/Debug.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/Debug.kt new file mode 100644 index 0000000..982a4f8 --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/Debug.kt @@ -0,0 +1,29 @@ +package xyz.fycz.myreader.model.third3 + +import android.annotation.SuppressLint +import java.text.SimpleDateFormat +import java.util.* + +/** + * @author fengyue + * @date 2022/1/21 10:42 + */ +object Debug { + var callback: Callback? = null + @SuppressLint("ConstantLocale") + private val debugTimeFormat = SimpleDateFormat("[hh:mm:ss.SSS]", Locale.getDefault()) + + fun log(msg: String) { + val time = debugTimeFormat.format(System.currentTimeMillis()) + callback?.print("$time $msg") + } + + fun log(tag: String, msg: String) { + val time = debugTimeFormat.format(System.currentTimeMillis()) + callback?.print("$time $tag:$msg") + } + + interface Callback { + fun print(msg: String) + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt index 2edf7eb..234b91c 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt @@ -10,7 +10,6 @@ import xyz.fycz.myreader.common.APPCONST.JS_PATTERN_3 import xyz.fycz.myreader.common.APPCONST.SCRIPT_ENGINE 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.service.CacheManager import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.model.third3.BaseSource diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt index fdae768..daec372 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt @@ -9,7 +9,6 @@ import okhttp3.Response import xyz.fycz.myreader.common.APPCONST.* 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.service.CacheManager import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.model.third3.BaseSource @@ -280,7 +279,7 @@ class AnalyzeUrl( */ private fun fetchStart(): ConcurrentRecord? { source ?: return null - val concurrentRate = source.concurrentRate + val concurrentRate = source.getConcurrentRateKt() if (concurrentRate.isNullOrEmpty()) { return null } diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt index d1ea8ff..787500e 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt @@ -12,10 +12,10 @@ import org.jsoup.Connection import org.jsoup.Jsoup import xyz.fycz.myreader.application.App import xyz.fycz.myreader.common.APPCONST -import xyz.fycz.myreader.greendao.entity.rule.BookSource import xyz.fycz.myreader.greendao.service.CacheManager import xyz.fycz.myreader.greendao.service.CookieStore import xyz.fycz.myreader.model.third3.BaseSource +import xyz.fycz.myreader.model.third3.Debug import xyz.fycz.myreader.model.third3.http.* import xyz.fycz.myreader.util.ZipUtils import xyz.fycz.myreader.util.utils.* @@ -484,9 +484,9 @@ interface JsExtensions { * 输出调试日志 */ fun log(msg: String): String { - /*getSource()?.let { - Debug.log(it.sourceUrl, msg) - } ?: Debug.log(msg)*/ + getSource()?.let { + Debug.log(it.getKey(), msg) + } ?: Debug.log(msg) if (App.isDebug()) { Log.d(TAG + "-" + getSource()?.getKey(), msg) } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java index b3bc7b0..3878bef 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java @@ -1,6 +1,7 @@ package xyz.fycz.myreader.ui.activity; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -27,6 +28,7 @@ import okhttp3.RequestBody; import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.observer.MyObserver; +import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivitySourceDebugBinding; import xyz.fycz.myreader.entity.SearchBookBean; import xyz.fycz.myreader.entity.StrResponse; @@ -36,7 +38,9 @@ import xyz.fycz.myreader.entity.sourcedebug.DebugEntity; import xyz.fycz.myreader.entity.sourcedebug.ListResult; 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.ConMVMap; +import xyz.fycz.myreader.model.third3.Debug; import xyz.fycz.myreader.ui.dialog.LoadingDialog; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.NetworkUtils; @@ -63,6 +67,8 @@ public class SourceDebugActivity extends BaseActivity { private ReadCrawler rc; private Disposable disposable; private LoadingDialog loadingDialog; + private boolean isThird3; + private StringBuilder logSb; @Override protected void bindView() { @@ -96,12 +102,20 @@ public class SourceDebugActivity extends BaseActivity { protected void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); debugEntity = getIntent().getParcelableExtra("debugEntity"); - rc = ReadCrawlerUtil.getReadCrawler(debugEntity.getBookSource(), true); + if (debugEntity == null) finish(); + BookSource source = debugEntity.getBookSource(); + isThird3 = APPCONST.THIRD_3_SOURCE.equals(source.getSourceType()); + rc = ReadCrawlerUtil.getReadCrawler(source, true); loadingDialog = new LoadingDialog(this, "正在请求", () -> { if (disposable != null && !disposable.isDisposed()) { disposable.dispose(); } }); + if (isThird3) { + binding.tabLayout.getTabAt(1).setText(R.string.debug_log); + logSb = new StringBuilder(); + Debug.INSTANCE.setCallback(msg -> logSb.append(msg).append("\n")); + } } @Override @@ -112,7 +126,7 @@ public class SourceDebugActivity extends BaseActivity { debugEntity.getBookSource().getSourceUrl(), debugEntity.getUrl())); binding.rvParseResult.setLanguage(Language.JSON); - binding.rvSourceCode.setLanguage(Language.HTML); + binding.rvSourceCode.setLanguage(Language.AUTO); binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { @@ -142,6 +156,9 @@ public class SourceDebugActivity extends BaseActivity { if (loadingDialog != null) { loadingDialog.dismiss(); } + if (isThird3) { + Debug.INSTANCE.setCallback(null); + } super.onDestroy(); } @@ -196,7 +213,11 @@ public class SourceDebugActivity extends BaseActivity { @Override public void onNext(@NonNull Boolean flag) { binding.rvParseResult.setCode(debugEntity.getParseResult()).apply(); - binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); + if (!isThird3) { + binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); + } else { + binding.rvSourceCode.setCode(logSb.toString()).apply(); + } loadingDialog.dismiss(); } @@ -204,7 +225,11 @@ public class SourceDebugActivity extends BaseActivity { public void onError(Throwable e) { binding.rvParseResult.setCode(String.format("{\n\b\b\b\b\"result\": \"error\", \n\b\b\b\b\"msg\": \"%s\"\n}" , e.getLocalizedMessage().replace("\"", "\\\""))).apply(); - binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); + if (!isThird3) { + binding.rvSourceCode.setCode(debugEntity.getHtml()).apply(); + } else { + binding.rvSourceCode.setCode(logSb.toString()).apply(); + } loadingDialog.dismiss(); } }); 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 018daf0..17fcb25 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 @@ -1,6 +1,9 @@ package xyz.fycz.myreader.ui.activity; import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Menu; @@ -30,6 +33,7 @@ import xyz.fycz.myreader.ui.dialog.DialogCreator; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.util.help.StringHelper; import xyz.fycz.myreader.util.ToastUtils; +import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.webapi.crawler.source.MatcherCrawler; /** @@ -182,6 +186,14 @@ public class SourceEditActivity extends BaseActivity { } else { ToastUtils.showWarring("当前书源没有配置登录地址"); } + } else if (item.getItemId() == R.id.action_copy_source) { + ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + //数据 + ClipData mClipData = ClipData.newPlainText("Label", + GsonExtensionsKt.getGSON().toJson(getSource())); + //把数据设置到剪切板上 + mClipboardManager.setPrimaryClip(mClipData); + ToastUtils.showSuccess("拷贝成功"); } else if (item.getItemId() == R.id.action_clear_cookie) { DbManager.getDaoSession().getCookieBeanDao().deleteByKey(getSource().getSourceUrl()); ToastUtils.showSuccess("Cookie清除成功"); diff --git a/app/src/main/res/layout/activity_source_debug.xml b/app/src/main/res/layout/activity_source_debug.xml index 4a88252..1d3aa0a 100644 --- a/app/src/main/res/layout/activity_source_debug.xml +++ b/app/src/main/res/layout/activity_source_debug.xml @@ -1,70 +1,65 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> + - + android:layout_height="wrap_content" + android:background="@color/colorForeground" + android:padding="10dp" + android:textColor="@color/textSecondary" + android:maxLines="6" + android:textSize="13sp" /> - + - + android:text="@string/parse_result" /> - - - + - + - + - - - + android:scrollbars="vertical" + android:visibility="visible" + app:cv_font_size="10" + app:cv_zoom_enable="true" /> - - + + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_source_edit.xml b/app/src/main/res/menu/menu_source_edit.xml index 9f2c29e..0b040d7 100644 --- a/app/src/main/res/menu/menu_source_edit.xml +++ b/app/src/main/res/menu/menu_source_edit.xml @@ -32,7 +32,10 @@ android:id="@+id/action_login" android:title="@string/text_login" app:showAsAction="never" /> - + 分享所有 解析结果 网页源码 + 调试日志 重新请求 测试搜索配置 测试书籍详情 @@ -540,6 +541,7 @@ 没有网络 网络连接超时 数据解析失败 + 拷贝书源