From 3c151e27a6581aa324bb86884fa702bdddf5bdb9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Oct 2019 16:43:41 +0200 Subject: [PATCH] allow sliding portrait photos to side --- app/build.gradle | 2 +- .../pro/adapters/PortraitPhotosAdapter.kt | 18 +++++++++++++++--- .../main/res/drawable/stroke_background.xml | 2 +- .../main/res/layout/portrait_photo_item.xml | 6 +++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e769648e5..29f344cce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.18.0' + implementation 'com.simplemobiletools:commons:5.18.1' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 a29ffe115..b44a2f448 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,16 +12,20 @@ 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) : RecyclerView.Adapter() { +class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, 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) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.bindView(photos[position]) + holder.bindView(photos[position], position) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -34,8 +38,14 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, fun getCurrentPhoto() = currentSelection inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - fun bindView(photo: String): 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) + } + portrait_photo_item_thumbnail.background = if (getCurrentPhoto() == photo) { strokeBackground } else { @@ -56,4 +66,6 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList, return itemView } } + + private fun getStripeSidePadding() = screenWidth / 2 - (itemWidth / 2).toInt() } diff --git a/app/src/main/res/drawable/stroke_background.xml b/app/src/main/res/drawable/stroke_background.xml index 6d274b7d2..518fda83c 100644 --- a/app/src/main/res/drawable/stroke_background.xml +++ b/app/src/main/res/drawable/stroke_background.xml @@ -2,7 +2,7 @@ - + diff --git a/app/src/main/res/layout/portrait_photo_item.xml b/app/src/main/res/layout/portrait_photo_item.xml index 3e0500cda..21b42ab42 100644 --- a/app/src/main/res/layout/portrait_photo_item.xml +++ b/app/src/main/res/layout/portrait_photo_item.xml @@ -3,8 +3,8 @@ android:id="@+id/portrait_photo_item_holder" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="1dp" - android:layout_marginEnd="1dp"> + android:layout_marginStart="@dimen/one_dp" + android:layout_marginEnd="@dimen/one_dp"> + android:padding="@dimen/one_dp" />