pull/21/head
fengyuecanzhu 3 years ago
parent eb7b98b429
commit da5c5ecd30
  1. 15
      app/src/main/java/xyz/fycz/myreader/greendao/entity/rule/BookSource.java
  2. 18
      app/src/main/java/xyz/fycz/myreader/model/third3/BaseSource.kt
  3. 29
      app/src/main/java/xyz/fycz/myreader/model/third3/Debug.kt
  4. 1
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeRule.kt
  5. 3
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/AnalyzeUrl.kt
  6. 8
      app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt
  7. 33
      app/src/main/java/xyz/fycz/myreader/ui/activity/SourceDebugActivity.java
  8. 12
      app/src/main/java/xyz/fycz/myreader/ui/activity/SourceEditActivity.java
  9. 99
      app/src/main/res/layout/activity_source_debug.xml
  10. 5
      app/src/main/res/menu/menu_source_edit.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -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

@ -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<String, String>().apply {
this[APPCONST.UA_NAME] = APPCONST.DEFAULT_USER_AGENT
header?.let {
getHeader()?.let {
GSON.fromJsonObject<Map<String, String>>(
when {
it.startsWith("@js:", true) ->

@ -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)
}
}

@ -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

@ -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
}

@ -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)
}

@ -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();
}
});

@ -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清除成功");

@ -1,70 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<LinearLayout
<TextView
android:id="@+id/tv_tip"
android:layout_width="match_parent"
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" />
<include layout="@layout/toolbar" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="@color/colorForeground"
android:elevation="3dp"
app:tabSelectedTextColor="@color/colorAccent">
<TextView
android:id="@+id/tv_tip"
android:layout_width="match_parent"
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorForeground"
android:padding="10dp"
android:textColor="@color/textSecondary"
android:textSize="13sp" />
android:text="@string/parse_result" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="@color/colorForeground"
android:elevation="3dp"
app:tabSelectedTextColor="@color/colorAccent">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/parse_result" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_code" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_code" />
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.tabs.TabLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#474949">
<RelativeLayout
<xyz.fycz.myreader.widget.codeview.CodeView
android:id="@+id/rv_parse_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#474949">
<xyz.fycz.myreader.widget.codeview.CodeView
android:id="@+id/rv_parse_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:visibility="visible"
app:cv_font_size="10"
app:cv_zoom_enable="true" />
android:scrollbars="vertical"
android:visibility="visible"
app:cv_font_size="10"
app:cv_zoom_enable="true" />
<xyz.fycz.myreader.widget.codeview.CodeView
android:id="@+id/rv_source_code"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:visibility="gone"
app:cv_font_size="10"
app:cv_zoom_enable="true" />
</RelativeLayout>
<xyz.fycz.myreader.widget.codeview.CodeView
android:id="@+id/rv_source_code"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:visibility="gone"
app:cv_font_size="10"
app:cv_zoom_enable="true" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

@ -32,7 +32,10 @@
android:id="@+id/action_login"
android:title="@string/text_login"
app:showAsAction="never" />
<item
android:id="@+id/action_copy_source"
android:title="@string/copy_source"
app:showAsAction="never" />
<item
android:id="@+id/action_clear_cookie"
android:title="@string/clear_cookie"

@ -448,6 +448,7 @@
<string name="share_all">分享所有</string>
<string name="parse_result">解析结果</string>
<string name="source_code">网页源码</string>
<string name="debug_log">调试日志</string>
<string name="re_request">重新请求</string>
<string name="debug_search">测试搜索配置</string>
<string name="debug_info">测试书籍详情</string>
@ -540,6 +541,7 @@
<string name="net_error_10001">没有网络</string>
<string name="net_error_10002">网络连接超时</string>
<string name="net_error_10003">数据解析失败</string>
<string name="copy_source">拷贝书源</string>
<!--error string end-->
<string-array name="reset_screen_time">

Loading…
Cancel
Save