From a73dd8a20d96b70e5e2ee29d0ddfb90ca3f3cd45 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Sep 2019 20:48:54 +0800 Subject: [PATCH] up --- .../app/ui/book/info/BookInfoActivity.kt | 10 ++--- .../app/ui/book/read/ReadBookActivity.kt | 10 ++--- .../app/ui/changesource/ChangeSourceDialog.kt | 37 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 3d170cc6e..74d3b4495 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -232,13 +232,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } } - override fun curOrigin(): String? { - return viewModel.bookData.value?.origin - } + override val curOrigin: String? + get() = viewModel.bookData.value?.origin - override fun oldBook(): Book? { - return viewModel.bookData.value - } + override val oldBook: Book? + get() = viewModel.bookData.value override fun changeTo(book: Book) { upLoading(true) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index eb72a47f4..2a3bf10a6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -330,13 +330,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea return viewModel.chapterSize } - override fun curOrigin(): String? { - return viewModel.bookData.value?.origin - } + override val curOrigin: String? + get() = viewModel.bookData.value?.origin - override fun oldBook(): Book? { - return viewModel.bookData.value - } + override val oldBook: Book? + get() = viewModel.bookData.value override fun changeTo(book: Book) { viewModel.changeTo(book) 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 8f02698b9..674db46c1 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 @@ -35,6 +35,7 @@ class ChangeSourceDialog : DialogFragment(), } } + private var callBack: CallBack? = null private lateinit var viewModel: ChangeSourceViewModel private lateinit var changeSourceAdapter: ChangeSourceAdapter @@ -49,6 +50,7 @@ class ChangeSourceDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + callBack = activity as? CallBack viewModel.searchStateData.observe(viewLifecycleOwner, Observer { refresh_progress_bar.isAutoLoading = it }) @@ -114,31 +116,24 @@ class ChangeSourceDialog : DialogFragment(), } override fun changeTo(searchBook: SearchBook) { - val activity = activity - if (activity is CallBack) { - val book = searchBook.toBook() - activity.oldBook()?.let { oldBook -> - book.durChapterIndex = oldBook.durChapterIndex - book.durChapterPos = oldBook.durChapterPos - book.durChapterTitle = oldBook.durChapterTitle - book.customCoverUrl = oldBook.customCoverUrl - book.customIntro = oldBook.customIntro - book.order = oldBook.order - if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = oldBook.getDisplayCover() - } - activity.changeTo(book) + val book = searchBook.toBook() + callBack?.oldBook?.let { oldBook -> + book.durChapterIndex = oldBook.durChapterIndex + book.durChapterPos = oldBook.durChapterPos + book.durChapterTitle = oldBook.durChapterTitle + book.customCoverUrl = oldBook.customCoverUrl + book.customIntro = oldBook.customIntro + book.order = oldBook.order + if (book.coverUrl.isNullOrEmpty()) { + book.coverUrl = oldBook.getDisplayCover() } + callBack?.changeTo(book) } dismiss() } override fun curOrigin(): String { - val activity = activity - if (activity is CallBack) { - return activity.curOrigin() ?: "" - } - return "" + return callBack?.curOrigin ?: "" } override fun adapter(): ChangeSourceAdapter { @@ -146,8 +141,8 @@ class ChangeSourceDialog : DialogFragment(), } interface CallBack { - fun curOrigin(): String? - fun oldBook(): Book? + val curOrigin: String? + val oldBook: Book? fun changeTo(book: Book) }