From fd34074a48acf8f3a83be500ff4dcff750f6cecf Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Oct 2019 20:57:49 +0200 Subject: [PATCH] properly handle the default portrait image selection --- .../pro/adapters/PortraitPhotosAdapter.kt | 13 +++---- .../gallery/pro/fragments/PhotoFragment.kt | 34 +++++++++++++++---- app/src/main/res/layout/pager_photo_item.xml | 2 +- 3 files changed, 33 insertions(+), 16 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 650207fb3..708a7c01b 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 @@ -18,7 +18,7 @@ import java.util.* 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() } + var currentSelectionIndex = -1 private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background) private val itemWidth = context.resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() @@ -33,12 +33,9 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, override fun getItemCount() = photos.size - fun getCurrentPhoto() = currentSelection - - private fun setCurrentPhoto(position: Int) { - val newPhoto = photos.getOrNull(position) ?: return - if (currentSelection != newPhoto) { - currentSelection = newPhoto + fun setCurrentPhoto(position: Int) { + if (currentSelectionIndex != position) { + currentSelectionIndex = position notifyDataSetChanged() } } @@ -52,7 +49,7 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, itemWidth } - portrait_photo_item_thumbnail.background = if (photo.isEmpty() || getCurrentPhoto() != photo) { + portrait_photo_item_thumbnail.background = if (photo.isEmpty() || position != currentSelectionIndex) { null } else { strokeBackground 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 6d902b1e5..3ed6d0fef 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 @@ -448,13 +448,6 @@ class PhotoFragment : ViewPagerFragment() { } private fun showPortraitStripe() { - var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt() - if (context!!.config.bottomActions) { - 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.beVisible() - val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList if (files != null) { val screenWidth = context!!.realScreenSize.x @@ -486,6 +479,33 @@ class PhotoFragment : ViewPagerFragment() { } mView.photo_portrait_stripe.adapter = adapter + + var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt() + if (context!!.config.bottomActions) { + bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt() + } + (mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin + + var coverIndex = -1 + paths.forEachIndexed { index, path -> + if (path.contains("cover", true)) { + coverIndex = index + } + } + + if (coverIndex == -1) { + paths.forEachIndexed { index, path -> + if (path.isNotEmpty()) { + coverIndex = index + } + } + } + + mView.photo_portrait_stripe.onGlobalLayout { + mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0) + adapter.setCurrentPhoto(coverIndex) + mView.photo_portrait_stripe_wrapper.beVisible() + } } } diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index 066740b3f..2198768c1 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -84,7 +84,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/portrait_photos_stripe_height" android:layout_alignParentBottom="true" - android:visibility="gone"> + android:visibility="invisible">