pull/1264/head
gedoor 3 years ago
parent fcd2b9b967
commit db2d3cc4c4
  1. 5
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 2
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  4. 4
      app/src/main/java/io/legado/app/model/ReadBook.kt
  5. 5
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  6. 6
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  7. 3
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  9. 3
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  10. 4
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  11. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  12. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  13. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  14. 3
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  15. 3
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  16. 3
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  17. 4
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

@ -10,6 +10,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor
import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.EpubFile
import io.legado.app.model.localBook.LocalBook
@ -167,6 +168,7 @@ object BookController {
val returnData = ReturnData()
if (book != null) {
book.save()
AppWebDav.uploadBookProgress(book)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex
@ -177,19 +179,18 @@ object BookController {
}
private fun saveBookReadIndex(book: Book, index: Int) {
if (index > book.durChapterIndex) {
book.durChapterIndex = index
book.durChapterTime = System.currentTimeMillis()
appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let {
book.durChapterTitle = it.title
}
appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(book)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = index
}
}
}
fun addLocalBook(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData()

@ -20,7 +20,7 @@ import java.io.File
import java.text.SimpleDateFormat
import java.util.*
object BookWebDav {
object AppWebDav {
private const val defaultWebDavUrl = "https://dav.jianguoyun.com/dav/"
private val bookProgressUrl = "${rootWebDavUrl}bookProgress/"
private val zipFilePath = "${appCtx.externalFiles.absolutePath}${File.separator}backup.zip"

@ -98,7 +98,7 @@ object Backup {
}
edit.commit()
}
BookWebDav.backUpWebDav(backupPath)
AppWebDav.backUpWebDav(backupPath)
if (path.isContentScheme()) {
copyBackup(context, Uri.parse(path), isAuto)
} else {

@ -7,7 +7,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.*
import io.legado.app.help.*
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.BookWebDav
import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.CacheBook
@ -100,7 +100,7 @@ object ReadBook : CoroutineScope by MainScope() {
fun uploadProgress(syncBookProgress: Boolean = AppConfig.syncBookProgress) {
if (syncBookProgress) {
book?.let {
BookWebDav.uploadBookProgress(it)
AppWebDav.uploadBookProgress(it)
}
}
}

@ -6,7 +6,6 @@ import android.view.Menu
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
@ -111,7 +110,6 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
@SuppressLint("NotifyDataSetChanged")
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowAll().collect {
groupList.clear()
groupList.addAll(it)
@ -120,12 +118,10 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
}
}
}
}
private fun initBookData() {
booksFlowJob?.cancel()
booksFlowJob = launch {
lifecycle.whenStarted {
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
@ -145,7 +141,6 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
}
}
}
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {

@ -18,7 +18,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.BookWebDav
import io.legado.app.help.storage.AppWebDav
import io.legado.app.utils.*
import me.ag2s.epublib.domain.*
import me.ag2s.epublib.epub.EpubWriter
@ -78,7 +78,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
// 导出到webdav
val byteArray =
stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset))
BookWebDav.exportWebDav(byteArray, filename)
AppWebDav.exportWebDav(byteArray, filename)
}
}
getSrcList(book).forEach {
@ -105,7 +105,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
if (AppConfig.exportToWebDav) {
val byteArray =
stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset))
BookWebDav.exportWebDav(byteArray, filename) // 导出到webdav
AppWebDav.exportWebDav(byteArray, filename) // 导出到webdav
}
getSrcList(book).forEach {
val vFile = BookHelp.getImage(book, it.third)

@ -7,7 +7,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
@ -154,7 +153,6 @@ class ChangeSourceDialog : BaseDialogFragment(),
adapter.setItems(it)
})
launch {
lifecycle.whenStarted {
appDb.bookSourceDao.flowGroupEnabled().collect {
groups.clear()
it.map { group ->
@ -164,7 +162,6 @@ class ChangeSourceDialog : BaseDialogFragment(),
}
}
}
}
private val stopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_stop)

