mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
properly handle the default portrait image selection
This commit is contained in:
parent
615f32935c
commit
fd34074a48
3 changed files with 33 additions and 16 deletions
|
@ -18,7 +18,7 @@ import java.util.*
|
||||||
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) :
|
class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>, val sideElementWidth: Int, val itemClick: (Int, Int) -> Unit) :
|
||||||
RecyclerView.Adapter<PortraitPhotosAdapter.ViewHolder>() {
|
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 var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background)
|
||||||
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).toInt()
|
||||||
|
|
||||||
|
@ -33,12 +33,9 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
|
||||||
|
|
||||||
override fun getItemCount() = photos.size
|
override fun getItemCount() = photos.size
|
||||||
|
|
||||||
fun getCurrentPhoto() = currentSelection
|
fun setCurrentPhoto(position: Int) {
|
||||||
|
if (currentSelectionIndex != position) {
|
||||||
private fun setCurrentPhoto(position: Int) {
|
currentSelectionIndex = position
|
||||||
val newPhoto = photos.getOrNull(position) ?: return
|
|
||||||
if (currentSelection != newPhoto) {
|
|
||||||
currentSelection = newPhoto
|
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +49,7 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
|
||||||
itemWidth
|
itemWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
portrait_photo_item_thumbnail.background = if (photo.isEmpty() || getCurrentPhoto() != photo) {
|
portrait_photo_item_thumbnail.background = if (photo.isEmpty() || position != currentSelectionIndex) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
strokeBackground
|
strokeBackground
|
||||||
|
|
|
@ -448,13 +448,6 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPortraitStripe() {
|
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>
|
val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList<File>
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
val screenWidth = context!!.realScreenSize.x
|
val screenWidth = context!!.realScreenSize.x
|
||||||
|
@ -486,6 +479,33 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.photo_portrait_stripe.adapter = adapter
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/portrait_photos_stripe_height"
|
android:layout_height="@dimen/portrait_photos_stripe_height"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:visibility="gone">
|
android:visibility="invisible">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/photo_portrait_stripe"
|
android:id="@+id/photo_portrait_stripe"
|
||||||
|
|
Loading…
Reference in a new issue