pull/1222/head
gedoor 3 years ago
parent c19565715f
commit 422a71967f
  1. 54
      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.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource 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.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -169,29 +169,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
override fun onMenuItemClick(item: MenuItem): Boolean { override fun onMenuItemClick(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_new_group -> { R.id.menu_new_group -> alertCustomGroup(item)
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
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_Keep_original_name -> { R.id.menu_Keep_original_name -> {
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
putPrefBoolean(PreferKey.importKeepName, item.isChecked) putPrefBoolean(PreferKey.importKeepName, item.isChecked)
@ -200,6 +178,34 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
return false return false
} }
private fun alertCustomGroup(item: MenuItem) {
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
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) : inner class SourcesAdapter(context: Context) :
RecyclerAdapter<BookSource, ItemSourceImportBinding>(context) { RecyclerAdapter<BookSource, ItemSourceImportBinding>(context) {

@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig 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.isAbsUrl
import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonArray
import io.legado.app.utils.isJsonObject import io.legado.app.utils.isJsonObject
import io.legado.app.utils.splitNotBlank
class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
var isAddGroup = false
var groupName: String? = null var groupName: String? = null
val errorLiveData = MutableLiveData<String>() val errorLiveData = MutableLiveData<String>()
val successLiveData = MutableLiveData<Int>() val successLiveData = MutableLiveData<Int>()
@ -49,6 +52,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
fun importSelect(finally: () -> Unit) { fun importSelect(finally: () -> Unit) {
execute { execute {
val group = groupName?.trim()
val keepName = AppConfig.importKeepName val keepName = AppConfig.importKeepName
val selectSource = arrayListOf<BookSource>() val selectSource = arrayListOf<BookSource>()
selectStatus.forEachIndexed { index, b -> selectStatus.forEachIndexed { index, b ->
@ -61,8 +65,16 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
source.customOrder = it.customOrder source.customOrder = it.customOrder
} }
} }
if (groupName != null) { if (!group.isNullOrEmpty()) {
source.bookSourceGroup = groupName 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) 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="dict">字典</string>
<string name="unknown_error">未知错误</string> <string name="unknown_error">未知错误</string>
<string name="end">end</string> <string name="end">end</string>
<string name="custom_group_summary">关闭替换分组/开启添加分组</string>
</resources> </resources>

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

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

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

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

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

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

Loading…
Cancel
Save