diff --git a/app/build.gradle b/app/build.gradle index a8b99fcb8..b39eaf4aa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.18.5' + compile 'com.simplemobiletools:commons:2.18.8' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index e52b93000..e2c9649b9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -127,8 +127,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mLastMediaHandler.removeCallbacksAndMessages(null) } - override fun onStop() { - super.onStop() + override fun onDestroy() { + super.onDestroy() config.temporarilyShowHidden = false } @@ -342,8 +342,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun storeDirectories() { - val directories = Gson().toJson(mDirs) - config.directories = directories + if (!config.temporarilyShowHidden) { + val directories = Gson().toJson(mDirs) + config.directories = directories + } } private fun setupAdapter() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 5d1527b28..f3b861a9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -92,8 +92,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLastMediaHandler.removeCallbacksAndMessages(null) } - override fun onStop() { - super.onStop() + override fun onDestroy() { + super.onDestroy() config.temporarilyShowHidden = false } @@ -399,9 +399,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun storeFolder() { - val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size)) - val json = Gson().toJson(subList) - config.saveFolderMedia(mPath, json) + if (!config.temporarilyShowHidden) { + val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size)) + val json = Gson().toJson(subList) + config.saveFolderMedia(mPath, json) + } } override fun deleteFiles(files: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 2acc9dd99..4a5876a18 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -145,7 +145,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 - selectedPositions.map { media[it] }.forEach { + selectedPositions.map { media.getOrNull(it) }.filterNotNull().forEach { if (it.name.startsWith('.')) hiddenCnt++ else diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 5b92327d0..5c781f4df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -58,9 +58,7 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%") val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath)) - cur.use { cur -> - return parseCursor(this, cur, isPickImage, isPickVideo, curPath) - } + return parseCursor(this, cur, isPickImage, isPickVideo, curPath) } private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList { @@ -69,78 +67,80 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP val showMedia = config.showMedia val showHidden = config.shouldShowHidden - if (cur.moveToFirst()) { - var filename: String - var path: String - var dateTaken: Long - var dateModified: Long - var size: Long - var isImage: Boolean - var isVideo: Boolean - val excludedFolders = config.excludedFolders - val noMediaFolders = context.getNoMediaFolders() + cur.use { cur -> + if (cur.moveToFirst()) { + var filename: String + var path: String + var dateTaken: Long + var dateModified: Long + var size: Long + var isImage: Boolean + var isVideo: Boolean + val excludedFolders = config.excludedFolders + val noMediaFolders = context.getNoMediaFolders() - do { - try { - path = cur.getStringValue(MediaStore.Images.Media.DATA) - size = cur.getLongValue(MediaStore.Images.Media.SIZE) - if (size == 0L) { - size = File(path).length() - } - - if (size <= 0L) { - continue - } - - filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" - if (filename.isEmpty()) - filename = path.getFilenameFromPath() - - isImage = filename.isImageFast() || filename.isGif() - isVideo = if (isImage) false else filename.isVideoFast() - - if (!isImage && !isVideo) - continue - - if (isVideo && (isPickImage || showMedia == IMAGES)) - continue - - if (isImage && (isPickVideo || showMedia == VIDEOS)) - continue - - if (!showHidden && filename.startsWith('.')) - continue - - var isExcluded = false - excludedFolders.forEach { - if (path.startsWith(it)) { - isExcluded = true + do { + try { + path = cur.getStringValue(MediaStore.Images.Media.DATA) + size = cur.getLongValue(MediaStore.Images.Media.SIZE) + if (size == 0L) { + size = File(path).length() } - } - if (!isExcluded && !showHidden) { - noMediaFolders.forEach { + if (size <= 0L) { + continue + } + + filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" + if (filename.isEmpty()) + filename = path.getFilenameFromPath() + + isImage = filename.isImageFast() || filename.isGif() + isVideo = if (isImage) false else filename.isVideoFast() + + if (!isImage && !isVideo) + continue + + if (isVideo && (isPickImage || showMedia == IMAGES)) + continue + + if (isImage && (isPickVideo || showMedia == VIDEOS)) + continue + + if (!showHidden && filename.startsWith('.')) + continue + + var isExcluded = false + excludedFolders.forEach { if (path.startsWith(it)) { isExcluded = true } } - } - if (!isExcluded && !showHidden && path.contains("/.")) { - isExcluded = true - } + if (!isExcluded && !showHidden) { + noMediaFolders.forEach { + if (path.startsWith(it)) { + isExcluded = true + } + } + } - if (!isExcluded) { - dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) - dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L + if (!isExcluded && !showHidden && path.contains("/.")) { + isExcluded = true + } - val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) - curMedia.add(medium) + if (!isExcluded) { + dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) + dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L + + val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) + curMedia.add(medium) + } + } catch (e: Exception) { + continue } - } catch (e: Exception) { - continue - } - } while (cur.moveToNext()) + } while (cur.moveToNext()) + } } Medium.sorting = config.getFileSorting(curPath) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 09875dfe7..3f894e8e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -306,8 +306,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee return initMediaPlayer() - if (mMediaPlayer == null) + if (mMediaPlayer == null) { activity.toast(R.string.unknown_error_occurred) + return + } val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat() val display = activity.windowManager.defaultDisplay diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 010114801..fa5099f3f 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -74,7 +74,7 @@ A definir como fundo de ecrã… Fundo definido com sucesso Proporção na vertical - proporção na horizontal + Proporção na horizontal Mostrar pastas ocultas @@ -83,8 +83,8 @@ Mostrar multimédia Apenas imagens Apenas vídeos - Gifs only - Images, videos, gifs + Apenas gifs + Imagens, vídeos e gifs Imagens e vídeos Vídeos em ciclo Animação de gifs nas miniaturas