From b1e85ead4da2b98f8a2780a2ad1709612c8ade75 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 17 Feb 2020 20:41:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt | 2 +- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 5 ++++- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 7afa40839..779cfd1e2 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -59,5 +59,5 @@ interface SearchBookDao { fun insert(vararg searchBook: SearchBook): List @Query("delete from searchBooks where time < :time") - fun clearOld(time: Long) + fun clearExpired(time: Long) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index a4ede48c0..57c368a2c 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -52,17 +52,20 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) upVersion() + //初始化简繁转换引擎 when (AppConfig.chineseConverterType) { 1 -> ZhConverterUtil.toSimple("初始化") 2 -> ZhConverterUtil.toTraditional("初始化") } + //自动更新书籍 if (AppConfig.autoRefreshBook) { view_pager_main.postDelayed({ viewModel.upChapterList() }, 1000) } + //清楚过期数据 view_pager_main.postDelayed({ - viewModel.clearDb() + viewModel.clearExpiredData() }, 3000) } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 29fa339ea..1a0652bae 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -54,9 +54,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } } - fun clearDb() { + fun clearExpiredData() { execute { - App.db.searchBookDao().clearOld(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) + App.db.searchBookDao() + .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) } }