pull/737/head
Robot 4 years ago
commit 289e0331ff
  1. 11
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  6. 32
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  8. 3
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  9. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  10. 4
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt

@ -121,14 +121,11 @@ abstract class SimpleRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
}
fun swapItem(oldPosition: Int, newPosition: Int) {
fun swapItem(srcPosition: Int, targetPosition: Int) {
synchronized(lock) {
val size = itemCount
if (oldPosition in 0 until size && newPosition in 0 until size) {
Collections.swap(asyncListDiffer.currentList, oldPosition, newPosition)
notifyItemChanged(oldPosition)
notifyItemChanged(newPosition)
}
val list = ArrayList(getItems())
Collections.swap(list, srcPosition, targetPosition)
setItems(list)
}
}

@ -141,8 +141,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
val srcItem = getItem(srcPosition)
val targetItem = getItem(targetPosition)
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
if (srcItem != null && targetItem != null) {
if (srcItem.order == targetItem.order) {
for ((index, item) in getItems().withIndex()) {
@ -154,6 +152,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
targetItem.order = pos
}
}
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -31,7 +31,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: GroupViewModel
@ -194,8 +193,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -33,7 +33,6 @@ import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -193,8 +192,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -248,8 +248,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private var isMoved = false
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return super.onMove(srcPosition, targetPosition)
}

@ -77,15 +77,15 @@ class ReadView(context: Context, attrs: AttributeSet) :
private var firstCharIndex: Int = 0
val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
private val tlRect = RectF(10F, 10F, width * 0.33f, height * 0.33f)
private val tcRect = RectF(width * 0.33f, 10F, width * 0.66f, height * 0.33f)
private val trRect = RectF(width * 0.36f, 10F, width - 10f, height * 0.33f)
private val mlRect = RectF(10F, height * 0.33f, width * 0.33f, height * 0.66f)
private val tlRect = RectF(0f, 0f, width * 0.33f, height * 0.33f)
private val tcRect = RectF(width * 0.33f, 0f, width * 0.66f, height * 0.33f)
private val trRect = RectF(width * 0.36f, 0f, width - 0f, height * 0.33f)
private val mlRect = RectF(0f, height * 0.33f, width * 0.33f, height * 0.66f)
private val mcRect = RectF(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
private val mrRect = RectF(width * 0.66f, height * 0.33f, width - 10f, height * 0.66f)
private val blRect = RectF(10F, height * 0.66f, width * 0.33f, height - 10f)
private val bcRect = RectF(width * 0.33f, height * 0.66f, width * 0.66f, height - 10f)
private val brRect = RectF(width * 0.66f, height * 0.66f, width - 10f, height - 10f)
private val mrRect = RectF(width * 0.66f, height * 0.33f, width - 0f, height * 0.66f)
private val blRect = RectF(0f, height * 0.66f, width * 0.33f, height - 0f)
private val bcRect = RectF(width * 0.33f, height * 0.66f, width * 0.66f, height - 0f)
private val brRect = RectF(width * 0.66f, height * 0.66f, width - 0f, height - 0f)
private val autoPageRect by lazy { Rect() }
private val autoPagePint by lazy { Paint().apply { color = context.accentColor } }
private val boundary by lazy { BreakIterator.getWordInstance(Locale.getDefault()) }
@ -103,15 +103,15 @@ class ReadView(context: Context, attrs: AttributeSet) :
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
tlRect.set(10F, 10F, width * 0.33f, height * 0.33f)
tcRect.set(width * 0.33f, 10F, width * 0.66f, height * 0.33f)
trRect.set(width * 0.36f, 10F, width - 10f, height * 0.33f)
mlRect.set(10F, height * 0.33f, width * 0.33f, height * 0.66f)
tlRect.set(0f, 0f, width * 0.33f, height * 0.33f)
tcRect.set(width * 0.33f, 0f, width * 0.66f, height * 0.33f)
trRect.set(width * 0.36f, 0f, width - 0f, height * 0.33f)
mlRect.set(0f, height * 0.33f, width * 0.33f, height * 0.66f)
mcRect.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
mrRect.set(width * 0.66f, height * 0.33f, width - 10f, height * 0.66f)
blRect.set(10F, height * 0.66f, width * 0.33f, height - 10f)
bcRect.set(width * 0.33f, height * 0.66f, width * 0.66f, height - 10f)
brRect.set(width * 0.66f, height * 0.66f, width - 10f, height - 10f)
mrRect.set(width * 0.66f, height * 0.33f, width - 0f, height * 0.66f)
blRect.set(0f, height * 0.66f, width * 0.33f, height - 10f)
bcRect.set(width * 0.33f, height * 0.66f, width * 0.66f, height - 0f)
brRect.set(width * 0.66f, height * 0.66f, width - 0f, height - 0f)
prevPage.x = -w.toFloat()
pageDelegate?.setViewSize(w, h)
}

@ -21,7 +21,6 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class BookSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<BookSource, ItemBookSourceBinding>(context),
@ -194,8 +193,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -153,8 +153,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -17,7 +17,6 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class RssSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssSource, ItemRssSourceBinding>(context),
@ -160,8 +159,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -12,7 +12,6 @@ import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ItemRuleSubBinding
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class RuleSubAdapter(context: Context, val callBack: Callback) :
SimpleRecyclerAdapter<RuleSub, ItemRuleSubBinding>(context),
@ -74,8 +73,7 @@ class RuleSubAdapter(context: Context, val callBack: Callback) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

Loading…
Cancel
Save