Fix racecondition when button spam
This commit is contained in:
parent
6123048426
commit
728994a8f3
@ -6,6 +6,7 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import net.helcel.beans.activity.fragment.EditPlaceFragment
|
import net.helcel.beans.activity.fragment.EditPlaceFragment
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
class ViewPagerAdapter(
|
class ViewPagerAdapter(
|
||||||
fragmentManager: FragmentManager,
|
fragmentManager: FragmentManager,
|
||||||
@ -17,15 +18,13 @@ class ViewPagerAdapter(
|
|||||||
private val fragmentList: MutableList<EditPlaceFragment> = ArrayList()
|
private val fragmentList: MutableList<EditPlaceFragment> = ArrayList()
|
||||||
|
|
||||||
fun addFragment(src: EditPlaceFragment?, target: EditPlaceFragment) {
|
fun addFragment(src: EditPlaceFragment?, target: EditPlaceFragment) {
|
||||||
if (src != null) {
|
val idx = fragmentList.indexOf(src)
|
||||||
while (fragmentList.last() != src) {
|
viewPager.currentItem = max(0, idx)
|
||||||
fragmentList.removeLast()
|
if (src != null && idx >= 0) {
|
||||||
notifyItemRemoved(fragmentList.size)
|
fragmentList.subList(idx + 1, fragmentList.size).clear()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
println(src.toString() + " - " + target.toString())
|
|
||||||
fragmentList.add(target)
|
fragmentList.add(target)
|
||||||
notifyItemInserted(fragmentList.size)
|
notifyItemRangeChanged(max(0, idx), fragmentList.size)
|
||||||
viewPager.currentItem = fragmentList.size - 1
|
viewPager.currentItem = fragmentList.size - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user