pull/1814/head
kunfei 3 years ago
parent b2af3e18bd
commit 46fe025711
  1. 8
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  3. 10
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  4. 18
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt
  5. 8
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  6. 28
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -34,13 +34,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
val selection: List<BookSource>
get() {
val selection = arrayListOf<BookSource>()
getItems().map {
if (selected.contains(it)) {
selection.add(it)
}
return getItems().filter {
selected.contains(it)
}
return selection.sortedBy { it.customOrder }
}
val diffItemCallback: DiffUtil.ItemCallback<BookSource>

@ -13,6 +13,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: BookSource) {
execute {
sources.sortBy { it.customOrder }
val minOrder = appDb.bookSourceDao.minOrder - 1
val array = Array(sources.size) {
sources[it].copy(customOrder = minOrder - it)
@ -23,6 +24,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun bottomSource(vararg sources: BookSource) {
execute {
sources.sortBy { it.customOrder }
val maxOrder = appDb.bookSourceDao.maxOrder + 1
val array = Array(sources.size) {
sources[it].copy(customOrder = maxOrder + it)

@ -25,15 +25,11 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
private val selected = linkedSetOf<ReplaceRule>()
val selection: LinkedHashSet<ReplaceRule>
val selection: List<ReplaceRule>
get() {
val selection = linkedSetOf<ReplaceRule>()
getItems().map {
if (selected.contains(it)) {
selection.add(it)
}
return getItems().filter {
selected.contains(it)
}
return selection
}
val diffItemCallBack = object : DiffUtil.ItemCallback<ReplaceRule>() {

@ -65,23 +65,21 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
}
}
fun enableSelection(rules: LinkedHashSet<ReplaceRule>) {
fun enableSelection(rules: List<ReplaceRule>) {
execute {
val list = arrayListOf<ReplaceRule>()
rules.forEach {
list.add(it.copy(isEnabled = true))
val array = Array(rules.size) {
rules[it].copy(isEnabled = true)
}
appDb.replaceRuleDao.update(*list.toTypedArray())
appDb.replaceRuleDao.update(*array)
}
}
fun disableSelection(rules: LinkedHashSet<ReplaceRule>) {
fun disableSelection(rules: List<ReplaceRule>) {
execute {
val list = arrayListOf<ReplaceRule>()
rules.forEach {
list.add(it.copy(isEnabled = false))
val array = Array(rules.size) {
rules[it].copy(isEnabled = false)
}
appDb.replaceRuleDao.update(*list.toTypedArray())
appDb.replaceRuleDao.update(*array)
}
}

@ -27,13 +27,9 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
val selection: List<RssSource>
get() {
val selection = arrayListOf<RssSource>()
getItems().forEach {
if (selected.contains(it)) {
selection.add(it)
}
return getItems().filter {
selected.contains(it)
}
return selection.sortedBy { it.customOrder }
}
val diffItemCallback = object : DiffUtil.ItemCallback<RssSource>() {

@ -13,21 +13,23 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: RssSource) {
execute {
sources.sortBy { it.customOrder }
val minOrder = appDb.rssSourceDao.minOrder - 1
sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = minOrder - index
val array = Array(sources.size) {
sources[it].copy(customOrder = minOrder - it)
}
appDb.rssSourceDao.update(*sources)
appDb.rssSourceDao.update(*array)
}
}
fun bottomSource(vararg sources: RssSource) {
execute {
sources.sortBy { it.customOrder }
val maxOrder = appDb.rssSourceDao.maxOrder + 1
sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = maxOrder + index
val array = Array(sources.size) {
sources[it].copy(customOrder = maxOrder + it)
}
appDb.rssSourceDao.update(*sources)
appDb.rssSourceDao.update(*array)
}
}
@ -51,21 +53,19 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun enableSelection(sources: List<RssSource>) {
execute {
val list = arrayListOf<RssSource>()
sources.forEach {
list.add(it.copy(enabled = true))
val array = Array(sources.size) {
sources[it].copy(enabled = true)
}
appDb.rssSourceDao.update(*list.toTypedArray())
appDb.rssSourceDao.update(*array)
}
}
fun disableSelection(sources: List<RssSource>) {
execute {
val list = arrayListOf<RssSource>()
sources.forEach {
list.add(it.copy(enabled = false))
val array = Array(sources.size) {
sources[it].copy(enabled = false)
}
appDb.rssSourceDao.update(*list.toTypedArray())
appDb.rssSourceDao.update(*array)
}
}

Loading…
Cancel
Save