pull/1835/head
kunfei 3 years ago
parent 226acdb4c9
commit 8aaadee0ff
  1. 25
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  2. 20
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  3. 7
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -119,7 +119,7 @@ object AppWebDav {
} }
@Throws(WebDavException::class) @Throws(WebDavException::class)
private suspend fun restoreWebDav(name: String) { suspend fun restoreWebDav(name: String) {
authorization?.let { authorization?.let {
val webDav = WebDav(rootWebDavUrl + name, it) val webDav = WebDav(rootWebDavUrl + name, it)
webDav.downloadTo(zipFilePath, true) webDav.downloadTo(zipFilePath, true)
@ -138,21 +138,22 @@ object AppWebDav {
return false return false
} }
suspend fun lastBackUp(): WebDavFile? { suspend fun lastBackUp(): Result<WebDavFile?> {
authorization?.let { return kotlin.runCatching {
var lastBackupFile: WebDavFile? = null authorization?.let {
WebDav(rootWebDavUrl, it).listFiles().forEach { webDavFile -> var lastBackupFile: WebDavFile? = null
if (webDavFile.displayName.startsWith("backup")) { WebDav(rootWebDavUrl, it).listFiles().forEach { webDavFile ->
if (lastBackupFile == null if (webDavFile.displayName.startsWith("backup")) {
|| webDavFile.lastModify > lastBackupFile!!.lastModify if (lastBackupFile == null
) { || webDavFile.lastModify > lastBackupFile!!.lastModify
lastBackupFile = webDavFile ) {
lastBackupFile = webDavFile
}
} }
} }
lastBackupFile
} }
return lastBackupFile
} }
return null
} }
@Throws(Exception::class) @Throws(Exception::class)

@ -3,6 +3,7 @@
package io.legado.app.ui.main package io.legado.app.ui.main
import android.os.Bundle import android.os.Bundle
import android.text.format.DateUtils
import android.view.KeyEvent import android.view.KeyEvent
import android.view.MenuItem import android.view.MenuItem
import android.view.ViewGroup import android.view.ViewGroup
@ -23,7 +24,9 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.LocalConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.AppWebDav
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.elevation import io.legado.app.lib.theme.elevation
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -39,6 +42,9 @@ import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.showDialogFragment import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/** /**
* 主界面 * 主界面
@ -88,6 +94,20 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
binding.viewPagerMain.postDelayed({ binding.viewPagerMain.postDelayed({
viewModel.postLoad() viewModel.postLoad()
}, 3000) }, 3000)
launch {
val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() }
if (System.currentTimeMillis() - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS
&& lastBackupFile != null
) {
alert("恢复", "webDav书源比本地新,是否恢复") {
cancelButton()
okButton {
viewModel.restoreWebDav(lastBackupFile.displayName)
}
}
}
}
} }
override fun onNavigationItemSelected(item: MenuItem): Boolean = binding.run { override fun onNavigationItemSelected(item: MenuItem): Boolean = binding.run {

@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.LocalConfig
import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.CacheBook import io.legado.app.model.CacheBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.CacheBookService import io.legado.app.service.CacheBookService
@ -195,6 +196,12 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun restoreWebDav(name: String) {
execute {
AppWebDav.restoreWebDav(name)
}
}
fun upVersion() { fun upVersion() {
execute { execute {
if (LocalConfig.needUpHttpTTS) { if (LocalConfig.needUpHttpTTS) {

Loading…
Cancel
Save