diff --git a/app/build.gradle b/app/build.gradle index 49da96ccb..9df4e778b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.1' + implementation 'com.simplemobiletools:commons:4.3.2' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 edfec247a..8ccc7d9fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -425,6 +425,32 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { layoutManager.spanCount = config.dirColumnCnt } + private fun measureRecyclerViewContent(directories: ArrayList) { + directories_grid.onGlobalLayout { + if (config.scrollHorizontally) { + calculateContentWidth(directories) + } else { + calculateContentHeight(directories) + } + } + } + + private fun calculateContentWidth(directories: ArrayList) { + val layoutManager = directories_grid.layoutManager as MyGridLayoutManager + val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth + directories_horizontal_fastscroller.setContentWidth(fullWidth) + directories_horizontal_fastscroller.setScrollToX(directories_grid.computeHorizontalScrollOffset()) + } + + private fun calculateContentHeight(directories: ArrayList) { + val layoutManager = directories_grid.layoutManager as MyGridLayoutManager + val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0 + val fullHeight = ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight + directories_vertical_fastscroller.setContentHeight(fullHeight) + directories_vertical_fastscroller.setScrollToY(directories_grid.computeVerticalScrollOffset()) + } + private fun initZoomListener() { if (config.viewTypeFolders == VIEW_TYPE_GRID) { val layoutManager = directories_grid.layoutManager as MyGridLayoutManager @@ -466,19 +492,19 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun increaseColumnCount() { - directories_vertical_fastscroller.measureRecyclerViewOnRedraw() - directories_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.dirColumnCnt = ++(directories_grid.layoutManager as MyGridLayoutManager).spanCount - invalidateOptionsMenu() - directories_grid.adapter?.notifyDataSetChanged() + columnCountChanged() } private fun reduceColumnCount() { - directories_vertical_fastscroller.measureRecyclerViewOnRedraw() - directories_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.dirColumnCnt = --(directories_grid.layoutManager as MyGridLayoutManager).spanCount + columnCountChanged() + } + + private fun columnCountChanged() { invalidateOptionsMenu() directories_grid.adapter?.notifyDataSetChanged() + measureRecyclerViewContent(getRecyclerAdapter()!!.dirs) } private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent)) @@ -698,7 +724,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { runOnUiThread { directories_refresh_layout.isRefreshing = false - directories_vertical_fastscroller.measureRecyclerView() checkPlaceholderVisibility(dirs) } checkInvalidDirectories(dirs, directoryDao) @@ -763,12 +788,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { (currAdapter as DirectoryAdapter).updateDirs(directories) } + getRecyclerAdapter()?.dirs?.apply { + measureRecyclerViewContent(this) + } setupScrollDirection() } private fun setupScrollDirection() { val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID - directories_vertical_fastscroller.isHorizontal = false directories_vertical_fastscroller.beGoneIf(allowHorizontalScroll) 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 05a309f7e..c15bb52f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -355,7 +355,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) val sorting = config.getFileSorting(mPath) - if (allowHorizontalScroll) { media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { @@ -603,8 +602,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { 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 + val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth media_horizontal_fastscroller.setContentWidth(fullWidth) media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset()) } @@ -612,18 +611,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { 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 + val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 + val thumbnailHeight = 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 + fullHeight += sectionTitleHeight if (curSectionItems != 0) { val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) - fullHeight += rows * mThumbnailHeight + fullHeight += rows * thumbnailHeight } curSectionItems = 0 } else { @@ -631,7 +630,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight + fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * thumbnailHeight media_vertical_fastscroller.setContentHeight(fullHeight) media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset()) } 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 1c77d7af1..a44740940 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -255,7 +255,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList