feat: 优化

pull/219/head
kunfei 5 years ago
parent d9a5716361
commit 408720e25b
  1. 2
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  4. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  6. 10
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -10,7 +10,7 @@ import org.jetbrains.anko.toast
object CheckSource { object CheckSource {
fun start(context: Context, sources: LinkedHashSet<BookSource>) { fun start(context: Context, sources: List<BookSource>) {
if (sources.isEmpty()) { if (sources.isEmpty()) {
context.toast(R.string.non_select) context.toast(R.string.non_select)
return return

@ -46,14 +46,14 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
callBack.upCountView() callBack.upCountView()
} }
fun getSelection(): LinkedHashSet<BookSource> { fun getSelection(): List<BookSource> {
val selection = linkedSetOf<BookSource>() val selection = arrayListOf<BookSource>()
getItems().map { getItems().map {
if (selected.contains(it)) { if (selected.contains(it)) {
selection.add(it) selection.add(it)
} }
} }
return selection return selection.sortedBy { it.customOrder }
} }
override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList<Any>) {

@ -57,7 +57,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun enableSelection(sources: LinkedHashSet<BookSource>) { fun enableSelection(sources: List<BookSource>) {
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { sources.forEach {
@ -67,7 +67,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun disableSelection(sources: LinkedHashSet<BookSource>) { fun disableSelection(sources: List<BookSource>) {
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { sources.forEach {
@ -77,7 +77,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun enableSelectExplore(sources: LinkedHashSet<BookSource>) { fun enableSelectExplore(sources: List<BookSource>) {
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { sources.forEach {
@ -87,7 +87,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun disableSelectExplore(sources: LinkedHashSet<BookSource>) { fun disableSelectExplore(sources: List<BookSource>) {
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { sources.forEach {
@ -97,13 +97,13 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun delSelection(sources: LinkedHashSet<BookSource>) { fun delSelection(sources: List<BookSource>) {
execute { execute {
App.db.bookSourceDao().delete(*sources.toTypedArray()) App.db.bookSourceDao().delete(*sources.toTypedArray())
} }
} }
fun exportSelection(sources: LinkedHashSet<BookSource>, file: File) { fun exportSelection(sources: List<BookSource>, file: File) {
execute { execute {
val json = GSON.toJson(sources) val json = GSON.toJson(sources)
FileUtils.createFileIfNotExist(file, "exportBookSource.json") FileUtils.createFileIfNotExist(file, "exportBookSource.json")
@ -115,7 +115,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun exportSelection(sources: LinkedHashSet<BookSource>, doc: DocumentFile) { fun exportSelection(sources: List<BookSource>, doc: DocumentFile) {
execute { execute {
val json = GSON.toJson(sources) val json = GSON.toJson(sources)
doc.findFile("exportBookSource.json")?.delete() doc.findFile("exportBookSource.json")?.delete()

@ -204,7 +204,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
private fun upGroupMenu() { private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group) groupMenu?.removeGroup(R.id.source_group)
groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) groups.sortedWith(Collator.getInstance(Locale.CHINESE))
.map { .map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it) groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
} }

@ -40,14 +40,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
callBack.upCountView() callBack.upCountView()
} }
fun getSelection(): LinkedHashSet<RssSource> { fun getSelection(): List<RssSource> {
val selection = linkedSetOf<RssSource>() val selection = arrayListOf<RssSource>()
getItems().forEach { getItems().forEach {
if (selected.contains(it)) { if (selected.contains(it)) {
selection.add(it) selection.add(it)
} }
} }
return selection return selection.sortedBy { it.customOrder }
} }
override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList<Any>) {

@ -55,7 +55,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun enableSelection(sources: LinkedHashSet<RssSource>) { fun enableSelection(sources: List<RssSource>) {
execute { execute {
val list = arrayListOf<RssSource>() val list = arrayListOf<RssSource>()
sources.forEach { sources.forEach {
@ -65,7 +65,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun disableSelection(sources: LinkedHashSet<RssSource>) { fun disableSelection(sources: List<RssSource>) {
execute { execute {
val list = arrayListOf<RssSource>() val list = arrayListOf<RssSource>()
sources.forEach { sources.forEach {
@ -75,13 +75,13 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun delSelection(sources: LinkedHashSet<RssSource>) { fun delSelection(sources: List<RssSource>) {
execute { execute {
App.db.rssSourceDao().delete(*sources.toTypedArray()) App.db.rssSourceDao().delete(*sources.toTypedArray())
} }
} }
fun exportSelection(sources: LinkedHashSet<RssSource>, file: File) { fun exportSelection(sources: List<RssSource>, file: File) {
execute { execute {
val json = GSON.toJson(sources) val json = GSON.toJson(sources)
FileUtils.createFileIfNotExist(file, "exportRssSource.json") FileUtils.createFileIfNotExist(file, "exportRssSource.json")
@ -93,7 +93,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun exportSelection(sources: LinkedHashSet<RssSource>, doc: DocumentFile) { fun exportSelection(sources: List<RssSource>, doc: DocumentFile) {
execute { execute {
val json = GSON.toJson(sources) val json = GSON.toJson(sources)
doc.findFile("exportRssSource.json")?.delete() doc.findFile("exportRssSource.json")?.delete()

Loading…
Cancel
Save