From 73e5333eefde717381519e498ffa805fe43d6991 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 19:24:22 +0200 Subject: [PATCH] recreate whole thumbnails view on toggling horizontal scroll --- .../gallery/activities/MainActivity.kt | 6 +- .../gallery/activities/MediaActivity.kt | 68 ++++++++++++------- .../gallery/adapters/DirectoryAdapter.kt | 5 -- .../gallery/adapters/MediaAdapter.kt | 6 -- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 400bbf1f2..edfec247a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -138,8 +138,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } if (mStoredScrollHorizontally != config.scrollHorizontally) { - getRecyclerAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally) - setupScrollDirection() + mLoadedInitialPhotos = false + directories_grid.adapter = null + getDirectories() } if (mStoredTextColor != config.textColor) { @@ -382,6 +383,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun toggleTemporarilyShowHidden(show: Boolean) { mLoadedInitialPhotos = false config.temporarilyShowHidden = show + directories_grid.adapter = null getDirectories() invalidateOptionsMenu() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 61721dbca..e37ca9f78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -61,8 +61,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mIsSearchOpen = false private var mLatestMediaId = 0L private var mLatestMediaDateId = 0L - private var mSectionTitleHeight = 0 - private var mThumbnailHeight = 0 private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetMediaAsynctask? = null @@ -126,8 +124,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } if (mStoredScrollHorizontally != config.scrollHorizontally) { - getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally) - setupScrollDirection() + mLoadedInitialPhotos = false + media_grid.adapter = null + getMedia() } if (mStoredTextColor != config.textColor) { @@ -591,33 +590,50 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun measureRecyclerViewContent(media: ArrayList) { - val layoutManager = media_grid.layoutManager as MyGridLayoutManager media_grid.onGlobalLayout { - val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 - mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 - mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height ?: 0 - - var fullHeight = 0 - var curSectionItems = 0 - media.forEach { - if (it is ThumbnailSection) { - fullHeight += mSectionTitleHeight - if (curSectionItems != 0) { - val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) - fullHeight += rows * mThumbnailHeight - } - curSectionItems = 0 - } else { - curSectionItems++ - } + if (config.scrollHorizontally) { + calculateContentWidth(media) + } else { + calculateContentHeight(media) } - - fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight - media_vertical_fastscroller.setContentHeight(fullHeight) - media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) } } + private fun calculateContentWidth(media: ArrayList) { + val layoutManager = media_grid.layoutManager as MyGridLayoutManager + val mThumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * mThumbnailWidth + media_horizontal_fastscroller.setContentWidth(fullWidth) + media_horizontal_fastscroller.setScrollTo(media_grid.computeHorizontalScrollOffset()) + } + + private fun calculateContentHeight(media: ArrayList) { + val layoutManager = media_grid.layoutManager as MyGridLayoutManager + val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally + val mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 + val mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height + ?: 0 + + var fullHeight = 0 + var curSectionItems = 0 + media.forEach { + if (it is ThumbnailSection) { + fullHeight += mSectionTitleHeight + if (curSectionItems != 0) { + val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) + fullHeight += rows * mThumbnailHeight + } + curSectionItems = 0 + } else { + curSectionItems++ + } + } + + fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight + media_vertical_fastscroller.setContentHeight(fullHeight) + media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) + } + private fun initZoomListener() { if (config.viewTypeFiles == VIEW_TYPE_GRID) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 87daaf994..1c77d7af1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -442,11 +442,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList