properly handle the default portrait image selection

This commit is contained in:
tibbi 2019-10-02 20:57:49 +02:00
parent 615f32935c
commit fd34074a48
3 changed files with 33 additions and 16 deletions

View file

@ -18,7 +18,7 @@ import java.util.*
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) :
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
private var currentSelection = photos.firstOrNull { it.contains("cover", true) } ?: photos.firstOrNull { it.isNotEmpty() }
var currentSelectionIndex = -1
private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background)
private val itemWidth = context.resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt()
@ -33,12 +33,9 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
override fun getItemCount() = photos.size
fun getCurrentPhoto() = currentSelection
private fun setCurrentPhoto(position: Int) {
val newPhoto = photos.getOrNull(position) ?: return
if (currentSelection != newPhoto) {
currentSelection = newPhoto
fun setCurrentPhoto(position: Int) {
if (currentSelectionIndex != position) {
currentSelectionIndex = position
notifyDataSetChanged()
}
}
@ -52,7 +49,7 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
itemWidth
}
portrait_photo_item_thumbnail.background = if (photo.isEmpty() || getCurrentPhoto() != photo) {
portrait_photo_item_thumbnail.background = if (photo.isEmpty() || position != currentSelectionIndex) {
null
} else {
strokeBackground

View file

@ -448,13 +448,6 @@ class PhotoFragment : ViewPagerFragment() {
}
private fun showPortraitStripe() {
var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt()
if (context!!.config.bottomActions) {
bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt()
}
(mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin
mView.photo_portrait_stripe_wrapper.beVisible()
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
if (files != null) {
val screenWidth = context!!.realScreenSize.x
@ -486,6 +479,33 @@ class PhotoFragment : ViewPagerFragment() {
}
mView.photo_portrait_stripe.adapter = adapter
var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt()
if (context!!.config.bottomActions) {
bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt()
}
(mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin
var coverIndex = -1
paths.forEachIndexed { index, path ->
if (path.contains("cover", true)) {
coverIndex = index
}
}
if (coverIndex == -1) {
paths.forEachIndexed { index, path ->
if (path.isNotEmpty()) {
coverIndex = index
}
}
}
mView.photo_portrait_stripe.onGlobalLayout {
mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0)
adapter.setCurrentPhoto(coverIndex)
mView.photo_portrait_stripe_wrapper.beVisible()
}
}
}

View file

@ -84,7 +84,7 @@
android:layout_width="match_parent"
android:layout_height="@dimen/portrait_photos_stripe_height"
android:layout_alignParentBottom="true"
android:visibility="gone">
android:visibility="invisible">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/photo_portrait_stripe"