优化代码

pull/736/head
gedoor 4 years ago
parent 23acdff42e
commit 9d06bd1654
  1. 2
      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. 10
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  4. 14
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  5. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  6. 14
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  7. 2
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  8. 5
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  9. 12
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  10. 5
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt

@ -88,7 +88,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3
val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50)
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect()

@ -165,8 +165,8 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
isMoved = false
}
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback {
return object : DragSelectTouchHelper.AdvanceCallback<Book>(Mode.ToggleAndReverse) {
val dragSelectCallback: DragSelectTouchHelper.Callback =
object : DragSelectTouchHelper.AdvanceCallback<Book>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<Book> {
return selectedBooks
}
@ -189,7 +189,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
return false
}
}
}
interface CallBack {
val groupList: List<BookGroup>

@ -237,22 +237,22 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
/**
* 更新分组菜单
*/
private fun upGroupMenu() {
private fun upGroupMenu() = menu?.let { menu ->
val selectedGroup = getPrefString("searchGroup") ?: ""
menu?.removeGroup(R.id.source_group)
var item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
menu.removeGroup(R.id.source_group)
var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
if (selectedGroup == "") {
item?.isChecked = true
}
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.map {
item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
if (it == selectedGroup) {
item?.isChecked = true
}
}
menu?.setGroupCheckable(R.id.source_group, true, true)
menu.setGroupCheckable(R.id.source_group, true, true)
}
/**

@ -152,14 +152,14 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = BookSourceAdapter(this, this)
binding.recyclerView.adapter = adapter
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true
// When this page is opened, it is in selection mode
val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50)
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect()
// Note: need judge selection first, so add ItemTouchHelper after it.
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
}
@ -339,12 +339,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}.show()
}
private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group)
private fun upGroupMenu() = groupMenu?.let { menu ->
menu.removeGroup(R.id.source_group)
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
}

@ -204,8 +204,8 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
}
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback {
return object : DragSelectTouchHelper.AdvanceCallback<BookSource>(Mode.ToggleAndReverse) {
val dragSelectCallback: DragSelectTouchHelper.Callback =
object : DragSelectTouchHelper.AdvanceCallback<BookSource>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<BookSource> {
return selected
}
@ -228,7 +228,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
return false
}
}
}
interface CallBack {
fun del(bookSource: BookSource)

@ -123,14 +123,12 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
})
}
private fun upGroupsMenu() {
groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text)
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.forEach {
subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it)
}
private fun upGroupsMenu() = groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text)
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.forEach {
subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it)
}
}

@ -92,7 +92,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true
val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50)
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect()

@ -167,8 +167,8 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
}
}
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback {
return object : DragSelectTouchHelper.AdvanceCallback<ReplaceRule>(Mode.ToggleAndReverse) {
val dragSelectCallback: DragSelectTouchHelper.Callback =
object : DragSelectTouchHelper.AdvanceCallback<ReplaceRule>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<ReplaceRule> {
return selected
}
@ -191,7 +191,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
return false
}
}
}
interface CallBack {
fun update(vararg rule: ReplaceRule)

@ -121,13 +121,11 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = RssSourceAdapter(this, this)
binding.recyclerView.adapter = adapter
// When this page is opened, it is in selection mode
val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50)
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect()
// Note: need judge selection first, so add ItemTouchHelper after it.
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true
@ -193,12 +191,12 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}.show()
}
private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group)
private fun upGroupMenu() = groupMenu?.let { menu ->
menu.removeGroup(R.id.source_group)
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
}

@ -170,8 +170,8 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
}
}
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback {
return object : DragSelectTouchHelper.AdvanceCallback<RssSource>(Mode.ToggleAndReverse) {
val dragSelectCallback: DragSelectTouchHelper.Callback =
object : DragSelectTouchHelper.AdvanceCallback<RssSource>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<RssSource> {
return selected
}
@ -194,7 +194,6 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
return false
}
}
}
interface CallBack {
fun del(source: RssSource)

Loading…
Cancel
Save