mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
we finally dont have to calculate content height and width
This commit is contained in:
parent
a67e5ff86f
commit
fba4b6fc3e
2 changed files with 0 additions and 112 deletions
|
@ -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<Directory>) {
|
||||
directories_grid.onGlobalLayout {
|
||||
if (config.scrollHorizontally) {
|
||||
calculateContentWidth(directories)
|
||||
} else {
|
||||
calculateContentHeight(directories)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateContentWidth(directories: ArrayList<Directory>) {
|
||||
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<Directory>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ThumbnailItem>) {
|
||||
media_grid.onGlobalLayout {
|
||||
if (config.scrollHorizontally) {
|
||||
calculateContentWidth(media)
|
||||
} else {
|
||||
calculateContentHeight(media)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateContentWidth(media: ArrayList<ThumbnailItem>) {
|
||||
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<ThumbnailItem>) {
|
||||
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<ThumbnailItem> = 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue