pull/1649/head
kunfei 3 years ago
parent 17aaae27a5
commit 439fd5b5bf
  1. 6
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceAdapter.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt
  5. 50
      app/src/main/java/io/legado/app/ui/book/changesource/DiffCallBack.kt
  6. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  7. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@ -25,7 +25,7 @@ import io.legado.app.model.AudioPlay
import io.legado.app.model.BookCover
import io.legado.app.service.AudioPlayService
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity
@ -40,7 +40,7 @@ import java.util.*
*/
class AudioPlayActivity :
VMBaseActivity<ActivityAudioPlayBinding, AudioPlayViewModel>(toolBarTheme = Theme.Dark),
ChangeSourceDialog.CallBack {
ChangeBookSourceDialog.CallBack {
override val binding by viewBinding(ActivityAudioPlayBinding::inflate)
override val viewModel by viewModels<AudioPlayViewModel>()
@ -93,7 +93,7 @@ class AudioPlayActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_change_source -> AudioPlay.book?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author))
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
}
R.id.menu_login -> AudioPlay.bookSource?.let {
startActivity<SourceLoginActivity> {

@ -16,9 +16,9 @@ import io.legado.app.utils.visible
import splitties.views.onLongClick
class ChangeSourceAdapter(
class ChangeBookSourceAdapter(
context: Context,
val viewModel: ChangeSourceViewModel,
val viewModel: ChangeBookSourceViewModel,
val callBack: CallBack
) : DiffRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) {

@ -31,9 +31,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class ChangeSourceDialog() : BaseDialogFragment(R.layout.dialog_change_source),
class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_change_source),
Toolbar.OnMenuItemClickListener,
ChangeSourceAdapter.CallBack {
ChangeBookSourceAdapter.CallBack {
constructor(name: String, author: String) : this() {
arguments = Bundle().apply {
@ -45,8 +45,8 @@ class ChangeSourceDialog() : BaseDialogFragment(R.layout.dialog_change_source),
private val binding by viewBinding(DialogChangeSourceBinding::bind)
private val groups = linkedSetOf<String>()
private val callBack: CallBack? get() = activity as? CallBack
private val viewModel: ChangeSourceViewModel by viewModels()
private val adapter by lazy { ChangeSourceAdapter(requireContext(), viewModel, this) }
private val viewModel: ChangeBookSourceViewModel by viewModels()
private val adapter by lazy { ChangeBookSourceAdapter(requireContext(), viewModel, this) }
private val editSourceResult =
registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) {
viewModel.startSearch()

@ -32,7 +32,7 @@ import java.util.concurrent.Executors
import kotlin.math.min
@Suppress("MemberVisibilityCanBePrivate")
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
class ChangeBookSourceViewModel(application: Application) : BaseViewModel(application) {
private val threadCount = AppConfig.threadCount
private var searchPool: ExecutorCoroutineDispatcher? = null
val searchStateData = MutableLiveData<Boolean>()

@ -1,50 +0,0 @@
package io.legado.app.ui.book.changesource
import android.os.Bundle
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.data.entities.SearchBook
class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems: List<SearchBook>) :
DiffUtil.Callback() {
override fun getOldListSize(): Int {
return oldItems.size
}
override fun getNewListSize(): Int {
return newItems.size
}
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return oldItem.bookUrl == newItem.bookUrl
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return when {
oldItem.originName != newItem.originName -> false
oldItem.latestChapterTitle != newItem.latestChapterTitle -> false
else -> true
}
}
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
val payload = Bundle()
if (oldItem.originName != newItem.originName) {
payload.putString("name", newItem.originName)
}
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) {
payload.putString("latest", newItem.latestChapterTitle)
}
if (payload.isEmpty) {
return null
}
return payload
}
}

@ -31,7 +31,7 @@ import io.legado.app.model.BookCover
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.audio.AudioPlayActivity
import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity
@ -49,7 +49,7 @@ import kotlinx.coroutines.withContext
class BookInfoActivity :
VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
GroupSelectDialog.CallBack,
ChangeSourceDialog.CallBack,
ChangeBookSourceDialog.CallBack,
ChangeCoverDialog.CallBack {
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
@ -301,7 +301,7 @@ class BookInfoActivity :
}
tvChangeSource.setOnClickListener {
viewModel.bookData.value?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author))
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
}
}
tvTocView.setOnClickListener {

@ -37,7 +37,7 @@ import io.legado.app.model.ReadBook
import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
@ -69,7 +69,7 @@ class ReadBookActivity : BaseReadBookActivity(),
ReadMenu.CallBack,
SearchMenu.CallBack,
ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack,
ChangeBookSourceDialog.CallBack,
ReadBook.CallBack,
AutoReadDialog.CallBack,
TocRegexDialog.CallBack,
@ -239,13 +239,13 @@ class ReadBookActivity : BaseReadBookActivity(),
R.id.menu_book_change_source -> {
binding.readMenu.runMenuOut()
ReadBook.book?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author))
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
}
}
R.id.menu_chapter_change_source -> {
binding.readMenu.runMenuOut()
ReadBook.book?.let {
showDialogFragment(ChangeSourceDialog(it.name, it.author))
showDialogFragment(ChangeBookSourceDialog(it.name, it.author))
}
}
R.id.menu_refresh_dur -> {

Loading…
Cancel
Save