优化导入功能

pull/473/head
gedoor 5 years ago
parent fc710c7958
commit 87a3ef59e1
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 11
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  4. 16
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  5. 11
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  6. 16
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  7. 3
      app/src/main/res/menu/import_source.xml
  8. 1
      app/src/main/res/values-zh-rHK/strings.xml
  9. 1
      app/src/main/res/values-zh-rTW/strings.xml
  10. 1
      app/src/main/res/values-zh/strings.xml
  11. 1
      app/src/main/res/values/strings.xml

@ -53,6 +53,7 @@ object PreferKey {
const val showBrightnessView = "showBrightnessView" const val showBrightnessView = "showBrightnessView"
const val autoClearExpired = "autoClearExpired" const val autoClearExpired = "autoClearExpired"
const val autoChangeSource = "autoChangeSource" const val autoChangeSource = "autoChangeSource"
const val importKeepName = "importKeepName"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -134,5 +134,7 @@ object AppConfig {
val changeSourceLoadInfo get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc) val changeSourceLoadInfo get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc)
val changeSourceLoadToc get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc) val changeSourceLoadToc get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc)
val importKeepName get() = App.INSTANCE.getPrefBoolean(PreferKey.importKeepName)
} }

@ -14,7 +14,9 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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.constant.PreferKey
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
@ -22,6 +24,7 @@ import io.legado.app.lib.dialogs.okButton
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.putPrefBoolean
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_edit_text.view.*
import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.dialog_recycler_view.*
@ -75,6 +78,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
private fun initMenu() { private fun initMenu() {
tool_bar.setOnMenuItemClickListener(this) tool_bar.setOnMenuItemClickListener(this)
tool_bar.inflateMenu(R.menu.import_source) tool_bar.inflateMenu(R.menu.import_source)
tool_bar.menu.findItem(R.id.menu_Keep_original_name)?.isChecked = AppConfig.importKeepName
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
@ -113,6 +117,10 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
} }
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
} }
R.id.menu_Keep_original_name -> {
item.isChecked = !item.isChecked
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
}
} }
return false return false
} }
@ -130,12 +138,11 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
holder.itemView.apply { holder.itemView.apply {
cb_source_name.isChecked = viewModel.selectStatus[holder.layoutPosition] cb_source_name.isChecked = viewModel.selectStatus[holder.layoutPosition]
cb_source_name.text = item.bookSourceName cb_source_name.text = item.bookSourceName
tv_source_state.text = if (viewModel.sourceCheckState[holder.layoutPosition]) { tv_source_state.text = if (viewModel.checkSources[holder.layoutPosition] != null) {
"已存在" "已存在"
} else { } else {
"新书源" "新书源"
} }
} }
} }

@ -9,6 +9,7 @@ import io.legado.app.App
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.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig
import io.legado.app.help.SourceHelp import io.legado.app.help.SourceHelp
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.OldRule
@ -22,12 +23,13 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
val successLiveData = MutableLiveData<Int>() val successLiveData = MutableLiveData<Int>()
val allSources = arrayListOf<BookSource>() val allSources = arrayListOf<BookSource>()
val sourceCheckState = arrayListOf<Boolean>() val checkSources = arrayListOf<BookSource?>()
val selectStatus = arrayListOf<Boolean>() val selectStatus = arrayListOf<Boolean>()
fun importSelect(finally: () -> Unit) { fun importSelect(finally: () -> Unit) {
execute { execute {
val keepName = AppConfig.importKeepName
val selectSource = arrayListOf<BookSource>() val selectSource = arrayListOf<BookSource>()
selectStatus.forEachIndexed { index, b -> selectStatus.forEachIndexed { index, b ->
if (b) { if (b) {
@ -35,6 +37,12 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
if (groupName != null) { if (groupName != null) {
source.bookSourceGroup = groupName source.bookSourceGroup = groupName
} }
if (keepName) {
checkSources[index]?.let {
source.bookSourceName = it.bookSourceName
source.bookSourceGroup = it.bookSourceGroup
}
}
selectSource.add(source) selectSource.add(source)
} }
} }
@ -127,9 +135,9 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.bookSourceDao().getBookSource(it.bookSourceUrl) != null val has = App.db.bookSourceDao().getBookSource(it.bookSourceUrl)
sourceCheckState.add(has) checkSources.add(has)
selectStatus.add(!has) selectStatus.add(has == null)
} }
successLiveData.postValue(allSources.size) successLiveData.postValue(allSources.size)
} }

