pull/32/head
gedoor 6 years ago
parent 811c979141
commit 9e1e49ba66
  1. 8
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt
  2. 3
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfViewModel.kt
  3. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookGroupAdapter.kt
  4. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  5. 5
      app/src/main/res/layout/activity_bookshelf.xml
  6. 1
      app/src/main/res/layout/item_book_group.xml

@ -4,6 +4,7 @@ import android.os.Bundle
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_bookshelf.*
class BookshelfActivity : BaseActivity<BookshelfViewModel>() { class BookshelfActivity : BaseActivity<BookshelfViewModel>() {
override val viewModel: BookshelfViewModel override val viewModel: BookshelfViewModel
@ -12,7 +13,12 @@ class BookshelfActivity : BaseActivity<BookshelfViewModel>() {
get() = R.layout.activity_bookshelf get() = R.layout.activity_bookshelf
override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) { override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) {
if (viewModel.bookGroup == null) {
viewModel.bookGroup = intent.getParcelableExtra("data")
}
viewModel.bookGroup?.let {
title_bar.title = it.groupName
}
} }
} }

@ -2,7 +2,10 @@ package io.legado.app.ui.bookshelf
import android.app.Application import android.app.Application
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookGroup
class BookshelfViewModel(application: Application) : BaseViewModel(application) { class BookshelfViewModel(application: Application) : BaseViewModel(application) {
var bookGroup: BookGroup? = null
} }

@ -46,12 +46,10 @@ class BookGroupAdapter : PagedListAdapter<BookGroup, BookGroupAdapter.MyViewHold
} }
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
if (position < defaultGroups.size) { when {
holder.bind(defaultGroups[position], callBack) position < defaultGroups.size -> holder.bind(defaultGroups[position], callBack)
} else if (position == itemCount - 1) { position == itemCount - 1 -> holder.bind(addBookGroup, callBack)
holder.bind(addBookGroup, callBack) else -> currentList?.get(position - defaultGroups.size)?.let {
} else {
currentList?.get(position - defaultGroups.size)?.let {
holder.bind(it, callBack) holder.bind(it, callBack)
} }
} }
@ -61,11 +59,11 @@ class BookGroupAdapter : PagedListAdapter<BookGroup, BookGroupAdapter.MyViewHold
fun bind(bookGroup: BookGroup, callBack: CallBack?) = with(itemView) { fun bind(bookGroup: BookGroup, callBack: CallBack?) = with(itemView) {
tv_group.text = bookGroup.groupName tv_group.text = bookGroup.groupName
tv_group.setOnClickListener { callBack?.open(bookGroup.groupId) } tv_group.setOnClickListener { callBack?.open(bookGroup) }
} }
} }
interface CallBack { interface CallBack {
fun open(groupId: Int) fun open(bookGroup: BookGroup)
} }
} }

@ -17,11 +17,13 @@ import io.legado.app.base.BaseFragment
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.utils.disableAutoFill import io.legado.app.utils.disableAutoFill
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
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) {
@ -48,8 +50,8 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
bookGroupAdapter = BookGroupAdapter() bookGroupAdapter = BookGroupAdapter()
rv_book_group.adapter = bookGroupAdapter rv_book_group.adapter = bookGroupAdapter
bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack { bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack {
override fun open(groupId: Int) { override fun open(bookGroup: BookGroup) {
when (groupId) { when (bookGroup.groupId) {
-10 -> context?.let { -10 -> context?.let {
MaterialDialog(it).show { MaterialDialog(it).show {
window?.decorView?.disableAutoFill() window?.decorView?.disableAutoFill()
@ -69,6 +71,7 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
positiveButton(R.string.ok) positiveButton(R.string.ok)
} }
} }
else -> context?.startActivity<BookshelfActivity>(Pair("data", bookGroup))
} }
} }
} }

@ -4,4 +4,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>

@ -3,5 +3,6 @@
android:id="@+id/tv_group" android:id="@+id/tv_group"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/bg_ib_pre"
android:layout_margin="5dp" android:layout_margin="5dp"
android:padding="5dp" /> android:padding="5dp" />
Loading…
Cancel
Save