Merge pull request #1282 from h11128/check-respond-time

根据响应时间排序
pull/1284/head
kunfei 3 years ago committed by GitHub
commit 6604eeb930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1465
      app/schemas/io.legado.app.data.AppDatabase/38.json
  2. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  3. 9
      app/src/main/java/io/legado/app/data/DatabaseMigrations.kt
  4. 1
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  5. 2
      app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt
  6. 10
      app/src/main/java/io/legado/app/model/Debug.kt
  7. 2
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  8. 9
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  9. 5
      app/src/main/res/menu/book_source.xml
  10. 1
      app/src/main/res/values-es-rES/strings.xml
  11. 1
      app/src/main/res/values-ja-rJP/strings.xml
  12. 1
      app/src/main/res/values-pt-rBR/strings.xml
  13. 3
      app/src/main/res/values-zh-rHK/strings.xml
  14. 3
      app/src/main/res/values-zh-rTW/strings.xml
  15. 3
      app/src/main/res/values-zh/strings.xml
  16. 1
      app/src/main/res/values/strings.xml

File diff suppressed because it is too large Load Diff

@ -16,7 +16,7 @@ val appDb by lazy {
}
@Database(
version = 37,
version = 38,
exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,

@ -33,7 +33,8 @@ object DatabaseMigrations {
migration_33_34,
migration_34_35,
migration_35_36,
migration_36_37
migration_36_37,
migration_37_38
)
}
@ -296,4 +297,10 @@ object DatabaseMigrations {
database.execSQL("ALTER TABLE `rssSources` ADD`loginCheckJs` TEXT")
}
}
private val migration_37_38 = object : Migration(37, 38) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE `book_sources` ADD `respondTime` INTEGER NOT NULL DEFAULT 180000")
}
}
}

