From da8cbb497bfc1d3d13d4ef771088c134f19d0072 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Sun, 23 Aug 2020 19:56:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B9=A6=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=88=86=E7=BB=84=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceActivity.kt | 44 +++++++++++++++++++ .../book/source/manage/BookSourceViewModel.kt | 38 ++++++++++++++++ app/src/main/res/menu/book_source_sel.xml | 10 +++++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 96 insertions(+) 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..6e0552724 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 -> selectionAddToGroup() + R.id.menu_remove_group -> selectionRemoveFromGroup() } return true } @@ -253,6 +255,48 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }.show().applyTint() } + @SuppressLint("InflateParams") + private fun selectionAddToGroup() { + 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.selectionAddToGroup(adapter.getSelection(), it) + } + } + } + noButton { } + }.show().applyTint() + } + + @SuppressLint("InflateParams") + private fun selectionRemoveFromGroup() { + 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.selectionRemoveFromGroup(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..ca81c50aa 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 selectionAddToGroup(sources: List, group: String) { + execute { + val list = arrayListOf() + sources.forEach { + val newGroupList = arrayListOf() + it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { + newGroupList.add(it) + } + group.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 selectionRemoveFromGroup(sources: List, group: String) { + execute { + val list = arrayListOf() + sources.forEach { + val newGroupList = arrayListOf() + it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { + newGroupList.add(it) + } + group.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 From 33a7255928ffe102cad7ff18613189fc11d8aaa8 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Sun, 23 Aug 2020 20:20:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1b72cee66..64f6871a4 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -7,6 +7,7 @@ * 应用被杀死时停止朗读 * 默认封面添加删除操作 * 备份阅读记录 +* 书源添加移除分组支持多选 **2020/08/22** * 添加阅读时间记录 From b87ff54a85dd12cbc0fdeae42c598f1cb29b974c Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Sun, 23 Aug 2020 20:46:46 +0800 Subject: [PATCH 3/3] update --- app/src/main/assets/updateLog.md | 2 +- .../app/ui/book/source/manage/BookSourceActivity.kt | 12 ++++++------ .../app/ui/book/source/manage/BookSourceViewModel.kt | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 64f6871a4..159dcf354 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -7,7 +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 6e0552724..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,8 +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 -> selectionAddToGroup() - R.id.menu_remove_group -> selectionRemoveFromGroup() + R.id.menu_add_group -> selectionAddToGroups() + R.id.menu_remove_group -> selectionRemoveFromGroups() } return true } @@ -256,7 +256,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } @SuppressLint("InflateParams") - private fun selectionAddToGroup() { + private fun selectionAddToGroups() { alert(titleResource = R.string.add_group) { var editText: AutoCompleteTextView? = null customView { @@ -268,7 +268,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity okButton { editText?.text?.toString()?.let { if (it.isNotEmpty()) { - viewModel.selectionAddToGroup(adapter.getSelection(), it) + viewModel.selectionAddToGroups(adapter.getSelection(), it) } } } @@ -277,7 +277,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } @SuppressLint("InflateParams") - private fun selectionRemoveFromGroup() { + private fun selectionRemoveFromGroups() { alert(titleResource = R.string.remove_group) { var editText: AutoCompleteTextView? = null customView { @@ -289,7 +289,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity okButton { editText?.text?.toString()?.let { if (it.isNotEmpty()) { - viewModel.selectionRemoveFromGroup(adapter.getSelection(), it) + viewModel.selectionRemoveFromGroups(adapter.getSelection(), it) } } } 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 ca81c50aa..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,7 +93,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } } - fun selectionAddToGroup(sources: List, group: String) { + fun selectionAddToGroups(sources: List, groups: String) { execute { val list = arrayListOf() sources.forEach { @@ -101,7 +101,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { newGroupList.add(it) } - group.splitNotBlank(",", ";").forEach { + groups.splitNotBlank(",", ";", ",").forEach { newGroupList.add(it) } val lh = LinkedHashSet(newGroupList) @@ -112,7 +112,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } } - fun selectionRemoveFromGroup(sources: List, group: String) { + fun selectionRemoveFromGroups(sources: List, groups: String) { execute { val list = arrayListOf() sources.forEach { @@ -120,7 +120,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach { newGroupList.add(it) } - group.splitNotBlank(",", ";").forEach { + groups.splitNotBlank(",", ";", ",").forEach { newGroupList.remove(it) } val lh = LinkedHashSet(newGroupList)