@ -13,7 +13,7 @@ import io.legado.app.data.entities.BookProgress
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.BookWebDav
import io.legado.app.help.storage.AppWebDav
import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.PreciseSearch
@ -169,7 +169,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) {
if (syncBookProgress)
execute {
BookWebDav.getBookProgress(book)
AppWebDav.getBookProgress(book)
}.onSuccess {
it?.let { progress ->
if (progress.durChapterIndex < book.durChapterIndex ||

@ -6,7 +6,6 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.whenStarted
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.EventBus
@ -110,7 +109,6 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
override fun upChapterList(searchKey: String?) {
tocFlowJob?.cancel()
tocFlowJob = launch {
lifecycle.whenStarted {
when {
searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl)
else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey)
@ -123,7 +121,6 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
}
}
}
}
override val isLocalBook: Boolean
get() = viewModel.bookData.value?.isLocalBook() == true

@ -19,8 +19,8 @@ import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig
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.BookWebDav
import io.legado.app.help.storage.ImportOldData
import io.legado.app.help.storage.Restore
import io.legado.app.lib.dialogs.alert
@ -268,7 +268,7 @@ class BackupConfigFragment : BasePreferenceFragment(),
fun restore() {
Coroutine.async(context = Main) {
BookWebDav.showRestoreDialog(requireContext())
AppWebDav.showRestoreDialog(requireContext())
}.onError {
alert {
setTitle(R.string.restore)

@ -10,7 +10,6 @@ import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.whenStarted
import com.google.android.material.tabs.TabLayout
import io.legado.app.R
import io.legado.app.constant.AppConst
@ -79,14 +78,12 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
private fun initBookGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowShow().collect {
viewModel.checkGroup(it)
upGroup(it)
}
}
}
}
override fun onQueryTextSubmit(query: String?): Boolean {
SearchActivity.start(requireContext(), query)

@ -5,7 +5,6 @@ import android.os.Bundle
import android.view.View
import androidx.core.view.isGone
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -107,7 +106,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private fun upRecyclerData() {
booksFlowJob?.cancel()
booksFlowJob = launch {
lifecycle.whenStarted {
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
@ -128,7 +126,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
}
}
}
}
fun getBooks(): List<Book> {
return booksAdapter.getItems()

@ -6,7 +6,6 @@ import android.view.Menu
import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -101,7 +100,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
@SuppressLint("NotifyDataSetChanged")
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowShow().collect {
if (it != bookGroups) {
bookGroups = it
@ -111,7 +109,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
}
}
}
}
@SuppressLint("NotifyDataSetChanged")
private fun initBooksData() {
@ -126,7 +123,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
}
booksFlowJob?.cancel()
booksFlowJob = launch {
lifecycle.whenStarted {
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
@ -153,7 +149,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
}
}
}
}
fun back(): Boolean {
if (groupId != AppConst.bookGroupNoneId) {

@ -7,7 +7,6 @@ import android.view.SubMenu
import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppPattern
@ -122,7 +121,6 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.rssSourceDao.flowGroup().collect {
groups.clear()
it.map { group ->
@ -132,7 +130,6 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
}
}
}
}
private fun upRssFlowJob(searchKey: String? = null) {
rssFlowJob?.cancel()

@ -6,7 +6,6 @@ import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -98,13 +97,11 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
val rssUrl = activityViewModel.url ?: return
articlesFlowJob?.cancel()
articlesFlowJob = lifecycleScope.launch {
lifecycle.whenStarted {
appDb.rssArticleDao.flowByOriginSort(rssUrl, viewModel.sortName).collect {
adapter.setItems(it)
}
}
}
}
private fun loadArticles() {
activityViewModel.rssSource?.let {

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.core.view.isGone
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.ItemTouchHelper
import io.legado.app.R
import io.legado.app.base.BaseActivity
@ -63,14 +62,12 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() {
launch {
lifecycle.whenStarted {
appDb.ruleSubDao.flowAll().collect {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
}
}
}
}
override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) {

@ -9,7 +9,7 @@ import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityWelcomeBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.BookWebDav
import io.legado.app.help.storage.AppWebDav
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainActivity
@ -37,7 +37,7 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
Coroutine.async {
val books = appDb.bookDao.all
books.forEach { book ->
BookWebDav.getBookProgress(book)?.let { bookProgress ->
AppWebDav.getBookProgress(book)?.let { bookProgress ->
if (bookProgress.durChapterIndex > book.durChapterIndex ||
(bookProgress.durChapterIndex == book.durChapterIndex &&
bookProgress.durChapterPos > book.durChapterPos)

Loading…
Cancel
Save