add portrait photo scrolling at selection
This commit is contained in:
parent
d70dd26ea6
commit
420a6459e7
2 changed files with 14 additions and 4 deletions
|
@ -15,7 +15,7 @@ import com.simplemobiletools.gallery.pro.R
|
||||||
import kotlinx.android.synthetic.main.portrait_photo_item.view.*
|
import kotlinx.android.synthetic.main.portrait_photo_item.view.*
|
||||||
import java.util.*
|
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>() {
|
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private var currentSelection = photos.firstOrNull { it.contains("cover", true) } ?: photos.firstOrNull { it.isNotEmpty() }
|
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())
|
.transition(DrawableTransitionOptions.withCrossFade())
|
||||||
.apply(options)
|
.apply(options)
|
||||||
.into(portrait_photo_item_thumbnail)
|
.into(portrait_photo_item_thumbnail)
|
||||||
|
|
||||||
|
if (photo.isNotEmpty()) {
|
||||||
|
setOnClickListener {
|
||||||
|
itemClick(position, x.toInt())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setOnClickListener(null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,7 +458,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
|
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
val screenWidth = context!!.realScreenSize.x
|
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 sideWidth = screenWidth / 2 - itemWidth / 2
|
||||||
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
|
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
|
||||||
|
|
||||||
|
@ -480,8 +480,10 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
curWidth += itemWidth
|
curWidth += itemWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
val sideElementWidth = curWidth.toInt() - screenWidth
|
val sideElementWidth = curWidth - screenWidth
|
||||||
val adapter = PortraitPhotosAdapter(context!!, paths, sideElementWidth) {
|
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
|
mView.photo_portrait_stripe.adapter = adapter
|
||||||
|
|
Loading…
Reference in a new issue