Merge branches 'mabdc' and 'master' of https://github.com/gedoor/legado into mabdc
# Conflicts: # app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.ktpull/36/head
commit
0d68701842
@ -0,0 +1,41 @@ |
||||
package io.legado.app.ui.rss.source.manage |
||||
|
||||
import androidx.recyclerview.widget.DiffUtil |
||||
import io.legado.app.data.entities.RssSource |
||||
|
||||
class DiffCallBack( |
||||
private val oldItems: List<RssSource>, |
||||
private val newItems: List<RssSource> |
||||
) : DiffUtil.Callback() { |
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { |
||||
val oldItem = oldItems[oldItemPosition] |
||||
val newItem = newItems[newItemPosition] |
||||
return oldItem.sourceUrl == newItem.sourceUrl |
||||
} |
||||
|
||||
override fun getOldListSize(): Int { |
||||
return oldItems.size |
||||
} |
||||
|
||||
override fun getNewListSize(): Int { |
||||
return newItems.size |
||||
} |
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { |
||||
val oldItem = oldItems[oldItemPosition] |
||||
val newItem = newItems[newItemPosition] |
||||
return oldItem.sourceName == newItem.sourceName |
||||
&& oldItem.enabled == newItem.enabled |
||||
} |
||||
|
||||
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { |
||||
val oldItem = oldItems[oldItemPosition] |
||||
val newItem = newItems[newItemPosition] |
||||
return when { |
||||
oldItem.sourceName == newItem.sourceName |
||||
&& oldItem.enabled != newItem.enabled -> 2 |
||||
else -> null |
||||
} |
||||
} |
||||
} |
@ -1,8 +1,26 @@ |
||||
package io.legado.app.ui.rss.source.manage |
||||
|
||||
import android.app.Application |
||||
import io.legado.app.App |
||||
import io.legado.app.base.BaseViewModel |
||||
|
||||
class RssSourceViewModel(application: Application) : BaseViewModel(application) { |
||||
|
||||
fun enableSelection(ids: LinkedHashSet<String>) { |
||||
execute { |
||||
App.db.rssSourceDao().enableSection(*ids.toTypedArray()) |
||||
} |
||||
} |
||||
|
||||
fun disableSelection(ids: LinkedHashSet<String>) { |
||||
execute { |
||||
App.db.rssSourceDao().disableSection(*ids.toTypedArray()) |
||||
} |
||||
} |
||||
|
||||
fun delSelection(ids: LinkedHashSet<String>) { |
||||
execute { |
||||
App.db.rssSourceDao().delSection(*ids.toTypedArray()) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue