From 420a6459e778cb448274085db88b2b42d9b396ef Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Oct 2019 19:51:09 +0200 Subject: [PATCH] add portrait photo scrolling at selection --- .../gallery/pro/adapters/PortraitPhotosAdapter.kt | 10 +++++++++- .../gallery/pro/fragments/PhotoFragment.kt | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/PortraitPhotosAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/PortraitPhotosAdapter.kt index 983ea00a2..aa4666cbf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/PortraitPhotosAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/PortraitPhotosAdapter.kt @@ -15,7 +15,7 @@ import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.portrait_photo_item.view.* import java.util.* -class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, val sideElementWidth: Int, val itemClick: (Int) -> Unit) : +class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) : RecyclerView.Adapter() { private var currentSelection = photos.firstOrNull { it.contains("cover", true) } ?: photos.firstOrNull { it.isNotEmpty() } @@ -60,6 +60,14 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, .transition(DrawableTransitionOptions.withCrossFade()) .apply(options) .into(portrait_photo_item_thumbnail) + + if (photo.isNotEmpty()) { + setOnClickListener { + itemClick(position, x.toInt()) + } + } else { + setOnClickListener(null) + } } return itemView } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index ffc8d4a2a..c1401fe21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -458,7 +458,7 @@ class PhotoFragment : ViewPagerFragment() { val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList if (files != null) { val screenWidth = context!!.realScreenSize.x - val itemWidth = context!!.resources.getDimension(R.dimen.portrait_photos_stripe_height) + context!!.resources.getDimension(R.dimen.one_dp) + val itemWidth = context!!.resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() + context!!.resources.getDimension(R.dimen.one_dp).toInt() val sideWidth = screenWidth / 2 - itemWidth / 2 val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt() @@ -480,8 +480,10 @@ class PhotoFragment : ViewPagerFragment() { curWidth += itemWidth } - val sideElementWidth = curWidth.toInt() - screenWidth - val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { + 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