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() initOnClick()
savedInstanceState?.let { savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog 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) { if (changeSourceDialog == null) {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog changeSourceDialog = ChangeSourceDialog
.newInstance(it.name, it.author, it.origin) .newInstance(it.name, it.author)
changeSourceDialog?.callBack = this
} }
} }
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag) 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? { override fun oldBook(): Book? {
return viewModel.bookData.value return viewModel.bookData.value
} }

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

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

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

Loading…
Cancel
Save