feat: 优化代码

pull/95/head
kunfei 5 years ago
parent 5c5a444a2f
commit a2cfe8d17d
  1. 88
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  3. 6
      app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt

@ -57,49 +57,6 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
return super.onPrepareOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_group_manage -> GroupManageDialog()
.show(supportFragmentManager, "groupManage")
R.id.menu_all -> {
title_bar.subtitle = item.title
groupId = -1
adapter.selectedBooks.clear()
initBookData()
}
R.id.menu_local -> {
title_bar.subtitle = item.title
groupId = -2
adapter.selectedBooks.clear()
initBookData()
}
R.id.menu_audio -> {
title_bar.subtitle = item.title
groupId = -3
adapter.selectedBooks.clear()
initBookData()
}
else -> if (item.groupId == R.id.menu_group) {
title_bar.subtitle = item.title
groupId = item.itemId
adapter.selectedBooks.clear()
initBookData()
}
}
return super.onCompatOptionsItemSelected(item)
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_del_selection ->
alert(titleResource = R.string.sure, messageResource = R.string.sure_del) {
okButton { viewModel.deleteBook(*adapter.selectedBooks.toTypedArray()) }
noButton { }
}.show().applyTint()
}
return false
}
private fun initView() {
ATH.applyEdgeEffectColor(recycler_view)
recycler_view.layoutManager = LinearLayoutManager(this)
@ -107,7 +64,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
adapter = ArrangeBookAdapter(this, this)
recycler_view.adapter = adapter
select_action_bar.setMainActionText(R.string.move_to_group)
select_action_bar.inflateMenu(R.menu.arrange_book)
select_action_bar.inflateMenu(R.menu.arrange_book_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) {
@ -149,6 +106,49 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
})
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_group_manage -> GroupManageDialog()
.show(supportFragmentManager, "groupManage")
R.id.menu_all -> {
title_bar.subtitle = item.title
groupId = -1
adapter.selectedBooks.clear()
initBookData()
}
R.id.menu_local -> {
title_bar.subtitle = item.title
groupId = -2
adapter.selectedBooks.clear()
initBookData()
}
R.id.menu_audio -> {
title_bar.subtitle = item.title
groupId = -3
adapter.selectedBooks.clear()
initBookData()
}
else -> if (item.groupId == R.id.menu_group) {
title_bar.subtitle = item.title
groupId = item.itemId
adapter.selectedBooks.clear()
initBookData()
}
}
return super.onCompatOptionsItemSelected(item)
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_del_selection ->
alert(titleResource = R.string.sure, messageResource = R.string.sure_del) {
okButton { viewModel.deleteBook(*adapter.selectedBooks.toTypedArray()) }
noButton { }
}.show().applyTint()
}
return false
}
private fun upMenu() {
menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group)

@ -21,13 +21,11 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
getItems().forEach {
selectedBooks.add(it)
}
notifyDataSetChanged()
callBack.upSelectCount()
} else {
selectedBooks.clear()
notifyDataSetChanged()
callBack.upSelectCount()
}
notifyDataSetChanged()
callBack.upSelectCount()
}
fun revertSelection() {
@ -38,6 +36,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
selectedBooks.add(it)
}
}
notifyDataSetChanged()
callBack.upSelectCount()
}

@ -46,13 +46,11 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
selectedUris.add(it.uri.toString())
}
}
notifyDataSetChanged()
callBack.upCountView()
} else {
selectedUris.clear()
notifyDataSetChanged()
callBack.upCountView()
}
notifyDataSetChanged()
callBack.upCountView()
}
fun revertSelection() {

Loading…
Cancel
Save