pull/32/head
GKF 6 years ago
parent 81bd481a0d
commit 9dcedd4e29
  1. 55
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -26,7 +26,7 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColor import org.jetbrains.anko.textColor
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf), BookGroupAdapter.CallBack {
private lateinit var bookshelfAdapter: BookshelfAdapter private lateinit var bookshelfAdapter: BookshelfAdapter
private lateinit var bookGroupAdapter: BookGroupAdapter private lateinit var bookGroupAdapter: BookGroupAdapter
@ -53,36 +53,12 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
} }
private fun initRecyclerView() { private fun initRecyclerView() {
refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context))
tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context) tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context)
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
bookGroupAdapter = BookGroupAdapter() bookGroupAdapter = BookGroupAdapter()
rv_book_group.adapter = bookGroupAdapter rv_book_group.adapter = bookGroupAdapter
bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack { bookGroupAdapter.callBack = this
override fun open(bookGroup: BookGroup) {
when (bookGroup.groupId) {
-10 -> context?.let {
MaterialDialog(it).show {
window?.decorView?.disableAutoFill()
title(text = "新建分组")
input(hint = "分组名称") { _, charSequence ->
run {
GlobalScope.launch {
App.db.bookGroupDao().insert(
BookGroup(
App.db.bookGroupDao().maxId + 1,
charSequence.toString()
)
)
}
}
}
positiveButton(R.string.ok)
}
}
else -> context?.startActivity<BookshelfActivity>(Pair("data", bookGroup))
}
}
}
rv_bookshelf.layoutManager = LinearLayoutManager(context) rv_bookshelf.layoutManager = LinearLayoutManager(context)
rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL)) rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL))
bookshelfAdapter = BookshelfAdapter() bookshelfAdapter = BookshelfAdapter()
@ -101,4 +77,29 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) }) bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) })
} }
override fun open(bookGroup: BookGroup) {
when (bookGroup.groupId) {
-10 -> context?.let {
MaterialDialog(it).show {
window?.decorView?.disableAutoFill()
title(text = "新建分组")
input(hint = "分组名称") { _, charSequence ->
run {
GlobalScope.launch {
App.db.bookGroupDao().insert(
BookGroup(
App.db.bookGroupDao().maxId + 1,
charSequence.toString()
)
)
}
}
}
positiveButton(R.string.ok)
}
}
else -> context?.startActivity<BookshelfActivity>(Pair("data", bookGroup))
}
}
} }
Loading…
Cancel
Save