From 9dcedd4e29f40c78e0e7ad54d94d0b8fa75870d7 Mon Sep 17 00:00:00 2001 From: GKF Date: Tue, 11 Jun 2019 08:40:10 +0800 Subject: [PATCH] up --- .../ui/main/bookshelf/BookshelfFragment.kt | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 45d9b713e..d8c3a6a94 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/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.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 bookGroupAdapter: BookGroupAdapter @@ -53,36 +53,12 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { } private fun initRecyclerView() { + refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context)) tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context) rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) bookGroupAdapter = BookGroupAdapter() rv_book_group.adapter = bookGroupAdapter - bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack { - 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(Pair("data", bookGroup)) - } - } - } + bookGroupAdapter.callBack = this rv_bookshelf.layoutManager = LinearLayoutManager(context) rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL)) bookshelfAdapter = BookshelfAdapter() @@ -101,4 +77,29 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { 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(Pair("data", bookGroup)) + } + } + } \ No newline at end of file