From da8cbb497bfc1d3d13d4ef771088c134f19d0072 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Sun, 23 Aug 2020 19:56:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A6=E6=BA=90=E6=B7=BB=E5=8A=A0=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=88=86=E7=BB=84=E6=94=AF=E6=8C=81=E5=A4=9A=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