pull/1198/head
gedoor 3 years ago
parent 3fad9d8a59
commit 0d0f07ba8c
  1. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 54
      app/src/main/java/io/legado/app/ui/book/group/GroupEdit.kt
  3. 37
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  4. 32
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -143,7 +143,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
get() = appCtx.getPrefBoolean(PreferKey.autoRefresh)
var threadCount: Int
get() = appCtx.getPrefInt(PreferKey.threadCount, 16)
get() = appCtx.getPrefInt(PreferKey.threadCount, 8)
set(value) {
appCtx.putPrefInt(PreferKey.threadCount, value)
}

@ -0,0 +1,54 @@
package io.legado.app.ui.book.group
import android.content.Context
import android.view.LayoutInflater
import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.requestInputMethod
object GroupEdit {
fun show(context: Context, layoutInflater: LayoutInflater, bookGroup: BookGroup) = context.run {
alert(title = getString(R.string.group_edit)) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name)
editView.setText(bookGroup.groupName)
}
if (bookGroup.groupId >= 0) {
neutralButton(R.string.delete) {
deleteGroup(context, bookGroup)
}
}
customView { alertBinding.root }
yesButton {
alertBinding.editView.text?.toString()?.let {
Coroutine.async {
appDb.bookGroupDao.update(bookGroup)
}
}
}
noButton()
}.show().requestInputMethod()
}
private fun deleteGroup(context: Context, bookGroup: BookGroup) = context.run {
alert(R.string.delete, R.string.sure_del) {
okButton {
Coroutine.async {
appDb.bookGroupDao.delete(bookGroup)
val books = appDb.bookDao.getBooksByGroup(bookGroup.groupId)
books.forEach {
it.group = it.group - bookGroup.groupId
}
appDb.bookDao.update(*books.toTypedArray())
}
}
noButton()
}.show()
}
}

@ -117,37 +117,6 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}.show().requestInputMethod()
}
@SuppressLint("InflateParams")
private fun editGroup(bookGroup: BookGroup) {
alert(title = getString(R.string.group_edit)) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name)
editView.setText(bookGroup.groupName)
}
if (bookGroup.groupId >= 0) {
neutralButton(R.string.delete) {
deleteGroup(bookGroup)
}
}
customView { alertBinding.root }
yesButton {
alertBinding.editView.text?.toString()?.let {
viewModel.upGroup(bookGroup.copy(groupName = it))
}
}
noButton()
}.show().requestInputMethod()
}
private fun deleteGroup(bookGroup: BookGroup) {
alert(R.string.delete, R.string.sure_del) {
okButton {
viewModel.delGroup(bookGroup)
}
noButton()
}.show()
}
private inner class GroupAdapter(context: Context) :
RecyclerAdapter<BookGroup, ItemBookGroupManageBinding>(context),
ItemTouchCallback.Callback {
@ -173,7 +142,11 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) {
binding.run {
tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } }
tvEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { bookGroup ->
GroupEdit.show(context, layoutInflater, bookGroup)
}
}
swShow.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed) {
getItem(holder.layoutPosition)?.let {

@ -22,6 +22,7 @@ import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.audio.AudioPlayActivity
import io.legado.app.ui.book.group.GroupEdit
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
@ -52,7 +53,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
override var books: List<Book> = emptyList()
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view)
setSupportToolbar(binding.titleBar.toolbar)
initRecyclerView()
initGroupData()
@ -159,34 +159,30 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
}
override fun onItemClick(position: Int) {
if (position < bookGroups.size) {
val bookGroup = bookGroups[position]
groupId = bookGroup.groupId
initBooksData()
} else {
val book = books[position - bookGroups.size]
when (book.type) {
when (val item = getItem(position)) {
is Book -> when (item.type) {
BookType.audio ->
startActivity<AudioPlayActivity> {
putExtra("bookUrl", book.bookUrl)
putExtra("bookUrl", item.bookUrl)
}
else -> startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl)
putExtra("bookUrl", item.bookUrl)
}
}
is BookGroup -> {
groupId = item.groupId
initBooksData()
}
}
}
override fun onItemLongClick(position: Int) {
if (position < bookGroups.size) {
groupId = bookGroups[position].groupId
initBooksData()
} else {
val book = books[position - bookGroups.size]
startActivity<BookInfoActivity> {
putExtra("name", book.name)
putExtra("author", book.author)
when (val item = getItem(position)) {
is Book -> startActivity<BookInfoActivity> {
putExtra("name", item.name)
putExtra("author", item.author)
}
is BookGroup -> GroupEdit.show(requireContext(), layoutInflater, item)
}
}

Loading…
Cancel
Save