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 b44a2f448..3a3d3f4ee 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 @@ -12,17 +12,15 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.signature.ObjectKey import com.simplemobiletools.commons.extensions.getFileKey import com.simplemobiletools.gallery.pro.R -import com.simplemobiletools.gallery.pro.extensions.realScreenSize import kotlinx.android.synthetic.main.portrait_photo_item.view.* import java.util.* -class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, val itemClick: (Int) -> Unit) : +class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, val sideElementWidth: Int, val itemClick: (Int) -> Unit) : RecyclerView.Adapter() { private var currentSelection = photos.first() private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background) - private val screenWidth = context.realScreenSize.x - private val itemWidth = context.resources.getDimension(R.dimen.portrait_photos_stripe_height) + context.resources.getDimension(R.dimen.one_dp) + private val itemWidth = context.resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() override fun onBindViewHolder(holder: ViewHolder, position: Int) { holder.bindView(photos[position], position) @@ -40,16 +38,16 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { fun bindView(photo: String, position: Int): View { itemView.apply { - if (position == 0) { - portrait_photo_item_holder.setPadding(getStripeSidePadding(), 0, 0, 0) - } else if (position == photos.size - 1) { - portrait_photo_item_holder.setPadding(0, 0, getStripeSidePadding(), 0) + if (position == 0 || position == photos.size - 1) { + portrait_photo_item_thumbnail.layoutParams.width = sideElementWidth + } else { + portrait_photo_item_thumbnail.layoutParams.width = itemWidth } - portrait_photo_item_thumbnail.background = if (getCurrentPhoto() == photo) { - strokeBackground - } else { + portrait_photo_item_thumbnail.background = if (photo.isEmpty() || getCurrentPhoto() != photo) { null + } else { + strokeBackground } val options = RequestOptions() @@ -66,6 +64,4 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, return itemView } } - - private fun getStripeSidePadding() = screenWidth / 2 - (itemWidth / 2).toInt() } 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 86528c15c..ffc8d4a2a 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 @@ -56,6 +56,7 @@ import pl.droidsonroids.gif.InputSource import java.io.File import java.io.FileOutputStream import java.util.* +import kotlin.math.ceil class PhotoFragment : ViewPagerFragment() { private val DEFAULT_DOUBLE_TAP_ZOOM = 2f @@ -456,10 +457,33 @@ class PhotoFragment : ViewPagerFragment() { val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList if (files != null) { - val paths = files.map { it.absolutePath }.toMutableList() as ArrayList - val adapter = PortraitPhotosAdapter(context!!, paths) { + val screenWidth = context!!.realScreenSize.x + val itemWidth = context!!.resources.getDimension(R.dimen.portrait_photos_stripe_height) + context!!.resources.getDimension(R.dimen.one_dp) + val sideWidth = screenWidth / 2 - itemWidth / 2 + val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt() + val paths = ArrayList() + for (i in 0 until fakeItemsCnt) { + paths.add("") } + + files.forEach { + paths.add(it.absolutePath) + } + + for (i in 0 until fakeItemsCnt) { + paths.add("") + } + + var curWidth = itemWidth + while (curWidth < screenWidth) { + curWidth += itemWidth + } + + val sideElementWidth = curWidth.toInt() - screenWidth + val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) { + } + mView.photo_portrait_stripe.adapter = adapter } } diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index c3e8751fe..066740b3f 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -86,7 +86,7 @@ android:layout_alignParentBottom="true" android:visibility="gone"> -