add a respondTime field and sorting

pull/1282/head
Jason Yao 3 years ago
parent 7631e05a81
commit 0e96739e61
  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. 12
      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. 1
      app/src/main/res/values-zh-rHK/strings.xml
  14. 1
      app/src/main/res/values-zh-rTW/strings.xml
  15. 1
      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")
}
}
}

@ -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)
@ -232,7 +237,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
o1.bookSourceName.cnCompare(o2.bookSourceName)
}
Sort.Url -> data.sortedBy { it.bookSourceUrl }
Sort.Update -> data.sortedByDescending { it.lastUpdateTime }
Sort.Update -> data.sortedByDescending { it.respondTime }
Sort.Respond -> data.sortedByDescending { it.respondTime }
Sort.Enable -> data.sortedWith { o1, o2 ->
var sort = -o1.enabled.compareTo(o2.enabled)
if (sort == 0) {
@ -248,7 +254,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
o2.bookSourceName.cnCompare(o1.bookSourceName)
}
Sort.Url -> data.sortedByDescending { it.bookSourceUrl }
Sort.Update -> data.sortedBy { it.lastUpdateTime }
Sort.Respond -> data.sortedBy { it.respondTime }
Sort.Enable -> data.sortedWith { o1, o2 ->
var sort = o1.enabled.compareTo(o2.enabled)
if (sort == 0) {
@ -547,6 +553,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">根据响应时间排序</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">根据响应时间排序</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">根据响应时间排序</string>
</resources>

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

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

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