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. 5
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  3. 4
      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) 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() { private fun initView() {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.layoutManager = LinearLayoutManager(this)
@ -107,7 +64,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
adapter = ArrangeBookAdapter(this, this) adapter = ArrangeBookAdapter(this, this)
recycler_view.adapter = adapter recycler_view.adapter = adapter
select_action_bar.setMainActionText(R.string.move_to_group) 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.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack { select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) { 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() { private fun upMenu() {
menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group) subMenu.removeGroup(R.id.menu_group)

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

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

Loading…
Cancel
Save