mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
rewrite scrolling to improve performance
This commit is contained in:
parent
ad1a787a15
commit
4123f67ad3
9 changed files with 59 additions and 16 deletions
|
@ -42,7 +42,7 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.5.0'
|
||||
implementation 'com.simplemobiletools:commons:3.5.9'
|
||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0'
|
||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
|
||||
implementation 'com.android.support:multidex:1.0.2'
|
||||
|
|
|
@ -402,12 +402,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
|
||||
private fun increaseColumnCount() {
|
||||
directories_vertical_fastscroller.measureRecyclerViewOnRedraw()
|
||||
directories_horizontal_fastscroller.measureRecyclerViewOnRedraw()
|
||||
config.dirColumnCnt = ++(directories_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
directories_grid.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
directories_vertical_fastscroller.measureRecyclerViewOnRedraw()
|
||||
directories_horizontal_fastscroller.measureRecyclerViewOnRedraw()
|
||||
config.dirColumnCnt = --(directories_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
directories_grid.adapter?.notifyDataSetChanged()
|
||||
|
@ -533,6 +537,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
directories_empty_text_label.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
||||
directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
||||
|
||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||
directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll)
|
||||
directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll)
|
||||
|
||||
checkLastMediaChanged()
|
||||
if (dirs.hashCode() == mDirs.hashCode()) {
|
||||
|
@ -559,7 +568,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
val currAdapter = directories_grid.adapter
|
||||
if (currAdapter == null) {
|
||||
initZoomListener()
|
||||
DirectoryAdapter(this, mDirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent)) {
|
||||
val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller
|
||||
DirectoryAdapter(this, mDirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) {
|
||||
itemClicked((it as Directory).path)
|
||||
}.apply {
|
||||
setupZoomListener(mZoomListener)
|
||||
|
|
|
@ -182,7 +182,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
val currAdapter = media_grid.adapter
|
||||
if (currAdapter == null) {
|
||||
initZoomListener()
|
||||
MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid) {
|
||||
val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller
|
||||
MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) {
|
||||
itemClicked((it as Medium).path)
|
||||
}.apply {
|
||||
setupZoomListener(mZoomListener)
|
||||
|
@ -466,12 +467,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun increaseColumnCount() {
|
||||
media_vertical_fastscroller.measureRecyclerViewOnRedraw()
|
||||
media_horizontal_fastscroller.measureRecyclerViewOnRedraw()
|
||||
config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
media_grid.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
media_vertical_fastscroller.measureRecyclerViewOnRedraw()
|
||||
media_horizontal_fastscroller.measureRecyclerViewOnRedraw()
|
||||
config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
media_grid.adapter?.notifyDataSetChanged()
|
||||
|
@ -548,6 +553,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||
media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||
media_grid.beVisibleIf(media_empty_text_label.isGone())
|
||||
|
||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||
media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
|
||||
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
||||
|
||||
checkLastMediaChanged()
|
||||
if (mLastDrawnHashCode == 0)
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
|||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||
|
@ -24,7 +25,8 @@ import java.io.File
|
|||
import java.util.*
|
||||
|
||||
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, recyclerView: MyRecyclerView,
|
||||
val isPickIntent: Boolean, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private val config = activity.config
|
||||
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST
|
||||
|
|
|
@ -14,7 +14,7 @@ import kotlinx.android.synthetic.main.item_manage_folder.view.*
|
|||
import java.util.*
|
||||
|
||||
class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<String>, val isShowingExcludedFolders: Boolean, val listener: RefreshRecyclerViewListener?,
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private val config = activity.config
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.io.File
|
|||
import java.util.*
|
||||
|
||||
class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<String>, val listener: RefreshRecyclerViewListener?,
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private val config = activity.config
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.simplemobiletools.gallery.adapters
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -12,22 +14,26 @@ import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
|||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import kotlinx.android.synthetic.main.photo_video_item_list.view.*
|
||||
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
||||
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null,
|
||||
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private val config = activity.config
|
||||
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
|
||||
private var skipConfirmationDialog = false
|
||||
private var visibleItemPaths = ArrayList<String>()
|
||||
private var delayHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
private var scrollHorizontally = config.scrollHorizontally
|
||||
private var animateGifs = config.animateGifs
|
||||
|
@ -51,6 +57,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
|||
|
||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||
val medium = media[position]
|
||||
visibleItemPaths.add(medium.path)
|
||||
val view = holder.bindView(medium, !allowMultiplePicks) { itemView, layoutPosition ->
|
||||
setupView(itemView, medium)
|
||||
}
|
||||
|
@ -92,7 +99,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
|||
override fun onViewRecycled(holder: ViewHolder?) {
|
||||
super.onViewRecycled(holder)
|
||||
if (!activity.isActivityDestroyed()) {
|
||||
Glide.with(activity).clear(holder?.itemView?.medium_thumbnail)
|
||||
val itemView = holder?.itemView
|
||||
visibleItemPaths.remove(itemView?.photo_name?.tag)
|
||||
Glide.with(activity).clear(itemView?.medium_thumbnail)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,7 +268,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
|||
play_outline.beVisibleIf(medium.video)
|
||||
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
||||
photo_name.text = medium.name
|
||||
photo_name.tag = medium.path
|
||||
|
||||
medium_thumbnail.isHorizontalScrolling = scrollHorizontally
|
||||
delayHandler.postDelayed({
|
||||
val isVisible = visibleItemPaths.contains(medium.path)
|
||||
if (isVisible) {
|
||||
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||
}
|
||||
}, 200)
|
||||
|
||||
if (isListViewType) {
|
||||
photo_name.setTextColor(textColor)
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/directories_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||
app:spanCount="@integer/directory_columns_vertical_scroll"/>
|
||||
|
@ -48,7 +48,8 @@
|
|||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:visibility="gone">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
|
@ -61,7 +62,8 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:paddingTop="@dimen/normal_margin">
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:visibility="gone">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_horizontal"/>
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/media_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||
app:spanCount="@integer/media_columns_vertical_scroll"/>
|
||||
|
@ -48,7 +48,8 @@
|
|||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:visibility="gone">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
|
@ -61,7 +62,8 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:paddingTop="@dimen/normal_margin">
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:visibility="gone">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_horizontal"/>
|
||||
|
||||
|
|
Loading…
Reference in a new issue