improve portrait photos positioning
This commit is contained in:
parent
3c151e27a6
commit
29cd22bda7
3 changed files with 36 additions and 16 deletions
|
@ -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<String>, val itemClick: (Int) -> Unit) :
|
||||
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int) -> Unit) :
|
||||
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
|
||||
|
||||
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<String>,
|
|||
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<String>,
|
|||
return itemView
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStripeSidePadding() = screenWidth / 2 - (itemWidth / 2).toInt()
|
||||
}
|
||||
|
|
|
@ -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<File>
|
||||
if (files != null) {
|
||||
val paths = files.map { it.absolutePath }.toMutableList() as ArrayList<String>
|
||||
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<String>()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/photo_portrait_stripe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
Loading…
Reference in a new issue