From fba4b6fc3e1cc4a5daf64fc1d3063f43c12c4ede Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 29 Nov 2021 22:11:02 +0100 Subject: [PATCH] we finally dont have to calculate content height and width --- .../gallery/pro/activities/MainActivity.kt | 61 ------------------- .../gallery/pro/activities/MediaActivity.kt | 51 ---------------- 2 files changed, 112 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index c7bee7abd..047759661 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -631,11 +631,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun setupGridLayoutManager() { val layoutManager = directories_grid.layoutManager as MyGridLayoutManager - (directories_grid.layoutParams as RelativeLayout.LayoutParams).apply { - topMargin = 0 - bottomMargin = 0 - } - if (config.scrollHorizontally) { layoutManager.orientation = RecyclerView.HORIZONTAL directories_refresh_layout.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) @@ -652,62 +647,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { layoutManager.spanCount = 1 layoutManager.orientation = RecyclerView.VERTICAL directories_refresh_layout.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - - val smallMargin = resources.getDimension(R.dimen.small_margin).toInt() - (directories_grid.layoutParams as RelativeLayout.LayoutParams).apply { - topMargin = smallMargin - bottomMargin = smallMargin - } - mZoomListener = null } - 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 fullWidth = if (config.folderStyle == FOLDER_STYLE_SQUARE) { - val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 - ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth - } else { - val thumbnailWidth = (layoutManager.getChildAt(0)?.width ?: 0) + resources.getDimension(R.dimen.medium_margin).toInt() * 2 - val columnCount = (directories.size - 1) / layoutManager.spanCount + 1 - columnCount * 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 fullHeight = if (config.folderStyle == FOLDER_STYLE_SQUARE) { - val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0 - ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight - } else { - var thumbnailHeight = (layoutManager.getChildAt(0)?.height ?: 0) - if (config.viewTypeFolders == VIEW_TYPE_GRID) { - thumbnailHeight += resources.getDimension(R.dimen.medium_margin).toInt() * 2 - } - - val rowCount = (directories.size - 1) / layoutManager.spanCount + 1 - rowCount * 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 @@ -768,7 +710,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { invalidateOptionsMenu() getRecyclerAdapter()?.apply { notifyItemRangeChanged(0, dirs.size) - measureRecyclerViewContent(dirs) } } @@ -1263,7 +1204,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } } - measureRecyclerViewContent(dirsToShow) } else { runOnUiThread { if (textToSearch.isNotEmpty()) { @@ -1273,7 +1213,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { checkPlaceholderVisibility(dirsToShow) (directories_grid.adapter as? DirectoryAdapter)?.updateDirs(dirsToShow) - measureRecyclerViewContent(dirsToShow) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 5d29ce485..7c5537e2f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -370,7 +370,6 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { handleGridSpacing(grouped) getMediaAdapter()?.updateMedia(grouped) - measureRecyclerViewContent(grouped) } } catch (ignored: Exception) { } @@ -425,11 +424,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { setupLayoutManager() handleGridSpacing() - measureRecyclerViewContent(mMedia) } else if (mLastSearchedText.isEmpty()) { (currAdapter as MediaAdapter).updateMedia(mMedia) handleGridSpacing() - measureRecyclerViewContent(mMedia) } else { searchQueryChanged(mLastSearchedText) } @@ -705,53 +702,6 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { mZoomListener = null } - private fun measureRecyclerViewContent(media: ArrayList) { - media_grid.onGlobalLayout { - if (config.scrollHorizontally) { - calculateContentWidth(media) - } else { - calculateContentHeight(media) - } - } - } - - private fun calculateContentWidth(media: ArrayList) { - val layoutManager = media_grid.layoutManager as MyGridLayoutManager - val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 - val spacing = config.thumbnailSpacing - val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * (thumbnailWidth + spacing) - spacing - /*media_horizontal_fastscroller.setContentWidth(fullWidth) - media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset())*/ - } - - private fun calculateContentHeight(media: ArrayList) { - val layoutManager = media_grid.layoutManager as MyGridLayoutManager - val pathToCheck = if (mPath.isEmpty()) SHOW_ALL else mPath - val hasSections = config.getFolderGrouping(pathToCheck) and GROUP_BY_NONE == 0 && !config.scrollHorizontally - 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 += sectionTitleHeight - if (curSectionItems != 0) { - val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) - fullHeight += rows * thumbnailHeight - } - curSectionItems = 0 - } else { - curSectionItems++ - } - } - - val spacing = config.thumbnailSpacing - fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * (thumbnailHeight + spacing) - spacing - /*media_vertical_fastscroller.setContentHeight(fullHeight) - media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset())*/ - } - private fun handleGridSpacing(media: ArrayList = mMedia) { val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) if (viewType == VIEW_TYPE_GRID) { @@ -814,7 +764,6 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { invalidateOptionsMenu() getMediaAdapter()?.apply { notifyItemRangeChanged(0, media.size) - measureRecyclerViewContent(media) } }