|
|
@ -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) |
|
|
|
} |
|
|
|
} |
|
|
|