feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 84d480a833
commit af06cb384e
  1. 9
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 8
      app/src/main/res/menu/arrange_book_sel.xml
  3. 1
      app/src/main/res/values/strings.xml

@ -32,6 +32,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
get() = getViewModel(ArrangeBookViewModel::class.java)
override val groupList: ArrayList<BookGroup> = arrayListOf()
private val groupRequestCode = 22
private val addToGroupRequestCode = 34
private lateinit var adapter: ArrangeBookAdapter
private var groupLiveData: LiveData<List<BookGroup>>? = null
private var booksLiveData: LiveData<List<Book>>? = null
@ -151,6 +152,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
viewModel.upCanUpdate(adapter.selectedBooks.toTypedArray(), true)
R.id.menu_update_disable ->
viewModel.upCanUpdate(adapter.selectedBooks.toTypedArray(), true)
R.id.menu_add_to_group -> selectGroup(0, addToGroupRequestCode)
}
return false
}
@ -182,6 +184,13 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
viewModel.updateBook(it.copy(group = groupId))
}
}
addToGroupRequestCode -> {
val books = arrayListOf<Book>()
adapter.selectedBooks.forEach {
books.add(it.copy(group = it.group or groupId))
}
viewModel.updateBook(*books.toTypedArray())
}
}
}

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_del_selection"
android:title="@string/delete" />
<item
android:id="@+id/menu_update_enable"
android:title="@string/allow_update" />
@ -10,7 +14,7 @@
android:title="@string/disable_update" />
<item
android:id="@+id/menu_del_selection"
android:title="@string/delete" />
android:id="@+id/menu_add_to_group"
android:title="@string/add_to_group" />
</menu>

@ -638,4 +638,5 @@
<string name="title_left">靠左</string>
<string name="title_center">居中</string>
<string name="title_hide">隐藏</string>
<string name="add_to_group">加入分组</string>
</resources>

Loading…
Cancel
Save