fix some recycler glitches at the directories view

This commit is contained in:
tibbi 2018-06-24 20:43:19 +02:00
parent dfccdd4040
commit 66962c3ec9
4 changed files with 43 additions and 19 deletions

View File

@ -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'

View File

@ -425,6 +425,32 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
layoutManager.spanCount = config.dirColumnCnt
}
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 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<Directory>) {
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)

View File

@ -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<ThumbnailItem>) {
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<ThumbnailItem>) {
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())
}

View File

@ -255,7 +255,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dirs = newDirs
finishActMode()
fastScroller?.measureRecyclerView()
listener?.updateDirectories(newDirs)
}
}
@ -423,7 +422,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dirs = newDirs
notifyDataSetChanged()
finishActMode()
fastScroller?.measureRecyclerView()
}
}