From 1b53acd0961ad1da3d2f37893a877338568dc269 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:02:40 +0200 Subject: [PATCH 1/7] disable temporarily showing hidden folders only on destroy --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 ++-- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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..907b3883b 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 } 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..3c9fab44c 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 } From e3f0d7ea56b28becd3cf784d464555a905b341ff Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:09:00 +0200 Subject: [PATCH 2/7] do not cache media while temporarily showing hidden is enabled --- .../simplemobiletools/gallery/activities/MainActivity.kt | 6 ++++-- .../simplemobiletools/gallery/activities/MediaActivity.kt | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) 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 907b3883b..e2c9649b9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -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 3c9fab44c..f3b861a9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -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) { From 18b714f9c382c930463440d0c3967da9ca19c613 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:11:28 +0200 Subject: [PATCH 3/7] do not continue at setting up the video if theres an error --- .../com/simplemobiletools/gallery/fragments/VideoFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From a04d2d80b6e96404f7f49cd9a6d0a5124cd5957a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:17:06 +0200 Subject: [PATCH 4/7] move cursor closing in the function using it --- .../gallery/extensions/context.kt | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) 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) From 4c3a318e17791d85c5fd345a5680bfcacf4b08fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Marques?= Date: Sun, 28 May 2017 22:29:19 +0100 Subject: [PATCH 5/7] Update strings.xml --- app/src/main/res/values-pt/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 124cf8960dffc155665885742e7252bbc7454396 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:37:12 +0200 Subject: [PATCH 6/7] add a couple null checks at multiselectors --- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 4 ++-- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 From 630e4e11b8cf96b18172863ad3b96bb15a1b0f16 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 May 2017 23:59:38 +0200 Subject: [PATCH 7/7] update commons to 2.18.8 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'