improve portrait photos positioning

This commit is contained in:
tibbi 2019-10-02 19:25:27 +02:00
parent 3c151e27a6
commit 29cd22bda7
3 changed files with 36 additions and 16 deletions

View File

@ -12,17 +12,15 @@ import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.getFileKey import com.simplemobiletools.commons.extensions.getFileKey
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.extensions.realScreenSize
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 itemClick: (Int) -> Unit) : class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int) -> Unit) :
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() { RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
private var currentSelection = photos.first() private var currentSelection = photos.first()
private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background) 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).toInt()
private val itemWidth = context.resources.getDimension(R.dimen.portrait_photos_stripe_height) + context.resources.getDimension(R.dimen.one_dp)
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindView(photos[position], position) 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) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(photo: String, position: Int): View { fun bindView(photo: String, position: Int): View {
itemView.apply { itemView.apply {
if (position == 0) { if (position == 0 || position == photos.size - 1) {
portrait_photo_item_holder.setPadding(getStripeSidePadding(), 0, 0, 0) portrait_photo_item_thumbnail.layoutParams.width = sideElementWidth
} else if (position == photos.size - 1) { } else {
portrait_photo_item_holder.setPadding(0, 0, getStripeSidePadding(), 0) portrait_photo_item_thumbnail.layoutParams.width = itemWidth
} }
portrait_photo_item_thumbnail.background = if (getCurrentPhoto() == photo) { portrait_photo_item_thumbnail.background = if (photo.isEmpty() || getCurrentPhoto() != photo) {
strokeBackground
} else {
null null
} else {
strokeBackground
} }
val options = RequestOptions() val options = RequestOptions()
@ -66,6 +64,4 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
return itemView return itemView
} }
} }
private fun getStripeSidePadding() = screenWidth / 2 - (itemWidth / 2).toInt()
} }

View File

@ -56,6 +56,7 @@ import pl.droidsonroids.gif.InputSource
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.util.* import java.util.*
import kotlin.math.ceil
class PhotoFragment : ViewPagerFragment() { class PhotoFragment : ViewPagerFragment() {
private val DEFAULT_DOUBLE_TAP_ZOOM = 2f private val DEFAULT_DOUBLE_TAP_ZOOM = 2f
@ -456,10 +457,33 @@ 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 paths = files.map { it.absolutePath }.toMutableList() as ArrayList<String> val screenWidth = context!!.realScreenSize.x
val adapter = PortraitPhotosAdapter(context!!, paths) { 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 mView.photo_portrait_stripe.adapter = adapter
} }
} }

View File

@ -86,7 +86,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:visibility="gone"> android:visibility="gone">
<com.simplemobiletools.commons.views.MyRecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/photo_portrait_stripe" android:id="@+id/photo_portrait_stripe"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"