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 { 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.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View File

@ -425,6 +425,32 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
layoutManager.spanCount = config.dirColumnCnt 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() { private fun initZoomListener() {
if (config.viewTypeFolders == VIEW_TYPE_GRID) { if (config.viewTypeFolders == VIEW_TYPE_GRID) {
val layoutManager = directories_grid.layoutManager as MyGridLayoutManager val layoutManager = directories_grid.layoutManager as MyGridLayoutManager
@ -466,19 +492,19 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
private fun increaseColumnCount() { private fun increaseColumnCount() {
directories_vertical_fastscroller.measureRecyclerViewOnRedraw()
directories_horizontal_fastscroller.measureRecyclerViewOnRedraw()
config.dirColumnCnt = ++(directories_grid.layoutManager as MyGridLayoutManager).spanCount config.dirColumnCnt = ++(directories_grid.layoutManager as MyGridLayoutManager).spanCount
invalidateOptionsMenu() columnCountChanged()
directories_grid.adapter?.notifyDataSetChanged()
} }
private fun reduceColumnCount() { private fun reduceColumnCount() {
directories_vertical_fastscroller.measureRecyclerViewOnRedraw()
directories_horizontal_fastscroller.measureRecyclerViewOnRedraw()
config.dirColumnCnt = --(directories_grid.layoutManager as MyGridLayoutManager).spanCount config.dirColumnCnt = --(directories_grid.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
}
private fun columnCountChanged() {
invalidateOptionsMenu() invalidateOptionsMenu()
directories_grid.adapter?.notifyDataSetChanged() directories_grid.adapter?.notifyDataSetChanged()
measureRecyclerViewContent(getRecyclerAdapter()!!.dirs)
} }
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent)) private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))
@ -698,7 +724,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
runOnUiThread { runOnUiThread {
directories_refresh_layout.isRefreshing = false directories_refresh_layout.isRefreshing = false
directories_vertical_fastscroller.measureRecyclerView()
checkPlaceholderVisibility(dirs) checkPlaceholderVisibility(dirs)
} }
checkInvalidDirectories(dirs, directoryDao) checkInvalidDirectories(dirs, directoryDao)
@ -763,12 +788,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
(currAdapter as DirectoryAdapter).updateDirs(directories) (currAdapter as DirectoryAdapter).updateDirs(directories)
} }
getRecyclerAdapter()?.dirs?.apply {
measureRecyclerViewContent(this)
}
setupScrollDirection() setupScrollDirection()
} }
private fun setupScrollDirection() { private fun setupScrollDirection() {
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID
directories_vertical_fastscroller.isHorizontal = false directories_vertical_fastscroller.isHorizontal = false
directories_vertical_fastscroller.beGoneIf(allowHorizontalScroll) directories_vertical_fastscroller.beGoneIf(allowHorizontalScroll)

View File

@ -355,7 +355,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll)
val sorting = config.getFileSorting(mPath) val sorting = config.getFileSorting(mPath)
if (allowHorizontalScroll) { if (allowHorizontalScroll) {
media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble
media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) {
@ -603,8 +602,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun calculateContentWidth(media: ArrayList<ThumbnailItem>) { private fun calculateContentWidth(media: ArrayList<ThumbnailItem>) {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager val layoutManager = media_grid.layoutManager as MyGridLayoutManager
val mThumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0
val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * mThumbnailWidth val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth
media_horizontal_fastscroller.setContentWidth(fullWidth) media_horizontal_fastscroller.setContentWidth(fullWidth)
media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset()) media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset())
} }
@ -612,18 +611,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun calculateContentHeight(media: ArrayList<ThumbnailItem>) { private fun calculateContentHeight(media: ArrayList<ThumbnailItem>) {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager val layoutManager = media_grid.layoutManager as MyGridLayoutManager
val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally
val mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0
val mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height val thumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height
?: 0 ?: 0
var fullHeight = 0 var fullHeight = 0
var curSectionItems = 0 var curSectionItems = 0
media.forEach { media.forEach {
if (it is ThumbnailSection) { if (it is ThumbnailSection) {
fullHeight += mSectionTitleHeight fullHeight += sectionTitleHeight
if (curSectionItems != 0) { if (curSectionItems != 0) {
val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1)
fullHeight += rows * mThumbnailHeight fullHeight += rows * thumbnailHeight
} }
curSectionItems = 0 curSectionItems = 0
} else { } 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.setContentHeight(fullHeight)
media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset()) media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset())
} }

View File

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