style update + wrap gifDrawables in try/catch

This commit is contained in:
tibbi 2017-11-02 09:43:49 +01:00
parent ac640bbccc
commit 9d8dd61dfa
3 changed files with 26 additions and 19 deletions

View file

@ -75,11 +75,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
media_refresh_layout.setOnRefreshListener({ getMedia() }) media_refresh_layout.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY) mPath = intent.getStringExtra(DIRECTORY)
mStoredAnimateGifs = config.animateGifs storeStateVariables()
mStoredCropThumbnails = config.cropThumbnails
mStoredScrollHorizontally = config.scrollHorizontally
mStoredTextColor = config.textColor
mShowAll = config.showAll
if (mShowAll) if (mShowAll)
supportActionBar?.setDisplayHomeAsUpEnabled(false) supportActionBar?.setDisplayHomeAsUpEnabled(false)
@ -117,10 +113,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
super.onPause() super.onPause()
mIsGettingMedia = false mIsGettingMedia = false
media_refresh_layout.isRefreshing = false media_refresh_layout.isRefreshing = false
mStoredAnimateGifs = config.animateGifs storeStateVariables()
mStoredCropThumbnails = config.cropThumbnails
mStoredScrollHorizontally = config.scrollHorizontally
mStoredTextColor = config.textColor
media_grid.listener = null media_grid.listener = null
mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.removeCallbacksAndMessages(null)
@ -136,6 +129,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mMedia.clear() mMedia.clear()
} }
private fun storeStateVariables() {
config.apply {
mStoredAnimateGifs = animateGifs
mStoredCropThumbnails = cropThumbnails
mStoredScrollHorizontally = scrollHorizontally
mStoredTextColor = textColor
mShowAll = showAll
}
}
private fun tryloadGallery() { private fun tryloadGallery() {
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) { if (it) {

View file

@ -301,8 +301,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
actMode?.finish() actMode?.finish()
} }
fun updateDisplayFilenames(display: Boolean) { fun updateDisplayFilenames(displayFilenames: Boolean) {
displayFilenames = display this.displayFilenames = displayFilenames
notifyDataSetChanged() notifyDataSetChanged()
} }

View file

@ -146,6 +146,7 @@ fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll
loadJpg(path, target, cropThumbnails) loadJpg(path, target, cropThumbnails)
} }
} else if (path.isGif()) { } else if (path.isGif()) {
try {
val gifDrawable = GifDrawable(path) val gifDrawable = GifDrawable(path)
target.setImageDrawable(gifDrawable) target.setImageDrawable(gifDrawable)
if (animateGifs) { if (animateGifs) {
@ -155,6 +156,9 @@ fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll
} }
target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
} catch (e: Exception) {
showErrorToast(e)
}
} }
} }