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

View File

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

View File

@ -146,15 +146,19 @@ fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll
loadJpg(path, target, cropThumbnails)
}
} else if (path.isGif()) {
val gifDrawable = GifDrawable(path)
target.setImageDrawable(gifDrawable)
if (animateGifs) {
gifDrawable.start()
} else {
gifDrawable.stop()
}
try {
val gifDrawable = GifDrawable(path)
target.setImageDrawable(gifDrawable)
if (animateGifs) {
gifDrawable.start()
} else {
gifDrawable.stop()
}
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)
}
}
}