recreate whole thumbnails view on toggling horizontal scroll

This commit is contained in:
tibbi 2018-06-24 19:24:22 +02:00
parent 2d8ab6647d
commit 73e5333eef
4 changed files with 46 additions and 39 deletions

View file

@ -138,8 +138,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
if (mStoredScrollHorizontally != config.scrollHorizontally) {
getRecyclerAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally)
setupScrollDirection()
mLoadedInitialPhotos = false
directories_grid.adapter = null
getDirectories()
}
if (mStoredTextColor != config.textColor) {
@ -382,6 +383,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun toggleTemporarilyShowHidden(show: Boolean) {
mLoadedInitialPhotos = false
config.temporarilyShowHidden = show
directories_grid.adapter = null
getDirectories()
invalidateOptionsMenu()
}

View file

@ -61,8 +61,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private var mIsSearchOpen = false
private var mLatestMediaId = 0L
private var mLatestMediaDateId = 0L
private var mSectionTitleHeight = 0
private var mThumbnailHeight = 0
private var mLastMediaHandler = Handler()
private var mTempShowHiddenHandler = Handler()
private var mCurrAsyncTask: GetMediaAsynctask? = null
@ -126,8 +124,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
if (mStoredScrollHorizontally != config.scrollHorizontally) {
getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally)
setupScrollDirection()
mLoadedInitialPhotos = false
media_grid.adapter = null
getMedia()
}
if (mStoredTextColor != config.textColor) {
@ -591,33 +590,50 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
private fun measureRecyclerViewContent(media: ArrayList<ThumbnailItem>) {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager
media_grid.onGlobalLayout {
val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0
mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0
mThumbnailHeight = 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
if (curSectionItems != 0) {
val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1)
fullHeight += rows * mThumbnailHeight
}
curSectionItems = 0
} else {
curSectionItems++
}
if (config.scrollHorizontally) {
calculateContentWidth(media)
} else {
calculateContentHeight(media)
}
fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight
media_vertical_fastscroller.setContentHeight(fullHeight)
media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset())
}
}
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
media_horizontal_fastscroller.setContentWidth(fullWidth)
media_horizontal_fastscroller.setScrollTo(media_grid.computeHorizontalScrollOffset())
}
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
?: 0
var fullHeight = 0
var curSectionItems = 0
media.forEach {
if (it is ThumbnailSection) {
fullHeight += mSectionTitleHeight
if (curSectionItems != 0) {
val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1)
fullHeight += rows * mThumbnailHeight
}
curSectionItems = 0
} else {
curSectionItems++
}
}
fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight
media_vertical_fastscroller.setContentHeight(fullHeight)
media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset())
}
private fun initZoomListener() {
if (config.viewTypeFiles == VIEW_TYPE_GRID) {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager

View file

@ -442,11 +442,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
notifyDataSetChanged()
}
fun updateScrollHorizontally(scrollHorizontally: Boolean) {
this.scrollHorizontally = scrollHorizontally
notifyDataSetChanged()
}
private fun setupView(view: View, directory: Directory) {
view.apply {
dir_name.text = directory.name

View file

@ -335,7 +335,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
enableInstantLoad()
notifyDataSetChanged()
finishActMode()
fastScroller?.measureRecyclerView()
}, 100L)
}
}
@ -356,11 +355,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
notifyDataSetChanged()
}
fun updateScrollHorizontally(scrollHorizontally: Boolean) {
this.scrollHorizontally = scrollHorizontally
notifyDataSetChanged()
}
private fun enableInstantLoad() {
loadImageInstantly = true
delayHandler.postDelayed({