minor cleanup, moving some code in separate functions

This commit is contained in:
tibbi 2019-10-02 21:07:05 +02:00
parent fd34074a48
commit efee783e1f

View file

@ -455,6 +455,30 @@ class PhotoFragment : ViewPagerFragment() {
val sideWidth = screenWidth / 2 - itemWidth / 2 val sideWidth = screenWidth / 2 - itemWidth / 2
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt() val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
val paths = fillPhotoPaths(files, fakeItemsCnt)
var curWidth = itemWidth
while (curWidth < screenWidth) {
curWidth += itemWidth
}
val sideElementWidth = curWidth - screenWidth
val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { position, x ->
mView.photo_portrait_stripe.smoothScrollBy((x + itemWidth / 2) - screenWidth / 2, 0)
}
mView.photo_portrait_stripe.adapter = adapter
setupStripeBottomMargin()
val coverIndex = getCoverImageIndex(paths)
mView.photo_portrait_stripe.onGlobalLayout {
mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0)
adapter.setCurrentPhoto(coverIndex)
mView.photo_portrait_stripe_wrapper.beVisible()
}
}
}
private fun fillPhotoPaths(files: ArrayList<File>, fakeItemsCnt: Int): ArrayList<String> {
val paths = ArrayList<String>() val paths = ArrayList<String>()
for (i in 0 until fakeItemsCnt) { for (i in 0 until fakeItemsCnt) {
paths.add("") paths.add("")
@ -467,25 +491,18 @@ class PhotoFragment : ViewPagerFragment() {
for (i in 0 until fakeItemsCnt) { for (i in 0 until fakeItemsCnt) {
paths.add("") paths.add("")
} }
return paths
var curWidth = itemWidth
while (curWidth < screenWidth) {
curWidth += itemWidth
} }
val sideElementWidth = curWidth - screenWidth private fun setupStripeBottomMargin() {
val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { position, x ->
mView.photo_portrait_stripe.smoothScrollBy((x + itemWidth / 2) - screenWidth / 2, 0)
}
mView.photo_portrait_stripe.adapter = adapter
var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt() var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt()
if (context!!.config.bottomActions) { if (context!!.config.bottomActions) {
bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt() bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt()
} }
(mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin (mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin
}
private fun getCoverImageIndex(paths: ArrayList<String>): Int {
var coverIndex = -1 var coverIndex = -1
paths.forEachIndexed { index, path -> paths.forEachIndexed { index, path ->
if (path.contains("cover", true)) { if (path.contains("cover", true)) {
@ -500,13 +517,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
} }
return coverIndex
mView.photo_portrait_stripe.onGlobalLayout {
mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0)
adapter.setCurrentPhoto(coverIndex)
mView.photo_portrait_stripe_wrapper.beVisible()
}
}
} }
private fun openPanorama() { private fun openPanorama() {