|
|
|
@ -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,8 +94,11 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
|
|
|
|
|
override fun onPostCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onPostCreate(savedInstanceState) |
|
|
|
|
launch { |
|
|
|
|
//隐私协议 |
|
|
|
|
if (!privacyPolicy()) return@launch |
|
|
|
|
//版本更新 |
|
|
|
|
upVersion() |
|
|
|
|
privacyPolicy() |
|
|
|
|
//请求设置书籍保存位置 |
|
|
|
|
setBookStorage() |
|
|
|
|
//自动更新书籍 |
|
|
|
@ -108,6 +113,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
} |
|
|
|
|
syncAlert() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onNavigationItemSelected(item: MenuItem): Boolean = binding.run { |
|
|
|
|
when (item.itemId) { |
|
|
|
@ -142,17 +148,57 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upVersion() { |
|
|
|
|
if (LocalConfig.versionCode != appInfo.versionCode) { |
|
|
|
|
/** |
|
|
|
|
* 用户隐私与协议 |
|
|
|
|
*/ |
|
|
|
|
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()) |
|
|
|
|
showDialogFragment(TextDialog(help, TextDialog.Mode.MD)) |
|
|
|
|
val dialog = TextDialog(help, TextDialog.Mode.MD) |
|
|
|
|
dialog.setOnDismissListener { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
} |
|
|
|
|
showDialogFragment(dialog) |
|
|
|
|
} else if (!BuildConfig.DEBUG) { |
|
|
|
|
val log = String(assets.open("updateLog.md").readBytes()) |
|
|
|
|
showDialogFragment(TextDialog(log, TextDialog.Mode.MD)) |
|
|
|
|
val dialog = TextDialog(log, TextDialog.Mode.MD) |
|
|
|
|
dialog.setOnDismissListener { |
|
|
|
|
block.resume(Unit) |
|
|
|
|
} |
|
|
|
|
viewModel.upVersion() |
|
|
|
|
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() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置书籍保存位置 |
|
|
|
|
*/ |
|
|
|
|