pull/1705/head
kunfei 3 years ago
parent bd28d402ed
commit c0158bc925
  1. 26
      app/src/main/java/io/legado/app/App.kt
  2. 3
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  3. 39
      app/src/main/java/io/legado/app/help/RuleBigDataHelp.kt
  4. 34
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

@ -6,18 +6,26 @@ import android.content.Context
import android.content.res.Configuration
import android.os.Build
import androidx.multidex.MultiDexApplication
import com.github.liuyueyi.quick.transfer.ChineseUtils
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.base.AppContextWrapper
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.help.CrashHandler
import io.legado.app.help.LifecycleHelp
import io.legado.app.help.RuleBigDataHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ThemeConfig.applyDayNight
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.cronet.CronetLoader
import io.legado.app.model.BookCover
import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.getPrefBoolean
import splitties.systemservices.notificationManager
import java.util.concurrent.TimeUnit
class App : MultiDexApplication() {
@ -33,7 +41,23 @@ class App : MultiDexApplication() {
.autoClear(false)
registerActivityLifecycleCallbacks(LifecycleHelp)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
Coroutine.async {
//初始化封面
BookCover.toString()
//清除过期数据
appDb.cacheDao.clearDeadline(System.currentTimeMillis())
if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
appDb.searchBookDao
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
}
RuleBigDataHelp.clearInvalid()
//初始化简繁转换引擎
when (AppConfig.chineseConverterType) {
1 -> ChineseUtils.t2s("初始化")
2 -> ChineseUtils.s2t("初始化")
else -> null
}
}
}
override fun attachBaseContext(base: Context) {

@ -71,4 +71,7 @@ interface RssSourceDao {
@Query("select * from rssSources where sourceGroup like '%' || :group || '%'")
fun getByGroup(group: String): List<RssSource>
@Query("select 1 from rssSources where sourceUrl = :key")
fun has(key: String): Boolean?
}

@ -1,8 +1,12 @@
package io.legado.app.help
import io.legado.app.data.appDb
import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFiles
import io.legado.app.utils.getFile
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import splitties.init.appCtx
import java.io.File
@ -12,6 +16,41 @@ object RuleBigDataHelp {
private val bookData = FileUtils.createFolderIfNotExist(ruleDataDir, "book")
private val rssData = FileUtils.createFolderIfNotExist(ruleDataDir, "rss")
suspend fun clearInvalid() {
withContext(IO) {
bookData.listFiles()?.forEach {
if (it.isFile) {
FileUtils.delete(it)
} else {
val bookUrlFile = it.getFile("bookUrl.txt")
if (!bookUrlFile.exists()) {
FileUtils.delete(it)
} else {
val bookUrl = bookUrlFile.readText()
if (appDb.bookDao.has(bookUrl) != true) {
FileUtils.delete(it)
}
}
}
}
rssData.listFiles()?.forEach {
if (it.isFile) {
FileUtils.delete(it)
} else {
val originFile = it.getFile("origin.txt")
if (!originFile.exists()) {
FileUtils.delete(it)
} else {
val origin = originFile.readText()
if (appDb.rssSourceDao.has(origin) != true) {
FileUtils.delete(it)
}
}
}
}
}
}
fun putBookVariable(bookUrl: String, key: String, value: String?) {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5Key = MD5Utils.md5Encode(key)

@ -3,7 +3,6 @@ package io.legado.app.ui.welcome
import android.content.Intent
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.base.BaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.constant.Theme
@ -13,12 +12,10 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.AppWebDav
import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookCover
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
@ -27,16 +24,8 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.ivBook.setColorFilter(accentColor)
binding.vwTitleLine.setBackgroundColor(accentColor)
// 避免从桌面启动程序后,会重新实例化入口类的activity
if (intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) {
finish()
} else {
init()
}
}
private fun init() {
Coroutine.async {
//同步阅读记录
if (!AppConfig.syncBookProgress) return@async
val books = appDb.bookDao.all
books.forEach { book ->
@ -54,23 +43,12 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
}
}
}
Coroutine.async {
//初始化封面
BookCover.toString()
//清除过期数据
appDb.cacheDao.clearDeadline(System.currentTimeMillis())
if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
appDb.searchBookDao
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
}
//初始化简繁转换引擎
when (AppConfig.chineseConverterType) {
1 -> ChineseUtils.t2s("初始化")
2 -> ChineseUtils.s2t("初始化")
else -> null
}
// 避免从桌面启动程序后,会重新实例化入口类的activity
if (intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) {
finish()
} else {
binding.root.postDelayed({ startMainActivity() }, 500)
}
binding.root.postDelayed({ startMainActivity() }, 500)
}
override fun upBackgroundImage() {

Loading…
Cancel
Save