pull/32/head
gedoor 6 years ago
parent 794a27f079
commit 4c900d71d7
  1. 14
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt
  2. 8
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt

@ -30,7 +30,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
} }
} }
var callback: Callback? = null var callBack: CallBack? = null
val checkedList = HashSet<String>() val checkedList = HashSet<String>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
@ -39,13 +39,13 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let { holder.bind(it, checkedList, callback) } getItem(position)?.let { holder.bind(it, checkedList, callBack) }
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookSource: BookSource, checkedList: HashSet<String>, callback: Callback?) = with(itemView) { fun bind(bookSource: BookSource, checkedList: HashSet<String>, callBack: CallBack?) = with(itemView) {
cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group) cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group)
cb_book_source.onClick { cb_book_source.onClick {
if (cb_book_source.isChecked) { if (cb_book_source.isChecked) {
@ -57,7 +57,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
sw_enabled.isEnabled = bookSource.isEnabled sw_enabled.isEnabled = bookSource.isEnabled
sw_enabled.setOnClickListener{ sw_enabled.setOnClickListener{
bookSource.isEnabled = sw_enabled.isEnabled bookSource.isEnabled = sw_enabled.isEnabled
callback?.update(bookSource) callBack?.update(bookSource)
} }
iv_more.setOnClickListener{ iv_more.setOnClickListener{
val popupMenu = PopupMenu(context, this) val popupMenu = PopupMenu(context, this)
@ -67,10 +67,10 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
popupMenu.setOnMenuItemClickListener { popupMenu.setOnMenuItemClickListener {
when (it.itemId) { when (it.itemId) {
R.id.menu_edit ->{ R.id.menu_edit ->{
callback?.edit(bookSource) callBack?.edit(bookSource)
true} true}
R.id.menu_del ->{ R.id.menu_del ->{
callback?.del(bookSource) callBack?.del(bookSource)
true} true}
R.id.menu_top ->{ true} R.id.menu_top ->{ true}
else -> {false} else -> {false}
@ -81,7 +81,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
} }
} }
interface Callback { interface CallBack {
fun del(bookSource: BookSource) fun del(bookSource: BookSource)
fun edit(bookSource: BookSource) fun edit(bookSource: BookSource)
fun update(bookSource: BookSource) fun update(bookSource: BookSource)

@ -13,8 +13,10 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.ui.sourceedit.SourceEditActivity
import kotlinx.android.synthetic.main.fragment_book_source.* import kotlinx.android.synthetic.main.fragment_book_source.*
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
import org.jetbrains.anko.startActivity
class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) { class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) {
@ -32,7 +34,11 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) {
} }
override fun onCompatOptionsItemSelected(item: MenuItem) { override fun onCompatOptionsItemSelected(item: MenuItem) {
when (item.itemId) {
R.id.action_add_book_source -> {
context?.startActivity<SourceEditActivity>()
}
}
} }
private fun initRecyclerView() { private fun initRecyclerView() {

Loading…
Cancel
Save