From b736fd7ded5af4c65cd488ed60531372e4b250e3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 28 Aug 2019 16:20:10 +0800 Subject: [PATCH] up --- .../app/ui/bookinfo/BookInfoActivity.kt | 8 ++++--- .../app/ui/changesource/ChangeSourceDialog.kt | 21 ++++++++++--------- .../ui/changesource/ChangeSourceViewModel.kt | 1 - .../app/ui/readbook/ReadBookActivity.kt | 8 ++++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index ce7ba7b11..31af4fda5 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -50,7 +50,6 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo initOnClick() savedInstanceState?.let { changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog - changeSourceDialog?.callBack = this } } @@ -178,8 +177,7 @@ class BookInfoActivity : VMBaseActivity(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(R.layout.activity_boo } } + override fun curOrigin(): String? { + return viewModel.bookData.value?.origin + } + override fun oldBook(): Book? { return viewModel.bookData.value } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 0509ba52e..15e830033 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index acfba1ce3..fc096de5f 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -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 = "" diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 6bd81c895..d7507a57c 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -65,7 +65,6 @@ class ReadBookActivity : VMBaseActivity(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(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(R.layout.activity_rea return viewModel.chapterSize } + override fun curOrigin(): String? { + return viewModel.bookData.value?.origin + } + override fun oldBook(): Book? { return viewModel.bookData.value }