优化导入功能

pull/473/head
gedoor 4 years ago
parent 71420e723e
commit fc710c7958
  1. 9
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  2. 26
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  3. 8
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt

@ -30,11 +30,12 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
execute { execute {
val selectSource = arrayListOf<BookSource>() val selectSource = arrayListOf<BookSource>()
selectStatus.forEachIndexed { index, b -> selectStatus.forEachIndexed { index, b ->
if (groupName != null) {
allSources[index].bookSourceGroup = groupName
}
if (b) { if (b) {
selectSource.add(allSources[index]) val source = allSources[index]
if (groupName != null) {
source.bookSourceGroup = groupName
}
selectSource.add(source)
} }
} }
SourceHelp.insertBookSource(*selectSource.toTypedArray()) SourceHelp.insertBookSource(*selectSource.toTypedArray())

@ -1,5 +1,6 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
@ -14,8 +15,15 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton
import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.dialog_recycler_view.*
import kotlinx.android.synthetic.main.item_source_import.view.* import kotlinx.android.synthetic.main.item_source_import.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@ -70,8 +78,26 @@ class ImportRssSourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
tool_bar.inflateMenu(R.menu.import_source) tool_bar.inflateMenu(R.menu.import_source)
} }
@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 -> {
alert(R.string.diy_edit_source_group) {
var editText: AutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view
}
}
okButton {
editText?.text?.toString()?.let { group ->
viewModel.groupName = group
item.title = getString(R.string.diy_edit_source_group_title, group)
}
}
noButton { }
}.show().applyTint()
}
R.id.menu_select_all -> { R.id.menu_select_all -> {
viewModel.selectStatus.forEachIndexed { index, b -> viewModel.selectStatus.forEachIndexed { index, b ->
if (!b) { if (!b) {

@ -16,7 +16,7 @@ import io.legado.app.utils.*
import java.io.File import java.io.File
class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
var groupName: String? = null
val errorLiveData = MutableLiveData<String>() val errorLiveData = MutableLiveData<String>()
val successLiveData = MutableLiveData<Int>() val successLiveData = MutableLiveData<Int>()
@ -30,7 +30,11 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
val selectSource = arrayListOf<RssSource>() val selectSource = arrayListOf<RssSource>()
selectStatus.forEachIndexed { index, b -> selectStatus.forEachIndexed { index, b ->
if (b) { if (b) {
selectSource.add(allSources[index]) val source = allSources[index]
if (groupName != null) {
source.sourceGroup = groupName
}
selectSource.add(source)
} }
} }
SourceHelp.insertRssSource(*selectSource.toTypedArray()) SourceHelp.insertRssSource(*selectSource.toTypedArray())

Loading…
Cancel
Save