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