|
|
|
@ -47,6 +47,8 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
import kotlin.coroutines.resume |
|
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 主界面 |
|
|
|
@ -92,21 +94,25 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
|
|
|
|
|
override fun onPostCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onPostCreate(savedInstanceState) |
|
|
|
|
upVersion() |
|
|
|
|
privacyPolicy() |
|
|
|
|
//请求设置书籍保存位置 |
|
|
|
|
setBookStorage() |
|
|
|
|
//自动更新书籍 |
|
|
|
|
val isAutoRefreshedBook = savedInstanceState?.getBoolean("isAutoRefreshedBook") ?: false |
|
|
|
|
if (AppConfig.autoRefreshBook && !isAutoRefreshedBook) { |
|
|
|
|
binding.viewPagerMain.postDelayed(1000) { |
|
|
|
|
viewModel.upAllBookToc() |
|
|
|
|
launch { |
|
|
|
|
//隐私协议 |
|
|
|
|
if (!privacyPolicy()) return@launch |
|
|
|
|
//版本更新 |
|
|
|
|
upVersion() |
|
|
|
|
//请求设置书籍保存位置 |
|
|
|
|
setBookStorage() |
|
|
|
|
//自动更新书籍 |
|
|
|
|
val isAutoRefreshedBook = savedInstanceState?.getBoolean("isAutoRefreshedBook") ?: false |
|
|
|
|
if (AppConfig.autoRefreshBook && !isAutoRefreshedBook) { |
|
|
|
|
binding.viewPagerMain.postDelayed(1000) { |
|
|
|
|
viewModel.upAllBookToc() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
binding.viewPagerMain.postDelayed(3000) { |
|
|
|
|
viewModel.postLoad() |
|
|
|
|
} |
|
|
|
|
syncAlert() |
|
|
|
|
} |
|
|
|
|
binding.viewPagerMain.postDelayed(3000) { |
|
|
|
|
viewModel.postLoad() |
|
|
|
|
} |
|
|
|
|
syncAlert() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onNavigationItemSelected(item: MenuItem): Boolean = binding.run { |
|
|
|
@ -142,17 +148,57 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upVersion() { |
|
|
|
|
if (LocalConfig.versionCode != appInfo.versionCode) { |
|
|
|
|
LocalConfig.versionCode = appInfo.versionCode |
|
|
|
|
if (LocalConfig.isFirstOpenApp) { |
|
|
|
|
val help = String(assets.open("help/appHelp.md").readBytes()) |
|
|
|
|
showDialogFragment(TextDialog(help, TextDialog.Mode.MD)) |
|
|
|
|
} else if (!BuildConfig.DEBUG) { |
|
|
|
|
val log = String(assets.open("updateLog.md").readBytes()) |
|
|
|
|
showDialogFragment(TextDialog(log, TextDialog.Mode.MD)) |
|
|
|
|
/** |
|
|
|
|
* 用户隐私与协议 |
|
|
|
|
*/ |
|
|
|
|
private suspend fun privacyPolicy(): Boolean = suspendCoroutine { block -> |
|
|
|
|
if (LocalConfig.privacyPolicyOk) { |
|
|
|
|
block.resume(true) |
|
|
|
|
return@suspendCoroutine |
|
|
|
|
} |
|
|
|
|
val privacyPolicy = String(assets.open("privacyPolicy.md").readBytes()) |
|
|
|
|
alert("用户隐私与协议", privacyPolicy) { |
|
|
|
|
noButton { |
|
|
|
|
finish() |
|
|
|
|
block.resume(false) |
|
|
|
|
} |
|
|
|
|
yesButton { |
|
|
|
|
LocalConfig.privacyPolicyOk = true |
|
|
|
|
block.resume(true) |
|
|
|
|
} |
|
|
|
|
onCancelled { |
|
|
|
|
finish() |
|
|
|
|
block.resume(false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 版本更新日志 |
|
|
|
|
*/ |
|
|
|
|
private suspend fun upVersion() = suspendCoroutine { block -> |
|
|
|
|
if (LocalConfig.versionCode == appInfo.versionCode) { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
return@suspendCoroutine |
|
|
|
|
} |
|
|
|
|
LocalConfig.versionCode = appInfo.versionCode |
|
|
|
|
viewModel.upVersion() |
|
|
|
|
if (LocalConfig.isFirstOpenApp) { |
|
|
|
|
val help = String(assets.open("help/appHelp.md").readBytes()) |
|
|
|
|
val dialog = TextDialog(help, TextDialog.Mode.MD) |
|
|
|
|
dialog.setOnDismissListener { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
} |
|
|
|
|
viewModel.upVersion() |
|
|
|
|
showDialogFragment(dialog) |
|
|
|
|
} else if (!BuildConfig.DEBUG) { |
|
|
|
|
val log = String(assets.open("updateLog.md").readBytes()) |
|
|
|
|
val dialog = TextDialog(log, TextDialog.Mode.MD) |
|
|
|
|
dialog.setOnDismissListener { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
} |
|
|
|
|
showDialogFragment(dialog) |
|
|
|
|
} else { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -173,23 +219,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 用户隐私与协议 |
|
|
|
|
*/ |
|
|
|
|
private fun privacyPolicy() { |
|
|
|
|
if (LocalConfig.privacyPolicyOk) return |
|
|
|
|
val privacyPolicy = String(assets.open("privacyPolicy.md").readBytes()) |
|
|
|
|
alert("用户隐私与协议", privacyPolicy) { |
|
|
|
|
noButton() |
|
|
|
|
yesButton { |
|
|
|
|
LocalConfig.privacyPolicyOk = true |
|
|
|
|
} |
|
|
|
|
onCancelled { |
|
|
|
|
finish() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置书籍保存位置 |
|
|
|
|
*/ |
|
|
|
@ -200,10 +229,10 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
val storageHelp = String(assets.open("storageHelp.md").readBytes()) |
|
|
|
|
alert("设置书籍保存位置", storageHelp) { |
|
|
|
|
yesButton { |
|
|
|
|
localBookTreeSelect.launch { |
|
|
|
|
title = getString(R.string.select_book_folder) |
|
|
|
|
mode = HandleFileContract.DIR_SYS |
|
|
|
|
} |
|
|
|
|
localBookTreeSelect.launch { |
|
|
|
|
title = getString(R.string.select_book_folder) |
|
|
|
|
mode = HandleFileContract.DIR_SYS |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
noButton() |
|
|
|
|
} |
|
|
|
|