speed up the sidebar date and time formatter at scrolling

This commit is contained in:
tibbi 2020-04-23 22:34:58 +02:00
parent f8c80c2a5f
commit db210e8bd1
5 changed files with 23 additions and 7 deletions

View file

@ -61,6 +61,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
private var mLoadedInitialPhotos = false
private var mIsSearchOpen = false
private var mLastSearchedText = ""
private var mDateFormat = ""
private var mTimeFormat = ""
private var mLatestMediaId = 0L
private var mLatestMediaDateId = 0L
private var mLastMediaHandler = Handler()
@ -122,6 +124,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
override fun onResume() {
super.onResume()
mDateFormat = config.dateFormat
mTimeFormat = getTimeFormat()
if (mStoredAnimateGifs != config.animateGifs) {
getMediaAdapter()?.updateAnimateGifs(config.animateGifs)
}
@ -443,7 +448,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
if (mediaAdapter?.isASectionTitle(index) == true) {
realIndex++
}
return mediaAdapter?.getItemBubbleText(realIndex, sorting) ?: ""
return mediaAdapter?.getItemBubbleText(realIndex, sorting, mDateFormat, mTimeFormat) ?: ""
}
private fun checkLastMediaChanged() {

View file

@ -31,6 +31,8 @@ import java.io.File
class SearchActivity : SimpleActivity(), MediaOperationsListener {
private var mIsSearchOpen = false
private var mLastSearchedText = ""
private var mDateFormat = ""
private var mTimeFormat = ""
private var mSearchMenuItem: MenuItem? = null
private var mCurrAsyncTask: GetMediaAsynctask? = null
@ -40,6 +42,8 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search)
media_empty_text_placeholder.setTextColor(config.textColor)
mDateFormat = config.dateFormat
mTimeFormat = getTimeFormat()
getAllMedia()
}
@ -232,7 +236,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
if (mediaAdapter?.isASectionTitle(index) == true) {
realIndex++
}
return mediaAdapter?.getItemBubbleText(realIndex, sorting) ?: ""
return mediaAdapter?.getItemBubbleText(realIndex, sorting, mDateFormat, mTimeFormat) ?: ""
}
private fun measureRecyclerViewContent(media: ArrayList<ThumbnailItem>) {

View file

@ -493,7 +493,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
}, INSTANT_LOAD_DURATION)
}
fun getItemBubbleText(position: Int, sorting: Int) = (media[position] as? Medium)?.getBubbleText(sorting, activity)
fun getItemBubbleText(position: Int, sorting: Int, dateFormat: String, timeFormat: String): String {
return (media[position] as? Medium)?.getBubbleText(sorting, activity, dateFormat, timeFormat) ?: ""
}
private fun setupThumbnail(view: View, medium: Medium) {
val isSelected = selectedKeys.contains(medium.path.hashCode())

View file

@ -5,6 +5,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.beGoneIf
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getTimeFormat
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.gallery.pro.R
@ -74,6 +75,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType
val sorting = activity.config.getFolderSorting(if (path.isEmpty()) SHOW_ALL else path)
val dateFormat = activity.config.dateFormat
val timeFormat = activity.getTimeFormat()
view.apply {
media_grid.adapter = adapter
@ -86,12 +89,14 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
if (scrollHorizontally) {
media_horizontal_fastscroller.allowBubbleDisplay = activity.config.showInfoBubble
media_horizontal_fastscroller.setViews(media_grid) {
media_horizontal_fastscroller.updateBubbleText((media[it] as? Medium)?.getBubbleText(sorting, activity) ?: "")
val medium = (media[it] as? Medium)
media_horizontal_fastscroller.updateBubbleText(medium?.getBubbleText(sorting, activity, dateFormat, timeFormat) ?: "")
}
} else {
media_vertical_fastscroller.allowBubbleDisplay = activity.config.showInfoBubble
media_vertical_fastscroller.setViews(media_grid) {
media_vertical_fastscroller.updateBubbleText((media[it] as? Medium)?.getBubbleText(sorting, activity) ?: "")
val medium = (media[it] as? Medium)
media_vertical_fastscroller.updateBubbleText(medium?.getBubbleText(sorting, activity, dateFormat, timeFormat) ?: "")
}
}
}

View file

@ -48,11 +48,11 @@ data class Medium(
fun isHidden() = name.startsWith('.')
fun getBubbleText(sorting: Int, context: Context) = when {
fun getBubbleText(sorting: Int, context: Context, dateFormat: String, timeFormat: String) = when {
sorting and SORT_BY_NAME != 0 -> name
sorting and SORT_BY_PATH != 0 -> path
sorting and SORT_BY_SIZE != 0 -> size.formatSize()
sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate(context)
sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate(context, dateFormat, timeFormat)
else -> taken.formatDate(context)
}