add portrait photo scrolling at selection

This commit is contained in:
tibbi 2019-10-02 19:51:09 +02:00
parent d70dd26ea6
commit 420a6459e7
2 changed files with 14 additions and 4 deletions

View file

@ -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<String>, val sideElementWidth: Int, val itemClick: (Int) -> Unit) :
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) :
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
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<String>,
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.into(portrait_photo_item_thumbnail)
if (photo.isNotEmpty()) {
setOnClickListener {
itemClick(position, x.toInt())
}
} else {
setOnClickListener(null)
}
}
return itemView
}

View file

@ -458,7 +458,7 @@ class PhotoFragment : ViewPagerFragment() {
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
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