feat: 优化代码

pull/123/head
kunfei 5 years ago
parent d1c2f7dc27
commit 823bfe7685
  1. 11
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  3. 16
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

@ -7,7 +7,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.github.houbb.opencc4j.util.ZhConverterUtil
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.App import io.legado.app.App
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
@ -16,7 +15,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -53,21 +51,12 @@ 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) {
1 -> Coroutine.async { ZhConverterUtil.toSimple("初始化") }
2 -> Coroutine.async { 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({
viewModel.clearExpiredData()
}, 3000)
} }
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean {

@ -13,7 +13,6 @@ 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>()
@ -54,13 +53,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun clearExpiredData() {
execute {
App.db.searchBookDao()
.clearExpired(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"

@ -2,14 +2,19 @@ package io.legado.app.ui.welcome
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.github.houbb.opencc4j.util.ZhConverterUtil
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainActivity import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import kotlinx.android.synthetic.main.activity_welcome.* import kotlinx.android.synthetic.main.activity_welcome.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
@ -20,6 +25,17 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
finish() finish()
return return
} }
Coroutine.async {
//清楚过期数据
App.db.searchBookDao()
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
//初始化简繁转换引擎
when (AppConfig.chineseConverterType) {
1 -> ZhConverterUtil.toSimple("初始化")
2 -> ZhConverterUtil.toTraditional("初始化")
else -> null
}
}
root_view.postDelayed({ root_view.postDelayed({
startActivity<MainActivity>() startActivity<MainActivity>()
if (getPrefBoolean(getString(R.string.pk_default_read))) { if (getPrefBoolean(getString(R.string.pk_default_read))) {

Loading…
Cancel
Save