diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index e3a096677..cc240f3f2 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -20,7 +20,7 @@ import io.legado.app.constant.AppPattern import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource -import io.legado.app.databinding.DialogEditTextBinding +import io.legado.app.databinding.DialogCustomGroupBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig @@ -169,29 +169,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList @SuppressLint("InflateParams") override fun onMenuItemClick(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_new_group -> { - alert(R.string.diy_edit_source_group) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { - val groups = linkedSetOf() - appDb.bookSourceDao.allGroup.forEach { group -> - groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) - } - textInputLayout.setHint(R.string.group_name) - editView.setFilterValues(groups.toList()) - editView.dropDownHeight = 180.dp - } - customView { - alertBinding.root - } - okButton { - alertBinding.editView.text?.toString()?.let { group -> - viewModel.groupName = group - item.title = getString(R.string.diy_edit_source_group_title, group) - } - } - noButton() - }.show() - } + R.id.menu_new_group -> alertCustomGroup(item) R.id.menu_Keep_original_name -> { item.isChecked = !item.isChecked putPrefBoolean(PreferKey.importKeepName, item.isChecked) @@ -200,6 +178,34 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList return false } + private fun alertCustomGroup(item: MenuItem) { + alert(R.string.diy_edit_source_group) { + val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply { + val groups = linkedSetOf() + appDb.bookSourceDao.allGroup.forEach { group -> + groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) + } + textInputLayout.setHint(R.string.group_name) + editView.setFilterValues(groups.toList()) + editView.dropDownHeight = 180.dp + } + customView { + alertBinding.root + } + okButton { + viewModel.isAddGroup = alertBinding.swAddGroup.isChecked + viewModel.groupName = alertBinding.editView.text?.toString() + if (viewModel.groupName.isNullOrBlank()) { + item.title = getString(R.string.diy_source_group) + } else { + item.title = + getString(R.string.diy_edit_source_group_title, viewModel.groupName) + } + } + noButton() + }.show() + } + inner class SourcesAdapter(context: Context) : RecyclerAdapter(context) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 0659487ad..0341f5d21 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import com.jayway.jsonpath.JsonPath import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.help.AppConfig @@ -18,8 +19,10 @@ import io.legado.app.help.storage.Restore import io.legado.app.utils.isAbsUrl import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonObject +import io.legado.app.utils.splitNotBlank class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { + var isAddGroup = false var groupName: String? = null val errorLiveData = MutableLiveData() val successLiveData = MutableLiveData() @@ -49,6 +52,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { fun importSelect(finally: () -> Unit) { execute { + val group = groupName?.trim() val keepName = AppConfig.importKeepName val selectSource = arrayListOf() selectStatus.forEachIndexed { index, b -> @@ -61,8 +65,16 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { source.customOrder = it.customOrder } } - if (groupName != null) { - source.bookSourceGroup = groupName + if (!group.isNullOrEmpty()) { + if (isAddGroup) { + val groups = linkedSetOf() + source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.let { + groups.addAll(it) + } + groups.add(group) + } else { + source.bookSourceGroup = group + } } selectSource.add(source) } diff --git a/app/src/main/res/layout/dialog_custom_group.xml b/app/src/main/res/layout/dialog_custom_group.xml new file mode 100644 index 000000000..21c8f4967 --- /dev/null +++ b/app/src/main/res/layout/dialog_custom_group.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index ea85ec4e7..49c3fec0a 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -848,4 +848,5 @@ 字典 未知错误 end + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index cc05056fd..a3e06756a 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -848,4 +848,5 @@ 字典 未知错误 end + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index c804508f7..78aa4c716 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -848,4 +848,5 @@ Dicionários 未知错误 end + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 2146ac4a7..0a80ee0d5 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -849,5 +849,6 @@ 字典 未知錯誤 end + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 4af6a2440..3b17b9cef 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -850,5 +850,6 @@ 字典 未知錯誤 end + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index fd844c95e..3e1ffb84c 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -851,5 +851,6 @@ 未知错误 自动备份失败 结束 + 关闭替换分组/开启添加分组 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a61943742..fa3f75759 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -853,5 +853,6 @@ 未知错误 Autobackup failed end + 关闭替换分组/开启添加分组