allow sliding portrait photos to side

This commit is contained in:
tibbi 2019-10-02 16:43:41 +02:00
parent 1e9318a789
commit 3c151e27a6
4 changed files with 20 additions and 8 deletions

View File

@ -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'

View File

@ -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<String>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, 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)
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<String>,
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<String>,
return itemView
}
}
private fun getStripeSidePadding() = screenWidth / 2 - (itemWidth / 2).toInt()
}

View File

@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFFFFFFF"/>
<stroke android:width="@dimen/one_dp" android:color="#FFFFFFFF"/>
</shape>
</item>
</selector>

View File

@ -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">
<ImageView
android:id="@+id/portrait_photo_item_thumbnail"
@ -12,6 +12,6 @@
android:layout_height="@dimen/portrait_photos_stripe_height"
android:background="@drawable/stroke_background"
android:contentDescription="@null"
android:padding="1dp" />
android:padding="@dimen/one_dp" />
</RelativeLayout>