pull/1264/head
gedoor 3 years ago
parent fcd2b9b967
commit db2d3cc4c4
  1. 23
      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. 43
      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. 13
      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. 19
      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. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  12. 33
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  13. 57
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  14. 13
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  15. 7
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  16. 9
      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,17 +179,16 @@ 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)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = index
}
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
}
}

@ -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,13 +110,11 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
@SuppressLint("NotifyDataSetChanged")
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowAll().collect {
groupList.clear()
groupList.addAll(it)
adapter.notifyDataSetChanged()
upMenu()
}
appDb.bookGroupDao.flowAll().collect {
groupList.clear()
groupList.addAll(it)
adapter.notifyDataSetChanged()
upMenu()
}
}
}
@ -125,24 +122,22 @@ 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()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime }
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
adapter.setItems(books)
3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime }
}
adapter.setItems(books)
}
}
}

@ -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,14 +153,12 @@ class ChangeSourceDialog : BaseDialogFragment(),
adapter.setItems(it)
})
launch {
lifecycle.whenStarted {
appDb.bookSourceDao.flowGroupEnabled().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
upGroupMenu()
appDb.bookSourceDao.flowGroupEnabled().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
upGroupMenu()
}
}
}

@ -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,16 +109,14 @@ 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)
}.collect {
adapter.setItems(it)
if (searchKey.isNullOrBlank() && !scrollToDurChapter) {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
scrollToDurChapter = true
}
when {
searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl)
else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey)
}.collect {
adapter.setItems(it)
if (searchKey.isNullOrBlank() && !scrollToDurChapter) {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
scrollToDurChapter = 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,11 +78,9 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
private fun initBookGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowShow().collect {
viewModel.checkGroup(it)
upGroup(it)
}
appDb.bookGroupDao.flowShow().collect {
viewModel.checkGroup(it)
upGroup(it)
}
}
}

@ -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,25 +106,23 @@ 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()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty()
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime }
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty()
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
booksAdapter.setItems(books)
3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime }
}
booksAdapter.setItems(books)
}
}
}

@ -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,13 +100,11 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
@SuppressLint("NotifyDataSetChanged")
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.bookGroupDao.flowShow().collect {
if (it != bookGroups) {
bookGroups = it
booksAdapter.notifyDataSetChanged()
binding.tvEmptyMsg.isGone = getItemCount() > 0
}
appDb.bookGroupDao.flowShow().collect {
if (it != bookGroups) {
bookGroups = it
booksAdapter.notifyDataSetChanged()
binding.tvEmptyMsg.isGone = getItemCount() > 0
}
}
}
@ -126,31 +123,29 @@ 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()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending {
it.latestChapterTime
}
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
3 -> list.sortedBy {
it.order
}
else -> list.sortedByDescending {
it.durChapterTime
}
when (groupId) {
AppConst.bookGroupAllId -> appDb.bookDao.flowAll()
AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal()
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
else -> appDb.bookDao.flowByGroup(groupId)
}.collect { list ->
books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending {
it.latestChapterTime
}
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}
3 -> list.sortedBy {
it.order
}
else -> list.sortedByDescending {
it.durChapterTime
}
booksAdapter.notifyDataSetChanged()
binding.tvEmptyMsg.isGone = getItemCount() > 0
}
booksAdapter.notifyDataSetChanged()
binding.tvEmptyMsg.isGone = getItemCount() > 0
}
}
}

@ -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,14 +121,12 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private fun initGroupData() {
launch {
lifecycle.whenStarted {
appDb.rssSourceDao.flowGroup().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
upGroupsMenu()
appDb.rssSourceDao.flowGroup().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
upGroupsMenu()
}
}
}

@ -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,10 +97,8 @@ 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)
}
appDb.rssArticleDao.flowByOriginSort(rssUrl, viewModel.sortName).collect {
adapter.setItems(it)
}
}
}

@ -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,11 +62,9 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() {
launch {
lifecycle.whenStarted {
appDb.ruleSubDao.flowAll().collect {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
}
appDb.ruleSubDao.flowAll().collect {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
}
}
}

@ -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