@ -14,7 +14,9 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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.constant.PreferKey
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
@ -22,6 +24,7 @@ import io.legado.app.lib.dialogs.okButton
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.putPrefBoolean
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_edit_text.view.*
import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.dialog_recycler_view.*
@ -76,6 +79,7 @@ class ImportRssSourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
private fun initMenu() { private fun initMenu() {
tool_bar.setOnMenuItemClickListener(this) tool_bar.setOnMenuItemClickListener(this)
tool_bar.inflateMenu(R.menu.import_source) tool_bar.inflateMenu(R.menu.import_source)
tool_bar.menu.findItem(R.id.menu_Keep_original_name)?.isChecked = AppConfig.importKeepName
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
@ -114,6 +118,10 @@ class ImportRssSourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
} }
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
} }
R.id.menu_Keep_original_name -> {
item.isChecked = !item.isChecked
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
}
} }
return false return false
} }
@ -130,12 +138,11 @@ class ImportRssSourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
holder.itemView.apply { holder.itemView.apply {
cb_source_name.isChecked = viewModel.selectStatus[holder.layoutPosition] cb_source_name.isChecked = viewModel.selectStatus[holder.layoutPosition]
cb_source_name.text = item.sourceName cb_source_name.text = item.sourceName
tv_source_state.text = if (viewModel.sourceCheckState[holder.layoutPosition]) { tv_source_state.text = if (viewModel.checkSources[holder.layoutPosition] != null) {
"已存在" "已存在"
} else { } else {
"新订阅源" "新订阅源"
} }
} }
} }

@ -9,6 +9,7 @@ import io.legado.app.App
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.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.AppConfig
import io.legado.app.help.SourceHelp import io.legado.app.help.SourceHelp
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.Restore import io.legado.app.help.storage.Restore
@ -21,12 +22,13 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
val successLiveData = MutableLiveData<Int>() val successLiveData = MutableLiveData<Int>()
val allSources = arrayListOf<RssSource>() val allSources = arrayListOf<RssSource>()
val sourceCheckState = arrayListOf<Boolean>() val checkSources = arrayListOf<RssSource?>()
val selectStatus = arrayListOf<Boolean>() val selectStatus = arrayListOf<Boolean>()
fun importSelect(finally: () -> Unit) { fun importSelect(finally: () -> Unit) {
execute { execute {
val keepName = AppConfig.importKeepName
val selectSource = arrayListOf<RssSource>() val selectSource = arrayListOf<RssSource>()
selectStatus.forEachIndexed { index, b -> selectStatus.forEachIndexed { index, b ->
if (b) { if (b) {
@ -34,6 +36,12 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
if (groupName != null) { if (groupName != null) {
source.sourceGroup = groupName source.sourceGroup = groupName
} }
if (keepName) {
checkSources[index]?.let {
source.sourceName = it.sourceName
source.sourceGroup = it.sourceGroup
}
}
selectSource.add(source) selectSource.add(source)
} }
} }
@ -120,9 +128,9 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.rssSourceDao().getByKey(it.sourceUrl) != null val has = App.db.rssSourceDao().getByKey(it.sourceUrl)
sourceCheckState.add(has) checkSources.add(has)
selectStatus.add(!has) selectStatus.add(has == null)
} }
successLiveData.postValue(allSources.size) successLiveData.postValue(allSources.size)
} }

@ -22,7 +22,8 @@
<item <item
android:id="@+id/menu_Keep_original_name" android:id="@+id/menu_Keep_original_name"
android:title="保留原名" android:title="@string/keep_original_name"
android:checkable="true"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

@ -780,5 +780,6 @@
<string name="scan_folder">智能扫描</string> <string name="scan_folder">智能扫描</string>
<string name="copy_url">拷贝URL</string> <string name="copy_url">拷贝URL</string>
<string name="no_book">没有书籍</string> <string name="no_book">没有书籍</string>
<string name="keep_original_name">保留原名</string>
</resources> </resources>

@ -780,5 +780,6 @@
<string name="scan_folder">智能扫描</string> <string name="scan_folder">智能扫描</string>
<string name="copy_url">拷贝URL</string> <string name="copy_url">拷贝URL</string>
<string name="no_book">没有书籍</string> <string name="no_book">没有书籍</string>
<string name="keep_original_name">保留原名</string>
</resources> </resources>

@ -783,5 +783,6 @@
<string name="scan_folder">智能扫描</string> <string name="scan_folder">智能扫描</string>
<string name="copy_url">拷贝URL</string> <string name="copy_url">拷贝URL</string>
<string name="no_book">没有书籍</string> <string name="no_book">没有书籍</string>
<string name="keep_original_name">保留原名</string>
</resources> </resources>

@ -786,5 +786,6 @@
<string name="scan_folder">智能扫描</string> <string name="scan_folder">智能扫描</string>
<string name="copy_url">拷贝URL</string> <string name="copy_url">拷贝URL</string>
<string name="no_book">没有书籍</string> <string name="no_book">没有书籍</string>
<string name="keep_original_name">保留原名</string>
</resources> </resources>

Loading…
Cancel
Save