mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
minor cleanup, moving some code in separate functions
This commit is contained in:
parent
fd34074a48
commit
efee783e1f
1 changed files with 45 additions and 34 deletions
|
@ -455,19 +455,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
val sideWidth = screenWidth / 2 - itemWidth / 2
|
val sideWidth = screenWidth / 2 - itemWidth / 2
|
||||||
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
|
val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt()
|
||||||
|
|
||||||
val paths = ArrayList<String>()
|
val paths = fillPhotoPaths(files, fakeItemsCnt)
|
||||||
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
|
var curWidth = itemWidth
|
||||||
while (curWidth < screenWidth) {
|
while (curWidth < screenWidth) {
|
||||||
curWidth += itemWidth
|
curWidth += itemWidth
|
||||||
|
@ -479,28 +467,9 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.photo_portrait_stripe.adapter = adapter
|
mView.photo_portrait_stripe.adapter = adapter
|
||||||
|
setupStripeBottomMargin()
|
||||||
|
|
||||||
var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt()
|
val coverIndex = getCoverImageIndex(paths)
|
||||||
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.onGlobalLayout {
|
||||||
mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0)
|
mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0)
|
||||||
adapter.setCurrentPhoto(coverIndex)
|
adapter.setCurrentPhoto(coverIndex)
|
||||||
|
@ -509,6 +478,48 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fillPhotoPaths(files: ArrayList<File>, fakeItemsCnt: Int): ArrayList<String> {
|
||||||
|
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("")
|
||||||
|
}
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupStripeBottomMargin() {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getCoverImageIndex(paths: ArrayList<String>): Int {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return coverIndex
|
||||||
|
}
|
||||||
|
|
||||||
private fun openPanorama() {
|
private fun openPanorama() {
|
||||||
Intent(context, PanoramaPhotoActivity::class.java).apply {
|
Intent(context, PanoramaPhotoActivity::class.java).apply {
|
||||||
putExtra(PATH, mMedium.path)
|
putExtra(PATH, mMedium.path)
|
||||||
|
|
Loading…
Reference in a new issue