pull/32/head
kunfei 5 years ago
parent 6fed09063d
commit b736fd7ded
  1. 8
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 21
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  3. 1
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  4. 8
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt

@ -50,7 +50,6 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
initOnClick()
savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
changeSourceDialog?.callBack = this
}
}
@ -178,8 +177,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
if (changeSourceDialog == null) {
viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog
.newInstance(it.name, it.author, it.origin)
changeSourceDialog?.callBack = this
.newInstance(it.name, it.author)
}
}
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
@ -216,6 +214,10 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
}
}
override fun curOrigin(): String? {
return viewModel.bookData.value?.origin
}
override fun oldBook(): Book? {
return viewModel.bookData.value
}

@ -24,12 +24,11 @@ class ChangeSourceDialog : DialogFragment(),
companion object {
const val tag = "changeSourceDialog"
fun newInstance(name: String, author: String, origin: String): ChangeSourceDialog {
fun newInstance(name: String, author: String): ChangeSourceDialog {
val changeSourceDialog = ChangeSourceDialog()
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
bundle.putString("origin", origin)
changeSourceDialog.arguments = bundle
return changeSourceDialog
}
@ -37,7 +36,6 @@ class ChangeSourceDialog : DialogFragment(),
private lateinit var viewModel: ChangeSourceViewModel
private lateinit var changeSourceAdapter: ChangeSourceAdapter
var callBack: CallBack? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
viewModel = getViewModel(ChangeSourceViewModel::class.java)
@ -53,9 +51,6 @@ class ChangeSourceDialog : DialogFragment(),
bundle.getString("author")?.let {
viewModel.author = it
}
bundle.getString("origin")?.let {
viewModel.curOrigin = it
}
}
tool_bar.inflateMenu(R.menu.search_view)
showTitle()
@ -109,9 +104,10 @@ class ChangeSourceDialog : DialogFragment(),
}
override fun changeTo(searchBook: SearchBook) {
callBack?.let {
val activity = activity
if (activity is CallBack) {
val book = searchBook.toBook()
it.oldBook()?.let { oldBook ->
activity.oldBook()?.let { oldBook ->
book.durChapterIndex = oldBook.durChapterIndex
book.durChapterPos = oldBook.durChapterPos
book.durChapterTitle = oldBook.durChapterTitle
@ -122,13 +118,17 @@ class ChangeSourceDialog : DialogFragment(),
book.coverUrl = oldBook.getDisplayCover()
}
}
it.changeTo(book)
activity.changeTo(book)
}
dismiss()
}
override fun curOrigin(): String {
return viewModel.curOrigin
val activity = activity
if (activity is CallBack) {
return activity.curOrigin() ?: ""
}
return ""
}
override fun adapter(): ChangeSourceAdapter {
@ -136,6 +136,7 @@ class ChangeSourceDialog : DialogFragment(),
}
interface CallBack {
fun curOrigin(): String?
fun oldBook(): Book?
fun changeTo(book: Book)
}

@ -16,7 +16,6 @@ import org.jetbrains.anko.debug
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null
var curOrigin = ""
var name: String = ""
var author: String = ""
var screenKey: String = ""

@ -65,7 +65,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
savedInstanceState?.let {
changeSourceDialog =
supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
changeSourceDialog?.callBack = this
}
setScreenBrightness(getPrefInt("brightness", 100))
}
@ -182,8 +181,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
if (changeSourceDialog == null) {
viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog
.newInstance(it.name, it.author, it.origin)
changeSourceDialog?.callBack = this
.newInstance(it.name, it.author)
}
}
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
@ -305,6 +303,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
return viewModel.chapterSize
}
override fun curOrigin(): String? {
return viewModel.bookData.value?.origin
}
override fun oldBook(): Book? {
return viewModel.bookData.value
}

Loading…
Cancel
Save