pull/32/head
kunfei 5 years ago
parent 94c1fc84fa
commit d95f54924c
  1. 19
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt
  2. 18
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  3. 2
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -5,18 +5,35 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_change_source.view.* import kotlinx.android.synthetic.main.item_change_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class ChangeSourceAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_change_source) { class ChangeSourceAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_change_source) {
var callBack: CallBack? = null
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
holder.itemView.apply { holder.itemView.apply {
this.onClick {
callBack?.changeTo(item)
}
tv_origin.text = item.originName tv_origin.text = item.originName
tv_last.text = item.latestChapterTitle tv_last.text = item.latestChapterTitle
callBack?.let {
if (it.curBookUrl() == item.bookUrl) {
iv_checked.visible()
} else {
iv_checked.invisible()
}
} ?: iv_checked.invisible()
} }
} }
interface CallBack {
fun changeTo(searchBook: SearchBook)
fun curBookUrl(): String
}
} }

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.dialog_change_source.* import kotlinx.android.synthetic.main.dialog_change_source.*
@ -22,11 +23,12 @@ class ChangeSourceDialog : DialogFragment() {
companion object { companion object {
const val tag = "changeSourceDialog" const val tag = "changeSourceDialog"
fun newInstance(name: String, author: String): ChangeSourceDialog { fun newInstance(name: String, author: String, bookUrl: String? = null): 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("bookUrl", bookUrl)
changeSourceDialog.arguments = bundle changeSourceDialog.arguments = bundle
return changeSourceDialog return changeSourceDialog
} }
@ -50,6 +52,9 @@ class ChangeSourceDialog : DialogFragment() {
bundle.getString("author")?.let { bundle.getString("author")?.let {
viewModel.author = it viewModel.author = it
} }
bundle.getString("bookUrl")?.let {
viewModel.curBookUrl = it
}
} }
tool_bar.inflateMenu(R.menu.search_view) tool_bar.inflateMenu(R.menu.search_view)
showTitle() showTitle()
@ -72,6 +77,17 @@ class ChangeSourceDialog : DialogFragment() {
private fun initRecyclerView() { private fun initRecyclerView() {
changeSourceAdapter = ChangeSourceAdapter(requireContext()) changeSourceAdapter = ChangeSourceAdapter(requireContext())
changeSourceAdapter.callBack = object : ChangeSourceAdapter.CallBack {
override fun changeTo(searchBook: SearchBook) {
callBack?.changeTo(searchBook.toBook())
dismiss()
}
override fun curBookUrl(): String {
return viewModel.curBookUrl
}
}
recycler_view.layoutManager = LinearLayoutManager(context) recycler_view.layoutManager = LinearLayoutManager(context)
recycler_view.addItemDecoration(DividerItemDecoration(requireContext(), LinearLayout.VERTICAL)) recycler_view.addItemDecoration(DividerItemDecoration(requireContext(), LinearLayout.VERTICAL))
recycler_view.adapter = changeSourceAdapter recycler_view.adapter = changeSourceAdapter

@ -7,7 +7,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var curBookUrl = ""
var name: String = "" var name: String = ""
var author: String = "" var author: String = ""
val searchBookData = MutableLiveData<List<SearchBook>>() val searchBookData = MutableLiveData<List<SearchBook>>()

Loading…
Cancel
Save