feat: 优化代码

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

@ -58,4 +58,6 @@ interface SearchBookDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg searchBook: SearchBook): List<Long> fun insert(vararg searchBook: SearchBook): List<Long>
@Query("delete from searchBooks where time < :time")
fun clearOld(time: Long)
} }

@ -47,12 +47,19 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
view_pager_main.addOnPageChangeListener(this) view_pager_main.addOnPageChangeListener(this)
bottom_navigation_view.setOnNavigationItemSelectedListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this)
bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS
}
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
upVersion() upVersion()
if (AppConfig.autoRefreshBook) { if (AppConfig.autoRefreshBook) {
view_pager_main.postDelayed({ view_pager_main.postDelayed({
viewModel.upChapterList() viewModel.upChapterList()
}, 1000) }, 1000)
} }
view_pager_main.postDelayed({
viewModel.clearDb()
}, 5000)
} }
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean {

@ -13,6 +13,7 @@ import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import java.util.concurrent.TimeUnit
class MainViewModel(application: Application) : BaseViewModel(application) { class MainViewModel(application: Application) : BaseViewModel(application) {
val updateList = hashSetOf<String>() val updateList = hashSetOf<String>()
@ -53,6 +54,12 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun clearDb() {
execute {
App.db.searchBookDao().clearOld(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
}
}
fun initRss() { fun initRss() {
execute { execute {
val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource"

Loading…
Cancel
Save