some cleanup around thumbnail loading

This commit is contained in:
tibbi 2017-10-28 14:11:01 +02:00
parent 4b4869e845
commit 977edc1f34
6 changed files with 65 additions and 47 deletions

View file

@ -125,36 +125,24 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
super.onResume() super.onResume()
config.isThirdPartyIntent = false config.isThirdPartyIntent = false
if (mStoredAnimateGifs != config.animateGifs) { if (mStoredAnimateGifs != config.animateGifs) {
(directories_grid.adapter as? DirectoryAdapter)?.apply { getDirectoryAdapter()?.updateAnimateGifs(config.animateGifs)
animateGifs = config.animateGifs
notifyDataSetChanged()
}
} }
if (mStoredCropThumbnails != config.cropThumbnails) { if (mStoredCropThumbnails != config.cropThumbnails) {
(directories_grid.adapter as? DirectoryAdapter)?.apply { getDirectoryAdapter()?.updateCropThumbnails(config.cropThumbnails)
cropThumbnails = config.cropThumbnails
notifyDataSetChanged()
}
} }
if (mStoredShowMediaCount != config.showMediaCount) { if (mStoredShowMediaCount != config.showMediaCount) {
(directories_grid.adapter as? DirectoryAdapter)?.apply { getDirectoryAdapter()?.updateShowMediaCount(config.showMediaCount)
showMediaCount = config.showMediaCount
notifyDataSetChanged()
}
} }
if (mStoredScrollHorizontally != config.scrollHorizontally) { if (mStoredScrollHorizontally != config.scrollHorizontally) {
(directories_grid.adapter as? DirectoryAdapter)?.apply { getDirectoryAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally)
scrollVertically = config.viewTypeFolders == VIEW_TYPE_LIST || !config.scrollHorizontally
notifyDataSetChanged()
}
setupScrollDirection() setupScrollDirection()
} }
if (mStoredTextColor != config.textColor) { if (mStoredTextColor != config.textColor) {
(directories_grid.adapter as? DirectoryAdapter)?.updateTextColor(config.textColor) getDirectoryAdapter()?.updateTextColor(config.textColor)
} }
tryloadGallery() tryloadGallery()
@ -183,6 +171,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
removeTempFolder() removeTempFolder()
} }
private fun getDirectoryAdapter() = directories_grid.adapter as? DirectoryAdapter
private fun storeStateVariables() { private fun storeStateVariables() {
config.apply { config.apply {
mStoredAnimateGifs = animateGifs mStoredAnimateGifs = animateGifs

View file

@ -90,29 +90,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (mStoredAnimateGifs != config.animateGifs) { if (mStoredAnimateGifs != config.animateGifs) {
(media_grid.adapter as? MediaAdapter)?.apply { getMediaAdapter()?.updateAnimateGifs(config.animateGifs)
animateGifs = config.animateGifs
notifyDataSetChanged()
}
} }
if (mStoredCropThumbnails != config.cropThumbnails) { if (mStoredCropThumbnails != config.cropThumbnails) {
(media_grid.adapter as? MediaAdapter)?.apply { getMediaAdapter()?.updateCropThumbnails(config.cropThumbnails)
cropThumbnails = config.cropThumbnails
notifyDataSetChanged()
}
} }
if (mStoredScrollHorizontally != config.scrollHorizontally) { if (mStoredScrollHorizontally != config.scrollHorizontally) {
(media_grid.adapter as? MediaAdapter)?.apply { getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally)
scrollVertically = config.viewTypeFiles == VIEW_TYPE_LIST || !config.scrollHorizontally
notifyDataSetChanged()
}
setupScrollDirection() setupScrollDirection()
} }
if (mStoredTextColor != config.textColor) { if (mStoredTextColor != config.textColor) {
(media_grid.adapter as? MediaAdapter)?.updateTextColor(config.textColor) getMediaAdapter()?.updateTextColor(config.textColor)
} }
tryloadGallery() tryloadGallery()
@ -159,6 +150,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
} }
private fun getMediaAdapter() = media_grid.adapter as? MediaAdapter
private fun checkIfColorChanged() { private fun checkIfColorChanged() {
if (media_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) { if (media_grid.adapter != null && getRecyclerAdapter().primaryColor != config.primaryColor) {
getRecyclerAdapter().primaryColor = config.primaryColor getRecyclerAdapter().primaryColor = config.primaryColor

View file

@ -33,10 +33,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
private val config = activity.config private val config = activity.config
var actMode: ActionMode? = null var actMode: ActionMode? = null
var primaryColor = config.primaryColor 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 multiSelector = MultiSelector()
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST 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 val selectedPositions = HashSet<Int>()
private var textColor = config.textColor private var textColor = config.textColor
private var pinnedFolders = config.pinnedFolders 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) { fun toggleItemSelection(select: Boolean, pos: Int) {
if (select) { if (select) {
@ -355,7 +355,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dir = dirs[position] 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) toggleItemSelection(selectedPositions.contains(position), position)
holder.itemView.tag = holder holder.itemView.tag = holder
} }
@ -373,6 +373,26 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
actMode?.finish() 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) { fun updateTextColor(textColor: Int) {
this.textColor = textColor this.textColor = textColor
notifyDataSetChanged() 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, 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)) : val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) :
SwappingHolder(view, MultiSelector()) { 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 { animateGifs: Boolean, cropThumbnails: Boolean): View {
itemView.apply { itemView.apply {
dir_name.text = directory.name dir_name.text = directory.name
dir_path?.text = "${directory.path.substringBeforeLast("/")}/" dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
photo_cnt.text = directory.mediaCnt.toString() 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_pin.beVisibleIf(isPinned)
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path)) dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
photo_cnt.beVisibleIf(showMediaCount) photo_cnt.beVisibleIf(showMediaCount)

View file

@ -31,9 +31,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
private val config = activity.config private val config = activity.config
var actMode: ActionMode? = null var actMode: ActionMode? = null
var primaryColor = config.primaryColor var primaryColor = config.primaryColor
var scrollVertically = !config.scrollHorizontally
var animateGifs = config.animateGifs
var cropThumbnails = config.cropThumbnails
private val multiSelector = MultiSelector() private val multiSelector = MultiSelector()
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST 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 var itemViews = SparseArray<View>()
private val selectedPositions = HashSet<Int>() 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 textColor = config.textColor
private var displayFilenames = config.displayFileNames 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) { 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) toggleItemSelection(selectedPositions.contains(position), position)
holder.itemView.tag = holder holder.itemView.tag = holder
} }
@ -310,6 +310,21 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
notifyDataSetChanged() 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) { fun updateTextColor(textColor: Int) {
this.textColor = textColor this.textColor = textColor
notifyDataSetChanged() notifyDataSetChanged()
@ -358,13 +373,13 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean, val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean,
val itemClick: (Medium) -> (Unit)) : val itemClick: (Medium) -> (Unit)) :
SwappingHolder(view, MultiSelector()) { 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 { animateGifs: Boolean, cropThumbnails: Boolean): View {
itemView.apply { itemView.apply {
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
photo_name.beVisibleIf(displayFilenames || isListViewType) photo_name.beVisibleIf(displayFilenames || isListViewType)
photo_name.text = medium.name 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) { if (isListViewType) {
photo_name.setTextColor(textColor) photo_name.setTextColor(textColor)

View file

@ -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) { fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
target.isVerticalScrolling = verticalScroll target.isHorizontalScrolling = horizontalScroll
if (path.isImageFast() || path.isVideoFast()) { if (path.isImageFast() || path.isVideoFast()) {
if (path.isPng()) { if (path.isPng()) {
loadPng(path, target, cropThumbnails) loadPng(path, target, cropThumbnails)

View file

@ -5,7 +5,7 @@ import android.util.AttributeSet
import android.widget.ImageView import android.widget.ImageView
class MySquareImageView : ImageView { class MySquareImageView : ImageView {
var isVerticalScrolling = true var isHorizontalScrolling = false
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@ -14,7 +14,7 @@ class MySquareImageView : ImageView {
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 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) super.onMeasure(spec, spec)
} }
} }