Remove unused viewstatepageradapter dependency

This commit is contained in:
arkon 2022-07-31 11:48:23 -04:00
parent a2d53c439e
commit 2ca62c4eda
3 changed files with 7 additions and 74 deletions

View File

@ -247,7 +247,6 @@ dependencies {
implementation(libs.androidprocessbutton)
implementation(libs.flexible.adapter.core)
implementation(libs.flexible.adapter.ui)
implementation(libs.viewstatepageradapter)
implementation(libs.photoview)
implementation(libs.directionalviewpager) {
exclude(group = "androidx.viewpager", module = "viewpager")

View File

@ -1,65 +0,0 @@
package eu.kanade.tachiyomi.widget
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.ViewPager
import com.nightlynexus.viewstatepageradapter.ViewStatePagerAdapter
import java.util.Stack
abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
private val pool = HashMap<Int, Stack<View>>()
var recycle = true
set(value) {
if (!value) pool.clear()
field = value
}
protected abstract fun getViewType(position: Int): Int
protected abstract fun inflateView(container: ViewGroup, viewType: Int): View
protected abstract fun bindView(view: View, position: Int)
protected open fun recycleView(view: View, position: Int) {}
override fun createView(container: ViewGroup, position: Int): View {
val viewType = getViewType(position)
val view = if (pool[viewType] != null && pool[viewType]!!.isNotEmpty()) {
pool[viewType]!!.pop().setViewPagerPositionParam(position)
} else {
inflateView(container, viewType)
}
bindView(view, position)
return view
}
override fun destroyView(container: ViewGroup, position: Int, view: View) {
recycleView(view, position)
val viewType = getViewType(position)
if (pool[viewType] == null) pool[viewType] = Stack<View>()
if (recycle) pool[viewType]!!.push(view)
}
/**
* Making sure that this ViewPager child view has the correct "position" layout param
* after being recycled.
*/
private fun View.setViewPagerPositionParam(position: Int): View {
val params = layoutParams
if (params is ViewPager.LayoutParams) {
if (!params.isDecor) {
try {
val positionField = ViewPager.LayoutParams::class.java.getDeclaredField("position")
positionField.isAccessible = true
positionField.setInt(params, position)
layoutParams = params
} catch (e: NoSuchFieldException) {
} catch (e: IllegalAccessException) {
}
}
}
return this
}
}

View File

@ -63,7 +63,6 @@ material = "com.google.android.material:material:1.7.0-alpha03"
androidprocessbutton = "com.github.dmytrodanylyk.android-process-button:library:1.0.4"
flexible-adapter-core = "com.github.arkon.FlexibleAdapter:flexible-adapter:c8013533"
flexible-adapter-ui = "com.github.arkon.FlexibleAdapter:flexible-adapter-ui:c8013533"
viewstatepageradapter = "com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0"
photoview = "com.github.chrisbanes:PhotoView:2.3.0"
directionalviewpager = "com.github.tachiyomiorg:DirectionalViewPager:1.0.0"
insetter = "dev.chrisbanes.insetter:insetter:0.6.1"