pull/2380/head
kunfei 2 years ago
parent fd943bfa38
commit 9e6c3ab779
  1. 15
      app/src/main/java/io/legado/app/base/BaseDialogFragment.kt
  2. 75
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -1,5 +1,7 @@
package io.legado.app.base
import android.content.DialogInterface
import android.content.DialogInterface.OnDismissListener
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
@ -18,9 +20,13 @@ import kotlin.coroutines.CoroutineContext
abstract class BaseDialogFragment(
@LayoutRes layoutID: Int,
private val adaptationSoftKeyboard: Boolean = false
) : DialogFragment(layoutID),
) : DialogFragment(layoutID), CoroutineScope by MainScope() {
CoroutineScope by MainScope() {
private var onDismissListener: OnDismissListener? = null
fun setOnDismissListener(onDismissListener: OnDismissListener?) {
this.onDismissListener = onDismissListener
}
override fun onStart() {
super.onStart()
@ -51,6 +57,11 @@ abstract class BaseDialogFragment(
}
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
onDismissListener?.onDismiss(dialog)
}
override fun onDestroy() {
super.onDestroy()
cancel()

@ -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()
}
}
}
/**
* 设置书籍保存位置
*/

Loading…
Cancel
Save