From fc710c795861c0c1560c4a428ad7edf58aefda0f Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 8 Nov 2020 16:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../association/ImportBookSourceViewModel.kt | 9 ++++--- .../ui/association/ImportRssSourceDialog.kt | 26 +++++++++++++++++++ .../association/ImportRssSourceViewModel.kt | 8 ++++-- 3 files changed, 37 insertions(+), 6 deletions(-) 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 12b45c704..add4c05f1 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 @@ -30,11 +30,12 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { execute { val selectSource = arrayListOf() selectStatus.forEachIndexed { index, b -> - if (groupName != null) { - allSources[index].bookSourceGroup = groupName - } if (b) { - selectSource.add(allSources[index]) + val source = allSources[index] + if (groupName != null) { + source.bookSourceGroup = groupName + } + selectSource.add(source) } } SourceHelp.insertBookSource(*selectSource.toTypedArray()) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index d3aab6465..b65bddc55 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.association +import android.annotation.SuppressLint import android.content.Context import android.content.DialogInterface 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.SimpleRecyclerAdapter 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.visible +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_source_import.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -70,8 +78,26 @@ class ImportRssSourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList tool_bar.inflateMenu(R.menu.import_source) } + @SuppressLint("InflateParams") override fun onMenuItemClick(item: MenuItem): Boolean { 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 -> { viewModel.selectStatus.forEachIndexed { index, b -> if (!b) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt index 820821546..80df4c655 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt @@ -16,7 +16,7 @@ import io.legado.app.utils.* import java.io.File class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { - + var groupName: String? = null val errorLiveData = MutableLiveData() val successLiveData = MutableLiveData() @@ -30,7 +30,11 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { val selectSource = arrayListOf() selectStatus.forEachIndexed { index, b -> if (b) { - selectSource.add(allSources[index]) + val source = allSources[index] + if (groupName != null) { + source.sourceGroup = groupName + } + selectSource.add(source) } } SourceHelp.insertRssSource(*selectSource.toTypedArray())