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 a2260b4f9..7afa40839 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 @@ -58,4 +58,6 @@ interface SearchBookDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg searchBook: SearchBook): List + @Query("delete from searchBooks where time < :time") + fun clearOld(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 ba125d7db..253507dc3 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 @@ -47,12 +47,19 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), view_pager_main.addOnPageChangeListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this) bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) upVersion() if (AppConfig.autoRefreshBook) { view_pager_main.postDelayed({ viewModel.upChapterList() }, 1000) } + view_pager_main.postDelayed({ + viewModel.clearDb() + }, 5000) } override fun onNavigationItemSelected(item: MenuItem): Boolean { 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 4fe57d758..29fa339ea 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 @@ -13,6 +13,7 @@ import io.legado.app.utils.fromJsonObject import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay +import java.util.concurrent.TimeUnit class MainViewModel(application: Application) : BaseViewModel(application) { val updateList = hashSetOf() @@ -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() { execute { val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource"