pull/1222/head
gedoor 3 years ago
parent c19565715f
commit 422a71967f
  1. 32
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  2. 16
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  3. 69
      app/src/main/res/layout/dialog_custom_group.xml
  4. 1
      app/src/main/res/values-es-rES/strings.xml
  5. 1
      app/src/main/res/values-ja-rJP/strings.xml
  6. 1
      app/src/main/res/values-pt-rBR/strings.xml
  7. 1
      app/src/main/res/values-zh-rHK/strings.xml
  8. 1
      app/src/main/res/values-zh-rTW/strings.xml
  9. 1
      app/src/main/res/values-zh/strings.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -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,9 +169,18 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
@SuppressLint("InflateParams")
override fun onMenuItemClick(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_new_group -> {
R.id.menu_new_group -> alertCustomGroup(item)
R.id.menu_Keep_original_name -> {
item.isChecked = !item.isChecked
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
}
}
return false
}
private fun alertCustomGroup(item: MenuItem) {
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
appDb.bookSourceDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -184,21 +193,18 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
alertBinding.root
}
okButton {
alertBinding.editView.text?.toString()?.let { group ->
viewModel.groupName = group
item.title = getString(R.string.diy_edit_source_group_title, group)
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()
}
R.id.menu_Keep_original_name -> {
item.isChecked = !item.isChecked
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
}
}
return false
}
inner class SourcesAdapter(context: Context) :
RecyclerAdapter<BookSource, ItemSourceImportBinding>(context) {

@ -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<String>()
val successLiveData = MutableLiveData<Int>()
@ -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<BookSource>()
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<String>()
source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.let {
groups.addAll(it)
}
groups.add(group)
} else {
source.bookSourceGroup = group
}
}
selectSource.add(source)
}

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="12dp"
android:overScrollMode="ifContentScrolls">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_add_group_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/add_group"
android:textColor="@color/primaryText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/sw_add_group" />
<TextView
android:id="@+id/tv_add_group_s"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/custom_group_summary"
android:textColor="@color/secondaryText"
app:layout_constraintTop_toBottomOf="@+id/tv_add_group_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/sw_add_group" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/sw_add_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="@string/replace"
android:textOn="@string/add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<io.legado.app.ui.widget.text.AutoCompleteTextView
android:id="@+id/edit_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
</io.legado.app.ui.widget.text.TextInputLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

@ -848,4 +848,5 @@
<string name="dict">字典</string>
<string name="unknown_error">未知错误</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -848,4 +848,5 @@
<string name="dict">字典</string>
<string name="unknown_error">未知错误</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -848,4 +848,5 @@
<string name="dict">Dicionários</string>
<string name="unknown_error">未知错误</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -849,5 +849,6 @@
<string name="dict">字典</string>
<string name="unknown_error">未知錯誤</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -850,5 +850,6 @@
<string name="dict">字典</string>
<string name="unknown_error">未知錯誤</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -851,5 +851,6 @@
<string name="unknown_error">未知错误</string>
<string name="autobackup_fail">自动备份失败</string>
<string name="end">结束</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

@ -853,5 +853,6 @@
<string name="unknown_error">未知错误</string>
<string name="autobackup_fail">Autobackup failed</string>
<string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources>

Loading…
Cancel
Save