@ -33,6 +33,7 @@ data class BookSource(
var loginCheckJs: String? = null, //登录检测js
var bookSourceComment: String? = null, // 注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var respondTime: Long = 180000L, // 响应时间,用于排序
var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url
var ruleExplore: ExploreRule? = null, // 发现规则

@ -109,6 +109,7 @@ object BookSourceAnalyzer {
source.loginCheckJs = sourceAny.loginCheckJs
source.bookSourceComment = sourceAny.bookSourceComment
source.lastUpdateTime = sourceAny.lastUpdateTime
source.respondTime = sourceAny.respondTime
source.weight = sourceAny.weight
source.exploreUrl = sourceAny.exploreUrl
source.ruleExplore = if (sourceAny.ruleExplore is String) {
@ -160,6 +161,7 @@ object BookSourceAnalyzer {
var loginCheckJs: String? = null, //登录检测js
var bookSourceComment: String? = "", //书源注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var respondTime: Long = 180000L, // 响应时间,用于排序
var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url
var ruleExplore: Any? = null, // 发现规则

@ -87,11 +87,17 @@ object Debug {
isChecking = false
}
fun getRespondTime(sourceUrl: String): Long {
return debugTimeMap[sourceUrl] ?: 180000L
}
fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!!
debugTimeMap[sourceUrl] = if(state == "成功") spendingTime else 180000L
val printTime = DEBUG_TIME_FORMAT.format(Date(spendingTime))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$time $originalMessage $state"
debugMessageMap[sourceUrl] = "$printTime $originalMessage $state"
}
}

@ -140,6 +140,7 @@ class CheckSourceService : BaseService() {
${source.bookSourceComment}"
""".trimIndent()
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}")
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)
}.onSuccess(searchCoroutine) {
source.removeGroup("失效")
@ -149,6 +150,7 @@ class CheckSourceService : BaseService() {
it.startsWith("error:")
}?.joinToString("\n")
Debug.updateFinalMessage(source.bookSourceUrl, "成功")
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)
}.onFinally(searchCoroutine) {
onNext(source.bookSourceUrl, source.bookSourceName)

@ -155,6 +155,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
sortCheck(Sort.Update)
upBookSource(searchView.query?.toString())
}
R.id.menu_sort_respondTime -> {
item.isChecked = true
sortCheck(Sort.Respond)
upBookSource(searchView.query?.toString())
}
R.id.menu_sort_enable -> {
item.isChecked = true
sortCheck(Sort.Enable)
@ -233,6 +238,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
Sort.Url -> data.sortedBy { it.bookSourceUrl }
Sort.Update -> data.sortedByDescending { it.lastUpdateTime }
Sort.Respond -> data.sortedBy { it.respondTime }
Sort.Enable -> data.sortedWith { o1, o2 ->
var sort = -o1.enabled.compareTo(o2.enabled)
if (sort == 0) {
@ -249,6 +255,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
Sort.Url -> data.sortedByDescending { it.bookSourceUrl }
Sort.Update -> data.sortedBy { it.lastUpdateTime }
Sort.Respond -> data.sortedByDescending { it.respondTime }
Sort.Enable -> data.sortedWith { o1, o2 ->
var sort = o1.enabled.compareTo(o2.enabled)
if (sort == 0) {
@ -547,6 +554,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
enum class Sort {
Default, Name, Url, Weight, Update, Enable
Default, Name, Url, Weight, Update, Enable, Respond
}
}

@ -51,6 +51,11 @@
android:checkable="true"
android:title="@string/sort_by_lastUpdateTime" />
<item
android:id="@+id/menu_sort_respondTime"
android:checkable="true"
android:title="@string/sort_by_respondTime" />
<item
android:id="@+id/menu_sort_enable"
android:checkable="true"

@ -864,4 +864,5 @@
<string name="background_image_hint">Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="sort_by_respondTime">Ordenar por tiempo de respuesta</string>
</resources>

@ -864,4 +864,5 @@
<string name="background_image_hint">Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="sort_by_respondTime">Sort by respond time</string>
</resources>

@ -864,5 +864,6 @@
<string name="background_image_hint">Desativado quando 0, Ativado entre 1 e 25\n Quanto maior o raio, mais forte o efeito de desfocagem</string>
<string name="need_login">Login necessário</string>
<string name="pref_cronet_summary">Usando componentes de rede Cronet</string>
<string name="sort_by_respondTime">Classificar por tempo de resposta</string>
</resources>

@ -768,7 +768,7 @@
<string name="theme_list_summary">使用儲存主題,匯入,分享主題</string>
<string name="select_theme">切換默認主題</string>
<string name="share_selected_source">分享選中源</string>
<string name="sort_by_lastUpdateTime">時間排序</string>
<string name="sort_by_lastUpdateTime">更新時間排序</string>
<string name="search_content">全文搜索</string>
<string name="rss_source_empty">關注公眾號[开源阅读]獲取訂閲源!</string>
<string name="explore_empty">目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源!</string>
@ -861,5 +861,6 @@
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="sort_by_respondTime">響應時間排序</string>
</resources>

@ -771,7 +771,7 @@
<string name="theme_list">主題列表</string>
<string name="theme_list_summary">使用儲存主題,匯入,分享主題</string>
<string name="select_theme">切換預設主題</string>
<string name="sort_by_lastUpdateTime">時間排序</string>
<string name="sort_by_lastUpdateTime">更新時間排序</string>
<string name="search_content">全文搜尋</string>
<string name="rss_source_empty">關注公眾號[开源阅读]獲取訂閱源!</string>
<string name="explore_empty">目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源!</string>
@ -862,5 +862,6 @@
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="sort_by_respondTime">響應時間排序</string>
</resources>

@ -771,7 +771,7 @@
<string name="theme_list">主题列表</string>
<string name="theme_list_summary">使用保存主题,导入,分享主题</string>
<string name="select_theme">切换默认主题</string>
<string name="sort_by_lastUpdateTime">时间排序</string>
<string name="sort_by_lastUpdateTime">更新时间排序</string>
<string name="search_content">全文搜索</string>
<string name="rss_source_empty">关注公众号[开源阅读]获取订阅源!</string>
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
@ -863,5 +863,6 @@
<string name="check_source_show_debug_message_summary">书源校验时显示网络请求步骤和时间</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="sort_by_respondTime">响应时间排序</string>
</resources>

@ -773,6 +773,7 @@
<string name="theme_list_summary">Save, Import, Share theme</string>
<string name="select_theme">Switch default theme</string>
<string name="sort_by_lastUpdateTime">Sort by update time</string>
<string name="sort_by_respondTime">Sort by respond time</string>
<string name="search_content">Search content</string>
<string name="rss_source_empty">Follow Wechat official account [开源阅读] to get Subscription source</string>
<string name="explore_empty">Empty now,Follow Wechat official account [开源阅读] to get Discovery source</string>

Loading…
Cancel
Save