feat: 优化代码

pull/103/head
kunfei 5 years ago
parent bbc2823c08
commit b1e85ead4d
  1. 2
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 5
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  3. 5
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -59,5 +59,5 @@ interface SearchBookDao {
fun insert(vararg searchBook: SearchBook): List<Long> fun insert(vararg searchBook: SearchBook): List<Long>
@Query("delete from searchBooks where time < :time") @Query("delete from searchBooks where time < :time")
fun clearOld(time: Long) fun clearExpired(time: Long)
} }

@ -52,17 +52,20 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState) super.onPostCreate(savedInstanceState)
upVersion() upVersion()
//初始化简繁转换引擎
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> ZhConverterUtil.toSimple("初始化") 1 -> ZhConverterUtil.toSimple("初始化")
2 -> ZhConverterUtil.toTraditional("初始化") 2 -> ZhConverterUtil.toTraditional("初始化")
} }
//自动更新书籍
if (AppConfig.autoRefreshBook) { if (AppConfig.autoRefreshBook) {
view_pager_main.postDelayed({ view_pager_main.postDelayed({
viewModel.upChapterList() viewModel.upChapterList()
}, 1000) }, 1000)
} }
//清楚过期数据
view_pager_main.postDelayed({ view_pager_main.postDelayed({
viewModel.clearDb() viewModel.clearExpiredData()
}, 3000) }, 3000)
} }

@ -54,9 +54,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun clearDb() { fun clearExpiredData() {
execute { execute {
App.db.searchBookDao().clearOld(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) App.db.searchBookDao()
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
} }
} }

Loading…
Cancel
Save