mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
some cleanup around thumbnail loading
This commit is contained in:
parent
4b4869e845
commit
977edc1f34
6 changed files with 65 additions and 47 deletions
|
@ -125,36 +125,24 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
super.onResume()
|
||||
config.isThirdPartyIntent = false
|
||||
if (mStoredAnimateGifs != config.animateGifs) {
|
||||
(directories_grid.adapter as? DirectoryAdapter)?.apply {
|
||||
animateGifs = config.animateGifs
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getDirectoryAdapter()?.updateAnimateGifs(config.animateGifs)
|
||||
}
|
||||
|
||||
if (mStoredCropThumbnails != config.cropThumbnails) {
|
||||
(directories_grid.adapter as? DirectoryAdapter)?.apply {
|
||||
cropThumbnails = config.cropThumbnails
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getDirectoryAdapter()?.updateCropThumbnails(config.cropThumbnails)
|
||||
}
|
||||
|
||||
if (mStoredShowMediaCount != config.showMediaCount) {
|
||||
(directories_grid.adapter as? DirectoryAdapter)?.apply {
|
||||
showMediaCount = config.showMediaCount
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getDirectoryAdapter()?.updateShowMediaCount(config.showMediaCount)
|
||||
}
|
||||
|
||||
if (mStoredScrollHorizontally != config.scrollHorizontally) {
|
||||
(directories_grid.adapter as? DirectoryAdapter)?.apply {
|
||||
scrollVertically = config.viewTypeFolders == VIEW_TYPE_LIST || !config.scrollHorizontally
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getDirectoryAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally)
|
||||
setupScrollDirection()
|
||||
}
|
||||
|
||||
if (mStoredTextColor != config.textColor) {
|
||||
(directories_grid.adapter as? DirectoryAdapter)?.updateTextColor(config.textColor)
|
||||
getDirectoryAdapter()?.updateTextColor(config.textColor)
|
||||
}
|
||||
|
||||
tryloadGallery()
|
||||
|
@ -183,6 +171,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
removeTempFolder()
|
||||
}
|
||||
|
||||
private fun getDirectoryAdapter() = directories_grid.adapter as? DirectoryAdapter
|
||||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
mStoredAnimateGifs = animateGifs
|
||||
|
|
|
@ -90,29 +90,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (mStoredAnimateGifs != config.animateGifs) {
|
||||
(media_grid.adapter as? MediaAdapter)?.apply {
|
||||
animateGifs = config.animateGifs
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getMediaAdapter()?.updateAnimateGifs(config.animateGifs)
|
||||
}
|
||||
|
||||
if (mStoredCropThumbnails != config.cropThumbnails) {
|
||||
(media_grid.adapter as? MediaAdapter)?.apply {
|
||||
cropThumbnails = config.cropThumbnails
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getMediaAdapter()?.updateCropThumbnails(config.cropThumbnails)
|
||||
}
|
||||
|
||||
if (mStoredScrollHorizontally != config.scrollHorizontally) {
|
||||
(media_grid.adapter as? MediaAdapter)?.apply {
|
||||
scrollVertically = config.viewTypeFiles == VIEW_TYPE_LIST || !config.scrollHorizontally
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally)
|
||||
setupScrollDirection()
|
||||
}
|
||||
|
||||
if (mStoredTextColor != config.textColor) {
|
||||
(media_grid.adapter as? MediaAdapter)?.updateTextColor(config.textColor)
|
||||
getMediaAdapter()?.updateTextColor(config.textColor)
|
||||
}
|
||||
|
||||
tryloadGallery()
|
||||
|
@ -159,6 +150,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getMediaAdapter() = media_grid.adapter as? MediaAdapter
|
||||
|
||||
private fun checkIfColorChanged() {
|
||||
if (media_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) {
|
||||
getRecyclerAdapter().primaryColor = config.primaryColor
|
||||
|
|
|
@ -33,10 +33,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
private val config = activity.config
|
||||
var actMode: ActionMode? = null
|
||||
var primaryColor = config.primaryColor
|
||||
var scrollVertically = !config.scrollHorizontally
|
||||
var showMediaCount = config.showMediaCount
|
||||
var animateGifs = config.animateGifs
|
||||
var cropThumbnails = config.cropThumbnails
|
||||
|
||||
private val multiSelector = MultiSelector()
|
||||
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST
|
||||
|
@ -44,6 +40,10 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
private val selectedPositions = HashSet<Int>()
|
||||
private var textColor = config.textColor
|
||||
private var pinnedFolders = config.pinnedFolders
|
||||
private var scrollHorizontally = config.scrollHorizontally
|
||||
private var showMediaCount = config.showMediaCount
|
||||
private var animateGifs = config.animateGifs
|
||||
private var cropThumbnails = config.cropThumbnails
|
||||
|
||||
fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||
if (select) {
|
||||
|
@ -355,7 +355,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val dir = dirs[position]
|
||||
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollVertically, isListViewType, textColor, showMediaCount, animateGifs, cropThumbnails))
|
||||
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollHorizontally, isListViewType, textColor, showMediaCount, animateGifs, cropThumbnails))
|
||||
toggleItemSelection(selectedPositions.contains(position), position)
|
||||
holder.itemView.tag = holder
|
||||
}
|
||||
|
@ -373,6 +373,26 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
actMode?.finish()
|
||||
}
|
||||
|
||||
fun updateAnimateGifs(animateGifs: Boolean) {
|
||||
this.animateGifs = animateGifs
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateCropThumbnails(cropThumbnails: Boolean) {
|
||||
this.cropThumbnails = cropThumbnails
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateShowMediaCount(showMediaCount: Boolean) {
|
||||
this.showMediaCount = showMediaCount
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateScrollHorizontally(scrollHorizontally: Boolean) {
|
||||
this.scrollHorizontally = scrollHorizontally
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateTextColor(textColor: Int) {
|
||||
this.textColor = textColor
|
||||
notifyDataSetChanged()
|
||||
|
@ -420,13 +440,13 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
|
||||
val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) :
|
||||
SwappingHolder(view, MultiSelector()) {
|
||||
fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean, isListView: Boolean, textColor: Int, showMediaCount: Boolean,
|
||||
fun bindView(directory: Directory, isPinned: Boolean, scrollHorizontally: Boolean, isListView: Boolean, textColor: Int, showMediaCount: Boolean,
|
||||
animateGifs: Boolean, cropThumbnails: Boolean): View {
|
||||
itemView.apply {
|
||||
dir_name.text = directory.name
|
||||
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
|
||||
photo_cnt.text = directory.mediaCnt.toString()
|
||||
activity.loadImage(directory.tmb, dir_thumbnail, scrollVertically, animateGifs, cropThumbnails)
|
||||
activity.loadImage(directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||
dir_pin.beVisibleIf(isPinned)
|
||||
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
|
||||
photo_cnt.beVisibleIf(showMediaCount)
|
||||
|
|
|
@ -31,9 +31,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
private val config = activity.config
|
||||
var actMode: ActionMode? = null
|
||||
var primaryColor = config.primaryColor
|
||||
var scrollVertically = !config.scrollHorizontally
|
||||
var animateGifs = config.animateGifs
|
||||
var cropThumbnails = config.cropThumbnails
|
||||
|
||||
private val multiSelector = MultiSelector()
|
||||
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
|
||||
|
@ -41,6 +38,9 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
|
||||
private var itemViews = SparseArray<View>()
|
||||
private val selectedPositions = HashSet<Int>()
|
||||
private var scrollHorizontally = config.scrollHorizontally
|
||||
private var animateGifs = config.animateGifs
|
||||
private var cropThumbnails = config.cropThumbnails
|
||||
private var textColor = config.textColor
|
||||
private var displayFilenames = config.displayFileNames
|
||||
|
||||
|
@ -287,7 +287,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollVertically, isListViewType, textColor, animateGifs, cropThumbnails))
|
||||
itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollHorizontally, isListViewType, textColor, animateGifs, cropThumbnails))
|
||||
toggleItemSelection(selectedPositions.contains(position), position)
|
||||
holder.itemView.tag = holder
|
||||
}
|
||||
|
@ -310,6 +310,21 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateAnimateGifs(animateGifs: Boolean) {
|
||||
this.animateGifs = animateGifs
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateCropThumbnails(cropThumbnails: Boolean) {
|
||||
this.cropThumbnails = cropThumbnails
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateScrollHorizontally(scrollHorizontally: Boolean) {
|
||||
this.scrollHorizontally = scrollHorizontally
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateTextColor(textColor: Int) {
|
||||
this.textColor = textColor
|
||||
notifyDataSetChanged()
|
||||
|
@ -358,13 +373,13 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean,
|
||||
val itemClick: (Medium) -> (Unit)) :
|
||||
SwappingHolder(view, MultiSelector()) {
|
||||
fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean, isListViewType: Boolean, textColor: Int,
|
||||
fun bindView(medium: Medium, displayFilenames: Boolean, scrollHorizontally: Boolean, isListViewType: Boolean, textColor: Int,
|
||||
animateGifs: Boolean, cropThumbnails: Boolean): View {
|
||||
itemView.apply {
|
||||
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
|
||||
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
||||
photo_name.text = medium.name
|
||||
activity.loadImage(medium.path, medium_thumbnail, scrollVertically, animateGifs, cropThumbnails)
|
||||
activity.loadImage(medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
|
||||
|
||||
if (isListViewType) {
|
||||
photo_name.setTextColor(textColor)
|
||||
|
|
|
@ -201,8 +201,8 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
|
|||
}
|
||||
}
|
||||
|
||||
fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
|
||||
target.isVerticalScrolling = verticalScroll
|
||||
fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
|
||||
target.isHorizontalScrolling = horizontalScroll
|
||||
if (path.isImageFast() || path.isVideoFast()) {
|
||||
if (path.isPng()) {
|
||||
loadPng(path, target, cropThumbnails)
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.util.AttributeSet
|
|||
import android.widget.ImageView
|
||||
|
||||
class MySquareImageView : ImageView {
|
||||
var isVerticalScrolling = true
|
||||
var isHorizontalScrolling = false
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
|
@ -14,7 +14,7 @@ class MySquareImageView : ImageView {
|
|||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val spec = if (isVerticalScrolling) widthMeasureSpec else heightMeasureSpec
|
||||
val spec = if (isHorizontalScrolling) heightMeasureSpec else widthMeasureSpec
|
||||
super.onMeasure(spec, spec)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue