pull/737/head
Robot 4 years ago
commit 8782bc24a3
  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. 4
      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) val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3 itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3
val dragSelectTouchHelper: DragSelectTouchHelper = val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView) dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode // When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect() dragSelectTouchHelper.activeSlideSelect()

@ -165,8 +165,8 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
isMoved = false isMoved = false
} }
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback { val dragSelectCallback: DragSelectTouchHelper.Callback =
return object : DragSelectTouchHelper.AdvanceCallback<Book>(Mode.ToggleAndReverse) { object : DragSelectTouchHelper.AdvanceCallback<Book>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<Book> { override fun currentSelectedId(): MutableSet<Book> {
return selectedBooks return selectedBooks
} }
@ -189,7 +189,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
return false return false
} }
} }
}
interface CallBack { interface CallBack {
val groupList: List<BookGroup> 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") ?: "" val selectedGroup = getPrefString("searchGroup") ?: ""
menu?.removeGroup(R.id.source_group) menu.removeGroup(R.id.source_group)
var item = menu?.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
if (selectedGroup == "") { if (selectedGroup == "") {
item?.isChecked = true item?.isChecked = true
} }
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
}.map { }.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) { if (it == selectedGroup) {
item?.isChecked = true 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)) binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = BookSourceAdapter(this, this) adapter = BookSourceAdapter(this, this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
val itemTouchCallback = ItemTouchCallback(adapter) // When this page is opened, it is in selection mode
itemTouchCallback.isCanDrag = true
val dragSelectTouchHelper: DragSelectTouchHelper = val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView) dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect() dragSelectTouchHelper.activeSlideSelect()
// Note: need judge selection first, so add ItemTouchHelper after it. // Note: need judge selection first, so add ItemTouchHelper after it.
val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
} }
@ -339,12 +339,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}.show() }.show()
} }
private fun upGroupMenu() { private fun upGroupMenu() = groupMenu?.let { menu ->
groupMenu?.removeGroup(R.id.source_group) menu.removeGroup(R.id.source_group)
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
}.map { }.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 { val dragSelectCallback: DragSelectTouchHelper.Callback =
return object : DragSelectTouchHelper.AdvanceCallback<BookSource>(Mode.ToggleAndReverse) { object : DragSelectTouchHelper.AdvanceCallback<BookSource>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<BookSource> { override fun currentSelectedId(): MutableSet<BookSource> {
return selected return selected
} }
@ -228,7 +228,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
return false return false
} }
} }
}
interface CallBack { interface CallBack {
fun del(bookSource: BookSource) fun del(bookSource: BookSource)

@ -123,8 +123,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
}) })
} }
private fun upGroupsMenu() { private fun upGroupsMenu() = groupsMenu?.let { subMenu ->
groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text) subMenu.removeGroup(R.id.menu_group_text)
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
@ -132,7 +131,6 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it) subMenu.add(R.id.menu_group_text, Menu.NONE, Menu.NONE, it)
} }
} }
}
override fun onCompatOptionsItemSelected(item: MenuItem) { override fun onCompatOptionsItemSelected(item: MenuItem) {
super.onCompatOptionsItemSelected(item) super.onCompatOptionsItemSelected(item)

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

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

@ -121,13 +121,11 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
binding.recyclerView.addItemDecoration(VerticalDivider(this)) binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = RssSourceAdapter(this, this) adapter = RssSourceAdapter(this, this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
// When this page is opened, it is in selection mode
val dragSelectTouchHelper: DragSelectTouchHelper = val dragSelectTouchHelper: DragSelectTouchHelper =
DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView) dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
// When this page is opened, it is in selection mode
dragSelectTouchHelper.activeSlideSelect() dragSelectTouchHelper.activeSlideSelect()
// Note: need judge selection first, so add ItemTouchHelper after it. // Note: need judge selection first, so add ItemTouchHelper after it.
val itemTouchCallback = ItemTouchCallback(adapter) val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true itemTouchCallback.isCanDrag = true
@ -193,12 +191,12 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}.show() }.show()
} }
private fun upGroupMenu() { private fun upGroupMenu() = groupMenu?.let { menu ->
groupMenu?.removeGroup(R.id.source_group) menu.removeGroup(R.id.source_group)
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
}.map { }.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 { val dragSelectCallback: DragSelectTouchHelper.Callback =
return object : DragSelectTouchHelper.AdvanceCallback<RssSource>(Mode.ToggleAndReverse) { object : DragSelectTouchHelper.AdvanceCallback<RssSource>(Mode.ToggleAndReverse) {
override fun currentSelectedId(): MutableSet<RssSource> { override fun currentSelectedId(): MutableSet<RssSource> {
return selected return selected
} }
@ -194,7 +194,6 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
return false return false
} }
} }
}
interface CallBack { interface CallBack {
fun del(source: RssSource) fun del(source: RssSource)

Loading…
Cancel
Save