diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1f9cc2870..bf139ba5e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -12,6 +12,10 @@ * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 关于最近版本有时候界面没有数据的问题是因为把LiveData组件换成了谷歌推荐的Flow组件导致的问题,正在查找解决办法 +**2021/08/09** + +1. 修复选择文字不能选择单个文字的bug + **2021/08/08** 1. 背景图片添加模糊设置 diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index fe4319b13..3f3f04de1 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -24,7 +24,7 @@ val appDb by lazy { RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class, RuleSub::class], - version = 33, + version = 34, exportSchema = true ) abstract class AppDatabase : RoomDatabase() { @@ -60,7 +60,7 @@ abstract class AppDatabase : RoomDatabase() { migration_19_20, migration_20_21, migration_21_22, migration_22_23, migration_23_24, migration_24_25, migration_25_26, migration_26_27, migration_27_28, migration_28_29, migration_29_30, migration_30_31, - migration_31_32, migration_32_33 + migration_31_32, migration_32_33, migration_33_34 ) .allowMainThreadQueries() .addCallback(dbCallback) @@ -331,6 +331,12 @@ abstract class AppDatabase : RoomDatabase() { ) } } + + private val migration_33_34 = object : Migration(33, 34) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE `book_groups` ADD `cover` TEXT") + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index a4e71a0c3..f19f5f05c 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -14,6 +14,7 @@ data class BookGroup( @PrimaryKey val groupId: Long = 0b1, var groupName: String, + var cover: String? = null, var order: Int = 0, var show: Boolean = true ) : Parcelable { @@ -36,6 +37,7 @@ data class BookGroup( if (other is BookGroup) { return other.groupId == groupId && other.groupName == groupName + && other.cover == cover && other.order == order && other.show == show } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupEdit.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupEdit.kt deleted file mode 100644 index 79d66bd42..000000000 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupEdit.kt +++ /dev/null @@ -1,55 +0,0 @@ -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 { - textInputLayout.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 { - bookGroup.groupName = it - 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() - } - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt new file mode 100644 index 000000000..2bee351c8 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt @@ -0,0 +1,110 @@ +package io.legado.app.ui.book.group + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.viewModels +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment +import io.legado.app.data.entities.BookGroup +import io.legado.app.databinding.DialogBookGroupEditBinding +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.theme.primaryColor +import io.legado.app.utils.gone +import io.legado.app.utils.toastOnUi +import io.legado.app.utils.viewbindingdelegate.viewBinding +import io.legado.app.utils.windowSize +import splitties.views.onClick + +class GroupEditDialog : BaseDialogFragment() { + + companion object { + + fun start(fragmentManager: FragmentManager, bookGroup: BookGroup? = null) { + GroupEditDialog().apply { + arguments = Bundle().apply { + putParcelable("group", bookGroup) + } + }.show(fragmentManager, "bookGroupEdit") + } + + } + + private val binding by viewBinding(DialogBookGroupEditBinding::bind) + private val viewModel by viewModels() + private var bookGroup: BookGroup? = null + + override fun onStart() { + super.onStart() + val dm = requireActivity().windowSize + dialog?.window?.setLayout( + (dm.widthPixels * 0.9).toInt(), + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_book_group_edit, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.toolBar.setBackgroundColor(primaryColor) + bookGroup = arguments?.getParcelable("group") + bookGroup?.let { + binding.tieGroupName.setText(it.groupName) + binding.ivCover.load(it.cover) + } ?: let { + binding.toolBar.title = getString(R.string.add_group) + binding.btnDelete.gone() + } + binding.run { + btnCancel.onClick { + dismiss() + } + btnOk.onClick { + val groupName = tieGroupName.text?.toString() + if (groupName.isNullOrEmpty()) { + toastOnUi("分组名称不能为空") + } else { + bookGroup?.let { + it.groupName = groupName + it.cover = binding.ivCover.path + viewModel.upGroup(it) { + dismiss() + } + } ?: let { + viewModel.addGroup(groupName, binding.ivCover.path) { + dismiss() + } + } + } + + } + btnDelete.onClick { + deleteGroup { + bookGroup?.let { + viewModel.delGroup(it) { + dismiss() + } + } + } + } + } + } + + private fun deleteGroup(ok: () -> Unit) { + alert(R.string.delete, R.string.sure_del) { + okButton { + ok.invoke() + } + noButton() + }.show() + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index b3e7dfc66..c31d4a5aa 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.group -import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.view.LayoutInflater @@ -18,17 +17,14 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.appDb import io.legado.app.data.entities.BookGroup -import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemBookGroupManageBinding -import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.requestInputMethod import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible import io.legado.app.utils.windowSize @@ -94,29 +90,11 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_add -> addGroup() + R.id.menu_add -> GroupEditDialog.start(childFragmentManager) } return true } - @SuppressLint("InflateParams") - private fun addGroup() { - alert(title = getString(R.string.add_group)) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { - textInputLayout.setHint(R.string.group_name) - } - customView { alertBinding.root } - yesButton { - alertBinding.editView.text?.toString()?.let { - if (it.isNotBlank()) { - viewModel.addGroup(it) - } - } - } - noButton() - }.show().requestInputMethod() - } - private inner class GroupAdapter(context: Context) : RecyclerAdapter(context), ItemTouchCallback.Callback { @@ -144,7 +122,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener binding.run { tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { bookGroup -> - GroupEdit.show(context, layoutInflater, bookGroup) + GroupEditDialog.start(childFragmentManager, bookGroup) } } swShow.setOnCheckedChangeListener { buttonView, isChecked -> diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 6beb2e626..76b410de3 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.group -import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.view.LayoutInflater @@ -20,16 +19,13 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.appDb import io.legado.app.data.entities.BookGroup import io.legado.app.databinding.DialogBookGroupPickerBinding -import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.ItemGroupSelectBinding -import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.requestInputMethod import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize import kotlinx.coroutines.flow.collect @@ -116,46 +112,11 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_add -> addGroup() + R.id.menu_add -> GroupEditDialog.start(childFragmentManager) } return true } - @SuppressLint("InflateParams") - private fun addGroup() { - alert(title = getString(R.string.add_group)) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { - textInputLayout.setHint(R.string.group_name) - } - customView { alertBinding.root } - yesButton { - alertBinding.editView.text?.toString()?.let { - if (it.isNotBlank()) { - viewModel.addGroup(it) - } - } - } - noButton() - }.show().requestInputMethod() - } - - @SuppressLint("InflateParams") - private fun editGroup(bookGroup: BookGroup) { - alert(title = getString(R.string.group_edit)) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { - textInputLayout.setHint(R.string.group_name) - editView.setText(bookGroup.groupName) - } - customView { alertBinding.root } - yesButton { - alertBinding.editView.text?.toString()?.let { - viewModel.upGroup(bookGroup.copy(groupName = it)) - } - } - noButton() - }.show().requestInputMethod() - } - private inner class GroupAdapter(context: Context) : RecyclerAdapter(context), ItemTouchCallback.Callback { @@ -192,7 +153,9 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } } } - tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } + tvEdit.setOnClickListener { + GroupEditDialog.start(childFragmentManager, getItem(holder.layoutPosition)) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt index 3b78e45f8..752c27198 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt @@ -7,7 +7,15 @@ import io.legado.app.data.entities.BookGroup class GroupViewModel(application: Application) : BaseViewModel(application) { - fun addGroup(groupName: String) { + fun upGroup(vararg bookGroup: BookGroup, finally: (() -> Unit)? = null) { + execute { + appDb.bookGroupDao.update(*bookGroup) + }.onFinally { + finally?.invoke() + } + } + + fun addGroup(groupName: String, cover: String?, finally: () -> Unit) { execute { var id = 1L val idsSum = appDb.bookGroupDao.idsSum @@ -17,19 +25,16 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { val bookGroup = BookGroup( groupId = id, groupName = groupName, + cover = cover, order = appDb.bookGroupDao.maxOrder.plus(1) ) appDb.bookGroupDao.insert(bookGroup) + }.onFinally { + finally() } } - fun upGroup(vararg bookGroup: BookGroup) { - execute { - appDb.bookGroupDao.update(*bookGroup) - } - } - - fun delGroup(vararg bookGroup: BookGroup) { + fun delGroup(vararg bookGroup: BookGroup, finally: () -> Unit) { execute { appDb.bookGroupDao.delete(*bookGroup) bookGroup.forEach { group -> @@ -39,6 +44,8 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { } appDb.bookDao.update(*books.toTypedArray()) } + }.onFinally { + finally() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index acf725799..070c4e28f 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -22,7 +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.group.GroupEditDialog import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.search.SearchActivity @@ -190,7 +190,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), putExtra("name", item.name) putExtra("author", item.author) } - is BookGroup -> GroupEdit.show(requireContext(), layoutInflater, item) + is BookGroup -> GroupEditDialog.start(childFragmentManager, item) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 3e823829c..91a80a35b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -30,6 +30,8 @@ class CoverImageView @JvmOverloads constructor( ) { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() + var path: String? = null + private set private var nameHeight = 0f private var authorHeight = 0f private val namePaint by lazy { @@ -131,7 +133,8 @@ class CoverImageView @JvmOverloads constructor( } } - fun load(path: String?, name: String?, author: String?) { + fun load(path: String?, name: String? = null, author: String? = null) { + this.path = path setText(name, author) if (AppConfig.useDefaultCover) { ImageLoader.load(context, defaultDrawable) diff --git a/app/src/main/res/layout/dialog_book_group_edit.xml b/app/src/main/res/layout/dialog_book_group_edit.xml new file mode 100644 index 000000000..13240a0d4 --- /dev/null +++ b/app/src/main/res/layout/dialog_book_group_edit.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file