diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1b72cee66..159dcf354 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -7,6 +7,7 @@ * 应用被杀死时停止朗读 * 默认封面添加删除操作 * 备份阅读记录 +* 书源添加移除分组支持多选,多个分组以逗号(中英均可)隔开 **2020/08/22** * 添加阅读时间记录 diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 99b2c5ac2..da57654f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -227,6 +227,8 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_check_source -> checkSource() R.id.menu_top_sel -> viewModel.topSource(*adapter.getSelection().toTypedArray()) R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.getSelection().toTypedArray()) + R.id.menu_add_group -> selectionAddToGroups() + R.id.menu_remove_group -> selectionRemoveFromGroups() } return true } @@ -253,6 +255,48 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }.show().applyTint() } + @SuppressLint("InflateParams") + private fun selectionAddToGroups() { + alert(titleResource = R.string.add_group) { + var editText: AutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + edit_view.setHint(R.string.group_name) + } + } + okButton { + editText?.text?.toString()?.let { + if (it.isNotEmpty()) { + viewModel.selectionAddToGroups(adapter.getSelection(), it) + } + } + } + noButton { } + }.show().applyTint() + } + + @SuppressLint("InflateParams") + private fun selectionRemoveFromGroups() { + alert(titleResource = R.string.remove_group) { + var editText: AutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + edit_view.setHint(R.string.group_name) + } + } + okButton { + editText?.text?.toString()?.let { + if (it.isNotEmpty()) { + viewModel.selectionRemoveFromGroups(adapter.getSelection(), it) + } + } + } + noButton { } + }.show().applyTint() + } + private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 866122b9c..8038cf0db 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -93,6 +93,44 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } } + fun selectionAddToGroups(sources: List, groups: String) { + execute { + val list = arrayListOf() + sources.forEach { + val newGroupList = arrayListOf() + it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { + newGroupList.add(it) + } + groups.splitNotBlank(",", ";", ",").forEach { + newGroupList.add(it) + } + val lh = LinkedHashSet(newGroupList) + val newGroup = ArrayList(lh).joinToString(separator = ",") + list.add(it.copy(bookSourceGroup = newGroup)) + } + App.db.bookSourceDao().update(*list.toTypedArray()) + } + } + + fun selectionRemoveFromGroups(sources: List, groups: String) { + execute { + val list = arrayListOf() + sources.forEach { + val newGroupList = arrayListOf() + it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { + newGroupList.add(it) + } + groups.splitNotBlank(",", ";", ",").forEach { + newGroupList.remove(it) + } + val lh = LinkedHashSet(newGroupList) + val newGroup = ArrayList(lh).joinToString(separator = ",") + list.add(it.copy(bookSourceGroup = newGroup)) + } + App.db.bookSourceDao().update(*list.toTypedArray()) + } + } + fun delSelection(sources: List) { execute { App.db.bookSourceDao().delete(*sources.toTypedArray()) diff --git a/app/src/main/res/menu/book_source_sel.xml b/app/src/main/res/menu/book_source_sel.xml index 5ed76592d..02a6178ba 100644 --- a/app/src/main/res/menu/book_source_sel.xml +++ b/app/src/main/res/menu/book_source_sel.xml @@ -12,6 +12,16 @@ android:title="@string/disable_selection" app:showAsAction="never" /> + + + + 編輯分組 移入分組 添加分組 + 移除分組 新建替換 分組 分組: %s diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 59e5fc685..52dd21635 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -554,6 +554,7 @@ 編輯分組 移入分組 添加分組 + 移除分組 建立取代 分組 分組: %s diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3e6402a56..5aaae10c1 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -555,6 +555,7 @@ 编辑分组 移入分组 添加分组 + 移除分组 新建替换 分组 分组: %s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 585b95bd0..6c2ed0ecc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -557,6 +557,7 @@ Group editing Move to group Add to Groups + Remove from Groups New replacement Group Group: %s