From 570865bebf6d724c42c146186b62b5ad623989b8 Mon Sep 17 00:00:00 2001 From: FTno <16176811+FTno@users.noreply.github.com> Date: Fri, 13 Apr 2018 16:00:19 +0200 Subject: [PATCH 001/111] Update strings.xml Norwegian translation update --- app/src/main/res/values-nb/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 8b00f02b6..eacb6094d 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -5,7 +5,7 @@ Rediger Åpne kamera (skjult) - (excluded) + (ekskludert) Fest mappe Løsne mappe Fest til toppen From 502ecb6b0f0d2ae628ee694ad19c011b3941519b Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 21:26:48 +0200 Subject: [PATCH 002/111] update gradle to 3.1.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e6abf43e1..af56fd918 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0' + classpath 'com.android.tools.build:gradle:3.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong From 2f1b545456d591abaa92819a346dfa8fa1818e8c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 22:33:13 +0200 Subject: [PATCH 003/111] properly store the last filepicker path --- .../kotlin/com/simplemobiletools/gallery/helpers/Config.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index a76deb83c..131545dd1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -328,6 +328,6 @@ class Config(context: Context) : BaseConfig(context) { set(wasNewAppShown) = prefs.edit().putBoolean(WAS_NEW_APP_SHOWN, wasNewAppShown).apply() var lastFilepickerPath: String - get() = prefs.getString(TEMP_FOLDER_PATH, "") - set(tempFolderPath) = prefs.edit().putString(TEMP_FOLDER_PATH, tempFolderPath).apply() + get() = prefs.getString(LAST_FILEPICKER_PATH, "") + set(lastFilepickerPath) = prefs.edit().putString(LAST_FILEPICKER_PATH, lastFilepickerPath).apply() } From 26aa79294b747b864daed9f1405865132a19891d Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 22:54:53 +0200 Subject: [PATCH 004/111] remove sorting by date_taken while it doesnt work anyway --- .../gallery/dialogs/ChangeSortingDialog.kt | 8 +++----- .../simplemobiletools/gallery/helpers/Config.kt | 17 +++++++++++++++-- .../main/res/layout/dialog_change_sorting.xml | 8 -------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt index efbf4fe0e..5d4395988 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -29,8 +29,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti .setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.sort_by) - } + activity.setupDialogStuff(view, this, R.string.sort_by) + } currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(path) setupSortRadio() @@ -44,7 +44,6 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti currSorting and SORT_BY_PATH != 0 -> sortingRadio.sorting_dialog_radio_path currSorting and SORT_BY_SIZE != 0 -> sortingRadio.sorting_dialog_radio_size currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingRadio.sorting_dialog_radio_last_modified - currSorting and SORT_BY_DATE_TAKEN != 0 -> sortingRadio.sorting_dialog_radio_date_taken else -> sortingRadio.sorting_dialog_radio_name } sortBtn.isChecked = true @@ -66,8 +65,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti R.id.sorting_dialog_radio_name -> SORT_BY_NAME R.id.sorting_dialog_radio_path -> SORT_BY_PATH R.id.sorting_dialog_radio_size -> SORT_BY_SIZE - R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED - else -> SORT_BY_DATE_TAKEN + else -> SORT_BY_DATE_MODIFIED } if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 131545dd1..428c214b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -6,6 +6,7 @@ import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED +import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.commons.helpers.SORT_DESCENDING import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.models.AlbumCover @@ -17,7 +18,13 @@ class Config(context: Context) : BaseConfig(context) { } var directorySorting: Int - get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING) + get(): Int { + var sort = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING) + if (sort and SORT_BY_DATE_TAKEN != 0) { + sort = sort - SORT_BY_DATE_TAKEN + SORT_BY_DATE_MODIFIED + } + return sort + } set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply() fun saveFileSorting(path: String, value: Int) { @@ -28,7 +35,13 @@ class Config(context: Context) : BaseConfig(context) { } } - fun getFileSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path.toLowerCase(), sorting) + fun getFileSorting(path: String): Int { + var sort = prefs.getInt(SORT_FOLDER_PREFIX + path.toLowerCase(), sorting) + if (sort and SORT_BY_DATE_TAKEN != 0) { + sort = sort - SORT_BY_DATE_TAKEN + SORT_BY_DATE_MODIFIED + } + return sort + } fun removeFileSorting(path: String) { prefs.edit().remove(SORT_FOLDER_PREFIX + path.toLowerCase()).apply() diff --git a/app/src/main/res/layout/dialog_change_sorting.xml b/app/src/main/res/layout/dialog_change_sorting.xml index e0e642acc..812840f40 100644 --- a/app/src/main/res/layout/dialog_change_sorting.xml +++ b/app/src/main/res/layout/dialog_change_sorting.xml @@ -52,14 +52,6 @@ android:paddingTop="@dimen/medium_margin" android:text="@string/last_modified"/> - - Date: Sat, 14 Apr 2018 16:19:23 +0200 Subject: [PATCH 005/111] hide folders that contain .nomedia file themselves --- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 61e88604b..76dd0781f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -187,6 +187,8 @@ class MediaFetcher(val context: Context) { val file = File(path) return if (path.isEmpty()) { false + } else if (file.containsNoMedia()) { + false } else if (path.isThisOrParentIncluded(includedPaths)) { true } else if (path.isThisOrParentExcluded(excludedPaths)) { From a959e424838796bcdf8c44259436412d49da312a Mon Sep 17 00:00:00 2001 From: en2sv Date: Sat, 14 Apr 2018 20:19:02 +0200 Subject: [PATCH 006/111] Update Swedish translation --- app/src/main/res/values-sv/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b6cfae674..118ae9cae 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -3,9 +3,9 @@ Simple Gallery Galleri Redigera - Starta kameran + Öppna kameran (dold) - (excluded) + (utesluten) Fäst mapp Lossa mapp Fäst högst upp From c0c7752f797027b6418ba81d9a116af5eeef5c5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 21:31:31 +0200 Subject: [PATCH 007/111] try getting real filename from content uri at Edit Activity --- .../com/simplemobiletools/gallery/activities/EditActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 6f6338795..74e8662cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -188,6 +188,11 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } else if (saveUri.scheme == "content") { var newPath = applicationContext.getRealPathFromURI(saveUri) ?: "" var shouldAppendFilename = true + if (newPath.isEmpty()) { + newPath = applicationContext.getFilenameFromContentUri(saveUri) ?: "" + shouldAppendFilename = false + } + if (newPath.isEmpty()) { newPath = "$internalStoragePath/${getCurrentFormattedDateTime()}.${saveUri.toString().getFilenameExtension()}" shouldAppendFilename = false From 093fe92596fc54d5d33feeb4c3a090ffae44376e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 21:51:48 +0200 Subject: [PATCH 008/111] fix path fetching from content uri at editing --- .../simplemobiletools/gallery/activities/EditActivity.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 74e8662cb..fd9e8918f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -189,8 +189,11 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener var newPath = applicationContext.getRealPathFromURI(saveUri) ?: "" var shouldAppendFilename = true if (newPath.isEmpty()) { - newPath = applicationContext.getFilenameFromContentUri(saveUri) ?: "" - shouldAppendFilename = false + val filename = applicationContext.getFilenameFromContentUri(saveUri) ?: "" + if (filename.isNotEmpty()) { + newPath = "$internalStoragePath/$filename" + shouldAppendFilename = false + } } if (newPath.isEmpty()) { From c0d446a3a4506ddc48e96a6c54b6b97ae38e2aef Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 21:58:26 +0200 Subject: [PATCH 009/111] use better default file save path at Edit, if available --- .../com/simplemobiletools/gallery/activities/EditActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index fd9e8918f..96f3e20ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -191,7 +191,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (newPath.isEmpty()) { val filename = applicationContext.getFilenameFromContentUri(saveUri) ?: "" if (filename.isNotEmpty()) { - newPath = "$internalStoragePath/$filename" + val path = if (intent.extras?.containsKey(REAL_FILE_PATH) == true) intent.getStringExtra(REAL_FILE_PATH).getParentPath() else internalStoragePath + newPath = "$path/$filename" shouldAppendFilename = false } } From d8c17b8a80798964242a6729fa75dd385221b25f Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 22:10:12 +0200 Subject: [PATCH 010/111] do not unselect items at Edit intent --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b9b4cbddb..2794e9089 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.18.22' + implementation 'com.simplemobiletools:commons:3.18.25' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 5b8fbd420..819e24ab5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -158,7 +158,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun editFile() { activity.openEditor(getCurrentPath()) - finishActMode() } private fun toggleFileVisibility(hide: Boolean) { From 6db0adced81565bafaa76d335cdc27080efd4b2b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 22:11:33 +0200 Subject: [PATCH 011/111] catch exceptions thrown at saving image rotation --- .../gallery/activities/ViewPagerActivity.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index ab5e68d4a..bbb3c515b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -581,12 +581,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View @TargetApi(Build.VERSION_CODES.N) private fun tryRotateByExif(path: String): Boolean { - return if (saveImageRotation(path, mRotationDegrees)) { - mRotationDegrees = 0 - invalidateOptionsMenu() - toast(R.string.file_saved) - true - } else { + return try { + if (saveImageRotation(path, mRotationDegrees)) { + mRotationDegrees = 0 + invalidateOptionsMenu() + toast(R.string.file_saved) + true + } else { + false + } + } catch (e: Exception) { + showErrorToast(e) false } } From 3fdce65fe05454d25694f27e21958ebd7a78ecc8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 22:29:23 +0200 Subject: [PATCH 012/111] use file absolute path instead of name at file signature --- .../kotlin/com/simplemobiletools/gallery/extensions/String.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt index a2e6cbfc8..db7b0ec87 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt @@ -5,7 +5,7 @@ import java.io.File fun String.getFileSignature(): ObjectKey { val file = File(this) - return ObjectKey("${file.name}${file.lastModified()}") + return ObjectKey("${file.absolutePath}${file.lastModified()}") } fun String.isThisOrParentIncluded(includedPaths: MutableSet) = includedPaths.any { startsWith(it, true) } From 870b8c6837268a18951609ec5644b60c8c5ef7ad Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 23:02:01 +0200 Subject: [PATCH 013/111] sublist directories at background update --- .../gallery/receivers/RefreshMediaReceiver.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt index 589f98b45..e2c2731d5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -6,11 +6,13 @@ import android.content.Intent import com.google.gson.Gson import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT class RefreshMediaReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { GetDirectoriesAsynctask(context, false, false) { - context.config.directories = Gson().toJson(it) + val subList = it.subList(0, Math.min(SAVE_DIRS_CNT, it.size)) + context.config.directories = Gson().toJson(subList) }.execute() } } From 6503cb34a3c68753558bce6d3f5c93dcd2852450 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 23:06:20 +0200 Subject: [PATCH 014/111] update version to 3.7.2 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2794e9089..8a771ba66 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 171 - versionName "3.7.1" + versionCode 172 + versionName "3.7.2" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From 4e5b863d7cc886ff2839902c905cdde36f88426b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Apr 2018 23:06:25 +0200 Subject: [PATCH 015/111] updating changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11c107a5e..6b401e7c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========== +Version 3.7.1 *(2018-04-14)* +---------------------------- + + * Fix Edit intent handled by other apps + * Hide folders containing ".nomedia" file, even if explicitly included + * Remove sorting by Date Taken until proper implementation + Version 3.7.1 *(2018-04-12)* ---------------------------- From 8db3a5007a3e1371bf0389a227a5e619dfe69013 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 15 Apr 2018 08:47:07 +0200 Subject: [PATCH 016/111] fix #747, hide .nomedia folders only if Show Hidden is disabled --- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 76dd0781f..b4289d92f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -187,7 +187,7 @@ class MediaFetcher(val context: Context) { val file = File(path) return if (path.isEmpty()) { false - } else if (file.containsNoMedia()) { + } else if (!showHidden && file.containsNoMedia()) { false } else if (path.isThisOrParentIncluded(includedPaths)) { true From 99b39d0559cf79693117680f5dec351bbff2e4c4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 15 Apr 2018 08:48:09 +0200 Subject: [PATCH 017/111] update version to 3.7.3 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8a771ba66..192d8c574 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 172 - versionName "3.7.2" + versionCode 173 + versionName "3.7.3" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From f5a8da8f621df71b0ced6ef7f873b933567ff099 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 15 Apr 2018 08:48:25 +0200 Subject: [PATCH 018/111] updating changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b401e7c2..1babfb9c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ Changelog ========== -Version 3.7.1 *(2018-04-14)* +Version 3.7.3 *(2018-04-15)* +---------------------------- + + * Show hidden folders when appropriate + +Version 3.7.2 *(2018-04-14)* ---------------------------- * Fix Edit intent handled by other apps From c8c00fbfbe56ec43ad6f6bc9483edafabcfd9944 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 16 Apr 2018 09:32:24 +0200 Subject: [PATCH 019/111] move the LT strings in proper folder --- app/src/main/res/{values-lt => values-lt/strings.xml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename app/src/main/res/{values-lt => values-lt/strings.xml} (98%) diff --git a/app/src/main/res/values-lt b/app/src/main/res/values-lt/strings.xml similarity index 98% rename from app/src/main/res/values-lt rename to app/src/main/res/values-lt/strings.xml index 64542d1b7..aa9a2c9f4 100644 --- a/app/src/main/res/values-lt +++ b/app/src/main/res/values-lt/strings.xml @@ -34,7 +34,7 @@ Pakeisti filtrus - Ši funkcija slepia aplanką, pridedant į jį \ '. Nomedia \' bylą, jis taip pat slėps visus subaplankus. Galite juos peržiūrėti, perjunkite parinktį "Rodyti paslėptus elementus \" skiltyje Nustatymai. Tęsti? + Ši funkcija slepia aplanką, pridedant į jį \'. Nomedia \' bylą, jis taip pat slėps visus subaplankus. Galite juos peržiūrėti, perjunkite parinktį "Rodyti paslėptus elementus \" skiltyje Nustatymai. Tęsti? Išskirti Išskirti aplankai Tvarkyti išskirtus aplankus @@ -45,7 +45,7 @@ Pašalinti visus aplankus iš išskirtųjų sąrašo? Tai neištrins aplankų. Paslėpti aplankai Tvarkyti paslėptus aplankus - Atrodo, kad neturite jokių aplankų, paslėptų \ ". Nomedia \" bylos. + Atrodo, kad neturite jokių aplankų, paslėptų \". Nomedia \" bylos. Įtraukti aplankai From 508a97ad2bc01c1c45f7fd35c68bad986872414f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Marques?= Date: Mon, 16 Apr 2018 21:19:23 +0000 Subject: [PATCH 020/111] Update strings.xml --- app/src/main/res/values-pt/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index fe8f22d90..de1924bed 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -5,7 +5,7 @@ Editar Abrir câmara (oculta) - (excluded) + (excluída) Fixar pasta Desafixar pasta Fixar no topo From 28bdb3efb8d43f4b31d4d70151b7239be1412c0d Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 18 Apr 2018 22:15:18 +0200 Subject: [PATCH 021/111] update image cropper to 2.7.0 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 192d8c574..732eee71c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { dependencies { implementation 'com.simplemobiletools:commons:3.18.25' - implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' + implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' From d0ba3314ad6aa3662526f4bfe654823fef7da7e0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Apr 2018 13:49:27 +0200 Subject: [PATCH 022/111] update commons to 3.19.4 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 732eee71c..a4999534a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.18.25' + implementation 'com.simplemobiletools:commons:3.19.4' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' From 30ce207b1f7551eb1024877315294afe6b65bd3b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Apr 2018 23:35:18 +0200 Subject: [PATCH 023/111] lets use Room for caching directories --- app/build.gradle | 5 +++ .../gallery/activities/MainActivity.kt | 12 +++++-- .../asynctasks/GetDirectoriesAsynctask.kt | 9 ++++-- .../gallery/databases/DirectoryDataBase.kt | 31 +++++++++++++++++++ .../gallery/extensions/Activity.kt | 2 +- .../gallery/interfaces/DirectoryDao.kt | 16 ++++++++++ .../gallery/models/Directory.kt | 20 ++++++++++-- .../gallery/models/Medium.kt | 5 +-- 8 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt diff --git a/app/build.gradle b/app/build.gradle index a4999534a..a2345d9be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' android { compileSdkVersion 27 @@ -53,6 +54,10 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' implementation 'com.github.chrisbanes:PhotoView:2.1.3' + kapt "android.arch.persistence.room:compiler:1.0.0" + implementation "android.arch.persistence.room:runtime:1.0.0" + annotationProcessor "android.arch.persistence.room:compiler:1.0.0" + //implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0' implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.0-fork' 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 677b1caab..e685bac9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -29,6 +29,7 @@ import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask +import com.simplemobiletools.gallery.databases.DirectoryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* @@ -62,6 +63,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null + private var mDirsDB: DirectoryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -89,6 +91,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { removeTempFolder() directories_refresh_layout.setOnRefreshListener { getDirectories() } mDirs = ArrayList() + mDirsDB = DirectoryDataBase.getInstance(applicationContext) storeStateVariables() checkWhatsNewDialog() @@ -551,11 +554,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun gotDirectories(newDirs: ArrayList, isFromCache: Boolean) { - /*if (!isFromCache) { + if (!isFromCache) { Thread { - checkFolderContentChange(newDirs) + //checkFolderContentChange(newDirs) + newDirs.forEach { + mDirsDB!!.DirectoryDao().insert(it) + } }.start() - }*/ + } val dirs = getSortedDirectories(newDirs) directories_refresh_layout.isRefreshing = false diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 19f73ddde..3f19087c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -38,7 +38,12 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val firstItem = curMedia.first() val lastItem = curMedia.last() - val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) firstItem.path.getParentPath() else File(firstItem.path).parent ?: continue + val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { + firstItem.path.getParentPath() + } else { + File(firstItem.path).parent + } ?: continue + var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: "" if (thumbnail.startsWith(OTG_PATH)) { thumbnail = thumbnail.getOTGPublicPath(context) @@ -54,7 +59,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) val size = curMedia.sumByLong { it.size } - val directory = Directory(parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir)) + val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir)) directories.add(directory) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt new file mode 100644 index 000000000..102329dec --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt @@ -0,0 +1,31 @@ +package com.simplemobiletools.gallery.databases + +import android.arch.persistence.room.Database +import android.arch.persistence.room.Room +import android.arch.persistence.room.RoomDatabase +import android.content.Context +import com.simplemobiletools.gallery.interfaces.DirectoryDao +import com.simplemobiletools.gallery.models.Directory + +@Database(entities = [(Directory::class)], version = 1) +abstract class DirectoryDataBase : RoomDatabase() { + + abstract fun DirectoryDao(): DirectoryDao + + companion object { + private var INSTANCE: DirectoryDataBase? = null + + fun getInstance(context: Context): DirectoryDataBase { + if (INSTANCE == null) { + synchronized(DirectoryDataBase::class) { + INSTANCE = Room.databaseBuilder(context.applicationContext, DirectoryDataBase::class.java, "directories.db").build() + } + } + return INSTANCE!! + } + + fun destroyInstance() { + INSTANCE = null + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index f7073185f..d887a097d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -211,7 +211,7 @@ fun BaseSimpleActivity.addTempFolderIfNeeded(dirs: ArrayList): ArrayL val directories = ArrayList() val tempFolderPath = config.tempFolderPath if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath)) + val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath)) directories.add(newFolder) } directories.addAll(dirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt new file mode 100644 index 000000000..2761c1f66 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -0,0 +1,16 @@ +package com.simplemobiletools.gallery.interfaces + +import android.arch.persistence.room.Dao +import android.arch.persistence.room.Insert +import android.arch.persistence.room.OnConflictStrategy.REPLACE +import android.arch.persistence.room.Query +import com.simplemobiletools.gallery.models.Directory + +@Dao +interface DirectoryDao { + @Query("SELECT * from directories") + fun getAll(): List + + @Insert(onConflict = REPLACE) + fun insert(directory: Directory) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 3bb84637e..02b18d8d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -1,14 +1,28 @@ package com.simplemobiletools.gallery.models +import android.arch.persistence.room.ColumnInfo +import android.arch.persistence.room.Entity +import android.arch.persistence.room.Index +import android.arch.persistence.room.PrimaryKey import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.helpers.* import java.io.Serializable -data class Directory(var path: String, var tmb: String, var name: String, var mediaCnt: Int, val modified: Long, val taken: Long, - val size: Long, val isOnSDCard: Boolean) : Serializable, Comparable { +@Entity(tableName = "directories", indices = [Index(value = "path", unique = true)]) +data class Directory( + @PrimaryKey(autoGenerate = true) var id: Long?, + @ColumnInfo(name = "path") var path: String, + @ColumnInfo(name = "thumbnail") var tmb: String, + @ColumnInfo(name = "filename") var name: String, + @ColumnInfo(name = "media_count") var mediaCnt: Int, + @ColumnInfo(name = "last_modified") val modified: Long, + @ColumnInfo(name = "date_taken") val taken: Long, + @ColumnInfo(name = "size") val size: Long, + @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean) : Serializable, Comparable { + companion object { - private val serialVersionUID = -6553345863555455L + private const val serialVersionUID = -6553345863555455L var sorting: Int = 0 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index f00aedda9..9f3efc09a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.models import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize -import com.simplemobiletools.commons.extensions.getMimeType import com.simplemobiletools.commons.extensions.isDng import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.helpers.TYPE_GIF @@ -12,7 +11,7 @@ import java.io.Serializable data class Medium(var name: String, var path: String, val modified: Long, val taken: Long, val size: Long, val type: Int) : Serializable, Comparable { companion object { - private val serialVersionUID = -6553149366975455L + private const val serialVersionUID = -6553149366975455L var sorting: Int = 0 } @@ -24,8 +23,6 @@ data class Medium(var name: String, var path: String, val modified: Long, val ta fun isDng() = path.isDng() - fun getMimeType() = path.getMimeType() - override fun compareTo(other: Medium): Int { var result: Int when { From ce4ee915bb6dfbd8712a561f426d59c1fabc25ba Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 11:01:01 +0200 Subject: [PATCH 024/111] store media in a room db too --- .../gallery/activities/MainActivity.kt | 10 ++++------ .../gallery/activities/MediaActivity.kt | 10 +++++++++- .../gallery/activities/PhotoVideoActivity.kt | 2 +- ...irectoryDataBase.kt => GalleryDataBase.kt} | 18 +++++++++++------- .../gallery/helpers/MediaFetcher.kt | 4 ++-- .../gallery/interfaces/DirectoryDao.kt | 3 +++ .../gallery/interfaces/MediumDao.kt | 19 +++++++++++++++++++ .../gallery/models/Medium.kt | 15 ++++++++++++++- 8 files changed, 63 insertions(+), 18 deletions(-) rename app/src/main/kotlin/com/simplemobiletools/gallery/databases/{DirectoryDataBase.kt => GalleryDataBase.kt} (56%) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt 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 e685bac9b..8137f0ba5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -29,7 +29,7 @@ import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.databases.DirectoryDataBase +import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* @@ -63,7 +63,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null - private var mDirsDB: DirectoryDataBase? = null + private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -91,7 +91,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { removeTempFolder() directories_refresh_layout.setOnRefreshListener { getDirectories() } mDirs = ArrayList() - mDirsDB = DirectoryDataBase.getInstance(applicationContext) + mGalleryDB = GalleryDataBase.getInstance(applicationContext) storeStateVariables() checkWhatsNewDialog() @@ -557,9 +557,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!isFromCache) { Thread { //checkFolderContentChange(newDirs) - newDirs.forEach { - mDirsDB!!.DirectoryDao().insert(it) - } + mGalleryDB!!.DirectoryDao().insertAll(newDirs) }.start() } 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 cb26c7c38..507644f84 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -33,6 +33,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog @@ -62,6 +63,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mCurrAsyncTask: GetMediaAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null + private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -94,8 +96,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } storeStateVariables() - if (mShowAll) + mGalleryDB = GalleryDataBase.getInstance(applicationContext) + + if (mShowAll) { supportActionBar?.setDisplayHomeAsUpEnabled(false) + } media_empty_text.setOnClickListener { showFilterMediaDialog() @@ -623,6 +628,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { Thread { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() + if (!isFromCache) { + mGalleryDB!!.MediumDao().insertAll(media) + } }.start() mIsGettingMedia = false diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index f3c4084bd..dd68c39c2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -90,7 +90,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList else -> TYPE_GIF } - mMedium = Medium(getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type) + mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type) supportActionBar?.title = mMedium!!.name bundle.putSerializable(MEDIUM, mMedium) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDataBase.kt similarity index 56% rename from app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt rename to app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDataBase.kt index 102329dec..a011337e2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/DirectoryDataBase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDataBase.kt @@ -5,20 +5,24 @@ import android.arch.persistence.room.Room import android.arch.persistence.room.RoomDatabase import android.content.Context import com.simplemobiletools.gallery.interfaces.DirectoryDao +import com.simplemobiletools.gallery.interfaces.MediumDao import com.simplemobiletools.gallery.models.Directory +import com.simplemobiletools.gallery.models.Medium -@Database(entities = [(Directory::class)], version = 1) -abstract class DirectoryDataBase : RoomDatabase() { +@Database(entities = [(Directory::class), (Medium::class)], version = 1) +abstract class GalleryDataBase : RoomDatabase() { abstract fun DirectoryDao(): DirectoryDao - companion object { - private var INSTANCE: DirectoryDataBase? = null + abstract fun MediumDao(): MediumDao - fun getInstance(context: Context): DirectoryDataBase { + companion object { + private var INSTANCE: GalleryDataBase? = null + + fun getInstance(context: Context): GalleryDataBase { if (INSTANCE == null) { - synchronized(DirectoryDataBase::class) { - INSTANCE = Room.databaseBuilder(context.applicationContext, DirectoryDataBase::class.java, "directories.db").build() + synchronized(GalleryDataBase::class) { + INSTANCE = Room.databaseBuilder(context.applicationContext, GalleryDataBase::class.java, "gallery.db").build() } } return INSTANCE!! diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index b4289d92f..495c359f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -247,7 +247,7 @@ class MediaFetcher(val context: Context) { else -> TYPE_GIF } - val medium = Medium(filename, file.absolutePath, dateModified, dateTaken, size, type) + val medium = Medium(null, filename, file.absolutePath, dateModified, dateTaken, size, type) curMedia.add(medium) } } @@ -296,7 +296,7 @@ class MediaFetcher(val context: Context) { } val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) - val medium = Medium(filename, path, dateModified, dateTaken, size, type) + val medium = Medium(null, filename, path, dateModified, dateTaken, size, type) curMedia.add(medium) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 2761c1f66..fbec9b6fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -13,4 +13,7 @@ interface DirectoryDao { @Insert(onConflict = REPLACE) fun insert(directory: Directory) + + @Insert(onConflict = REPLACE) + fun insertAll(directories: List) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt new file mode 100644 index 000000000..d2ccd3aee --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -0,0 +1,19 @@ +package com.simplemobiletools.gallery.interfaces + +import android.arch.persistence.room.Dao +import android.arch.persistence.room.Insert +import android.arch.persistence.room.OnConflictStrategy.REPLACE +import android.arch.persistence.room.Query +import com.simplemobiletools.gallery.models.Medium + +@Dao +interface MediumDao { + @Query("SELECT * from media") + fun getAll(): List + + @Insert(onConflict = REPLACE) + fun insert(medium: Medium) + + @Insert(onConflict = REPLACE) + fun insertAll(media: List) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 9f3efc09a..6fc3c5818 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -1,5 +1,9 @@ package com.simplemobiletools.gallery.models +import android.arch.persistence.room.ColumnInfo +import android.arch.persistence.room.Entity +import android.arch.persistence.room.Index +import android.arch.persistence.room.PrimaryKey import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.extensions.isDng @@ -9,7 +13,16 @@ import com.simplemobiletools.gallery.helpers.TYPE_IMAGE import com.simplemobiletools.gallery.helpers.TYPE_VIDEO import java.io.Serializable -data class Medium(var name: String, var path: String, val modified: Long, val taken: Long, val size: Long, val type: Int) : Serializable, Comparable { +@Entity(tableName = "media", indices = [(Index(value = "path", unique = true))]) +data class Medium( + @PrimaryKey(autoGenerate = true) var id: Long?, + @ColumnInfo(name = "filename") var name: String, + @ColumnInfo(name = "path") var path: String, + @ColumnInfo(name = "last_modified") val modified: Long, + @ColumnInfo(name = "date_taken") val taken: Long, + @ColumnInfo(name = "size") val size: Long, + @ColumnInfo(name = "type") val type: Int) : Serializable, Comparable { + companion object { private const val serialVersionUID = -6553149366975455L var sorting: Int = 0 From 73000aa6118e507e6bc9b09ce8164da52a651d56 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 11:46:50 +0200 Subject: [PATCH 025/111] store media parent paths too --- app/build.gradle | 2 +- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 2 +- .../simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 2 +- .../com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt | 2 +- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 8 ++++---- .../simplemobiletools/gallery/interfaces/DirectoryDao.kt | 2 +- .../com/simplemobiletools/gallery/interfaces/MediumDao.kt | 5 ++++- .../kotlin/com/simplemobiletools/gallery/models/Medium.kt | 5 +++-- 10 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a2345d9be..4e75f2a77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.4' + implementation 'com.simplemobiletools:commons:3.19.5' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index dd68c39c2..0e16febe8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -90,7 +90,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList else -> TYPE_GIF } - mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type) + mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type) supportActionBar?.title = mMedium!!.name bundle.putSerializable(MEDIUM, mMedium) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index bbb3c515b..a262ade53 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -197,7 +197,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View showSystemUI() - mDirectory = mPath.getParentPath().trimEnd('/') + mDirectory = mPath.getParentPath() if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { mDirectory += "/" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 819e24ab5..6485ca21e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -250,7 +250,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun updateStoredFolderItems() { Thread { if (media.isNotEmpty()) { - activity.applicationContext.storeFolderItems(media.first().path.getParentPath().trimEnd('/'), media as ArrayList) + activity.applicationContext.storeFolderItems(media.first().parentPath, media as ArrayList) } }.start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 3f19087c0..55b127375 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -39,7 +39,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val firstItem = curMedia.first() val lastItem = curMedia.last() val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { - firstItem.path.getParentPath() + firstItem.parentPath } else { File(firstItem.path).parent } ?: continue diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt index 821706d9b..9fbd49fde 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -12,7 +12,7 @@ import java.io.File class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) { init { - var realPath = path.getParentPath().trimEnd('/') + var realPath = path.getParentPath() val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply { save_as_path.text = activity.humanizePath(realPath) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 495c359f6..8c5847192 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -172,8 +172,7 @@ class MediaFetcher(val context: Context) { break } - val parentDir = (if (hasOTG && medium.path.startsWith(OTG_PATH)) medium.path.getParentPath().toLowerCase() else File(medium.path).parent?.toLowerCase()) - ?: continue + val parentDir = medium.parentPath.toLowerCase() if (directories.containsKey(parentDir)) { directories[parentDir]!!.add(medium) } else { @@ -247,7 +246,8 @@ class MediaFetcher(val context: Context) { else -> TYPE_GIF } - val medium = Medium(null, filename, file.absolutePath, dateModified, dateTaken, size, type) + val parentPath = file.absolutePath.removeSuffix("/") + val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type) curMedia.add(medium) } } @@ -296,7 +296,7 @@ class MediaFetcher(val context: Context) { } val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) - val medium = Medium(null, filename, path, dateModified, dateTaken, size, type) + val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type) curMedia.add(medium) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index fbec9b6fb..3a242dd77 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.gallery.models.Directory @Dao interface DirectoryDao { - @Query("SELECT * from directories") + @Query("SELECT * FROM directories") fun getAll(): List @Insert(onConflict = REPLACE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index d2ccd3aee..c27a14dda 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -8,9 +8,12 @@ import com.simplemobiletools.gallery.models.Medium @Dao interface MediumDao { - @Query("SELECT * from media") + @Query("SELECT * FROM media") fun getAll(): List + @Query("SELECT * FROM media WHERE parent_path = :path") + fun getMediaFromPath(path: String): List + @Insert(onConflict = REPLACE) fun insert(medium: Medium) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 6fc3c5818..5dbfefcc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -13,11 +13,12 @@ import com.simplemobiletools.gallery.helpers.TYPE_IMAGE import com.simplemobiletools.gallery.helpers.TYPE_VIDEO import java.io.Serializable -@Entity(tableName = "media", indices = [(Index(value = "path", unique = true))]) +@Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) data class Medium( @PrimaryKey(autoGenerate = true) var id: Long?, @ColumnInfo(name = "filename") var name: String, - @ColumnInfo(name = "path") var path: String, + @ColumnInfo(name = "full_path") var path: String, + @ColumnInfo(name = "parent_path") var parentPath: String, @ColumnInfo(name = "last_modified") val modified: Long, @ColumnInfo(name = "date_taken") val taken: Long, @ColumnInfo(name = "size") val size: Long, From b0afe92afbad887a16920714573f850e2d05e9e8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 11:52:26 +0200 Subject: [PATCH 026/111] move the gallery database fetcher in a context extension --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +---- .../simplemobiletools/gallery/activities/MediaActivity.kt | 5 +---- .../com/simplemobiletools/gallery/extensions/Context.kt | 3 +++ 3 files changed, 5 insertions(+), 8 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 8137f0ba5..c56c0ebae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -29,7 +29,6 @@ import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* @@ -63,7 +62,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null - private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -91,7 +89,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { removeTempFolder() directories_refresh_layout.setOnRefreshListener { getDirectories() } mDirs = ArrayList() - mGalleryDB = GalleryDataBase.getInstance(applicationContext) storeStateVariables() checkWhatsNewDialog() @@ -557,7 +554,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!isFromCache) { Thread { //checkFolderContentChange(newDirs) - mGalleryDB!!.DirectoryDao().insertAll(newDirs) + galleryDB.DirectoryDao().insertAll(newDirs) }.start() } 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 507644f84..547cf7d37 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -33,7 +33,6 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask -import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog @@ -63,7 +62,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mCurrAsyncTask: GetMediaAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null - private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -96,7 +94,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } storeStateVariables() - mGalleryDB = GalleryDataBase.getInstance(applicationContext) if (mShowAll) { supportActionBar?.setDisplayHomeAsUpEnabled(false) @@ -629,7 +626,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - mGalleryDB!!.MediumDao().insertAll(media) + galleryDB.MediumDao().insertAll(media) } }.start() 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 66a7fbde5..33c0cf0d5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT @@ -65,6 +66,8 @@ fun Context.launchSettings() { val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.galleryDB: GalleryDataBase get() = GalleryDataBase.getInstance(applicationContext) + fun Context.movePinnedDirectoriesToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() val pinnedFolders = config.pinnedFolders From 236ceafe465b85db2657ba672292950c115ed1ca Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 11:55:51 +0200 Subject: [PATCH 027/111] removing the install receiver used to fetch media right after installing --- app/src/main/AndroidManifest.xml | 8 -------- .../gallery/receivers/InstallReceiver.kt | 16 ---------------- 2 files changed, 24 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b4915161f..09a160080 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -205,14 +205,6 @@ android:resource="@xml/provider_paths"/> - - - - - - diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt deleted file mode 100644 index fc3566bc0..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.simplemobiletools.gallery.receivers - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import com.google.gson.Gson -import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.extensions.config - -class InstallReceiver : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - GetDirectoriesAsynctask(context, false, false) { - context.config.directories = Gson().toJson(it) - }.execute() - } -} From 5b8143d41e3a30731970410c08543aa6419cb5bb Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 12:35:40 +0200 Subject: [PATCH 028/111] replace the Shared Prefs way of storing directories by Room --- .../gallery/activities/MainActivity.kt | 9 ++++++--- .../gallery/dialogs/PickDirectoryDialog.kt | 11 ++++++----- .../simplemobiletools/gallery/extensions/Activity.kt | 7 ++++--- .../simplemobiletools/gallery/extensions/Context.kt | 6 +++--- .../com/simplemobiletools/gallery/helpers/Config.kt | 4 ---- .../simplemobiletools/gallery/helpers/Constants.kt | 2 -- .../gallery/receivers/RefreshMediaReceiver.kt | 7 ++----- 7 files changed, 21 insertions(+), 25 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 c56c0ebae..1954b593d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -274,9 +274,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } mIsGettingDirs = true - val dirs = getCachedDirectories() - if (dirs.isNotEmpty() && !mLoadedInitialPhotos) { - gotDirectories(dirs, true) + if (!mLoadedInitialPhotos) { + getCachedDirectories { + if (it.isNotEmpty()) { + gotDirectories(it, true) + } + } } if (!mLoadedInitialPhotos) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index 471237111..e31b4b260 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -37,12 +37,13 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() }) .create().apply { - activity.setupDialogStuff(view, this, R.string.select_destination) - } + activity.setupDialogStuff(view, this, R.string.select_destination) + } - val dirs = activity.getCachedDirectories() - if (dirs.isNotEmpty()) { - gotDirectories(activity.addTempFolderIfNeeded(dirs)) + activity.getCachedDirectories { + if (it.isNotEmpty()) { + gotDirectories(activity.addTempFolderIfNeeded(it)) + } } GetDirectoriesAsynctask(activity, false, false) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index d887a097d..78d66eb98 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -244,9 +244,10 @@ fun Activity.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Bo builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target) } -fun Activity.getCachedDirectories(): ArrayList { - val token = object : TypeToken>() {}.type - return Gson().fromJson>(config.directories, token) ?: ArrayList(1) +fun Activity.getCachedDirectories(callback: (ArrayList) -> Unit) { + Thread { + callback(galleryDB.DirectoryDao().getAll() as ArrayList) + }.start() } fun Activity.getCachedMedia(path: String): ArrayList { 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 33c0cf0d5..75b6536bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -19,7 +19,6 @@ import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT import com.simplemobiletools.gallery.helpers.SAVE_MEDIA_CNT import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium @@ -163,8 +162,9 @@ fun Context.updateStoredDirectories() { } fun Context.storeDirectoryItems(items: ArrayList) { - val subList = items.subList(0, Math.min(SAVE_DIRS_CNT, items.size)) - config.directories = Gson().toJson(subList) + Thread { + galleryDB.DirectoryDao().insertAll(items) + }.start() } fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet): String { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 428c214b7..209ff4f6c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -239,10 +239,6 @@ class Config(context: Context) : BaseConfig(context) { private fun getDefaultMediaColumnCount() = context.resources.getInteger(if (scrollHorizontally) R.integer.media_columns_horizontal_scroll else R.integer.media_columns_vertical_scroll) - var directories: String - get() = prefs.getString(DIRECTORIES, "") - set(directories) = prefs.edit().putString(DIRECTORIES, directories).apply() - var albumCovers: String get() = prefs.getString(ALBUM_COVERS, "") set(albumCovers) = prefs.edit().putString(ALBUM_COVERS, albumCovers).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index c0431b69c..37cf9c4c1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -67,7 +67,6 @@ const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 600000L const val CLICK_MAX_DURATION = 150 const val DRAG_THRESHOLD = 8 -const val SAVE_DIRS_CNT = 60 const val SAVE_MEDIA_CNT = 80 const val DIRECTORY = "directory" @@ -77,7 +76,6 @@ const val GET_IMAGE_INTENT = "get_image_intent" const val GET_VIDEO_INTENT = "get_video_intent" const val GET_ANY_INTENT = "get_any_intent" const val SET_WALLPAPER_INTENT = "set_wallpaper_intent" -const val DIRECTORIES = "directories2" const val IS_VIEW_INTENT = "is_view_intent" const val PICKED_PATHS = "picked_paths" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt index e2c2731d5..7163a5af5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -3,16 +3,13 @@ package com.simplemobiletools.gallery.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import com.google.gson.Gson import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT +import com.simplemobiletools.gallery.extensions.storeDirectoryItems class RefreshMediaReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { GetDirectoriesAsynctask(context, false, false) { - val subList = it.subList(0, Math.min(SAVE_DIRS_CNT, it.size)) - context.config.directories = Gson().toJson(subList) + context.storeDirectoryItems(it) }.execute() } } From 73ac82266165819a14c1ad315e7f48c02da93913 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 13:20:44 +0200 Subject: [PATCH 029/111] handle deleting folders from local db --- .../simplemobiletools/gallery/activities/MainActivity.kt | 5 +++++ .../com/simplemobiletools/gallery/extensions/Activity.kt | 8 +++++++- .../simplemobiletools/gallery/interfaces/DirectoryDao.kt | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) 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 1954b593d..c017e10f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -362,6 +362,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { runOnUiThread { refreshItems() } + Thread { + folders.filter { !it.exists() }.forEach { + galleryDB.DirectoryDao().deleteDirPath(it.absolutePath) + } + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index 78d66eb98..bdcb171c2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -246,7 +246,13 @@ fun Activity.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Bo fun Activity.getCachedDirectories(callback: (ArrayList) -> Unit) { Thread { - callback(galleryDB.DirectoryDao().getAll() as ArrayList) + val directoryDao = galleryDB.DirectoryDao() + val directories = directoryDao.getAll() as ArrayList + callback(directories) + + directories.filter { !File(it.path).exists() }.forEach { + directoryDao.deleteDir(it) + } }.start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 3a242dd77..ed84a1319 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.interfaces import android.arch.persistence.room.Dao +import android.arch.persistence.room.Delete import android.arch.persistence.room.Insert import android.arch.persistence.room.OnConflictStrategy.REPLACE import android.arch.persistence.room.Query @@ -16,4 +17,10 @@ interface DirectoryDao { @Insert(onConflict = REPLACE) fun insertAll(directories: List) + + @Delete + fun deleteDir(directory: Directory) + + @Query("DELETE FROM directories WHERE path = :path") + fun deleteDirPath(path: String) } From d28b95290fb43fc6c650321f10d764b3b3d2b730 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 14:54:34 +0200 Subject: [PATCH 030/111] remove the functions related to old checking if folder content changed --- .../gallery/activities/MainActivity.kt | 12 ------------ .../com/simplemobiletools/gallery/helpers/Config.kt | 6 ------ .../simplemobiletools/gallery/helpers/Constants.kt | 1 - 3 files changed, 19 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 c017e10f3..8780134b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -590,18 +590,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - private fun checkFolderContentChange(newDirs: ArrayList) { - newDirs.forEach { - val storedShortDirValue = config.loadFolderMediaShort(it.path) - if (storedShortDirValue != it.toString()) { - config.saveFolderMediaShort(it.path, it.toString()) - if (storedShortDirValue.isNotEmpty()) { - updateStoredFolderItems(it.path) - } - } - } - } - private fun storeDirectories() { if (!config.temporarilyShowHidden && config.tempFolderPath.isEmpty()) { storeDirectoryItems(mDirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 209ff4f6c..edb79a028 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -137,12 +137,6 @@ class Config(context: Context) : BaseConfig(context) { fun loadFolderMedia(path: String) = prefs.getString(SAVE_FOLDER_PREFIX + path, "") - fun saveFolderMediaShort(path: String, value: String) { - prefs.edit().putString(SAVE_FOLDER_SHORT_PREFIX + path, value).apply() - } - - fun loadFolderMediaShort(path: String) = prefs.getString(SAVE_FOLDER_SHORT_PREFIX + path, "") - var autoplayVideos: Boolean get() = prefs.getBoolean(AUTOPLAY_VIDEOS, false) set(autoplay) = prefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 37cf9c4c1..5dcbc4305 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -26,7 +26,6 @@ const val MEDIA_HORIZONTAL_COLUMN_CNT = "media_horizontal_column_cnt" const val MEDIA_LANDSCAPE_HORIZONTAL_COLUMN_CNT = "media_landscape_horizontal_column_cnt" const val SHOW_ALL = "show_all" // display images and videos from all folders together const val SAVE_FOLDER_PREFIX = "folder2_" -const val SAVE_FOLDER_SHORT_PREFIX = "folder_short_" const val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown" const val EXCLUDED_FOLDERS = "excluded_folders" const val INCLUDED_FOLDERS = "included_folders" From 244e29b4377df01b5d8adbf4cdeb2615a793a850 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 14:55:14 +0200 Subject: [PATCH 031/111] remove the commented out function too --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 1 - 1 file changed, 1 deletion(-) 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 8780134b3..61a3e64fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -561,7 +561,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun gotDirectories(newDirs: ArrayList, isFromCache: Boolean) { if (!isFromCache) { Thread { - //checkFolderContentChange(newDirs) galleryDB.DirectoryDao().insertAll(newDirs) }.start() } From c17b58dc530e9915fa397d4e3d66da27acef3d17 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 15:34:17 +0200 Subject: [PATCH 032/111] rely on Room db data at caching items --- .../gallery/activities/MainActivity.kt | 7 ++--- .../gallery/activities/MediaActivity.kt | 31 +++++++++++-------- .../gallery/dialogs/PickMediumDialog.kt | 12 ++++--- .../gallery/extensions/Activity.kt | 11 ++++--- 4 files changed, 34 insertions(+), 27 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 61a3e64fb..fbe985495 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -573,14 +573,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache) directories_grid.beVisibleIf(directories_empty_text_label.isGone()) - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID - directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) - directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) - checkLastMediaChanged() mDirs = dirs runOnUiThread { + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) + directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) 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 547cf7d37..6bfaecad5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -454,9 +454,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } mIsGettingMedia = true - val media = getCachedMedia(mPath) - if (media.isNotEmpty() && !mLoadedInitialPhotos) { - gotMedia(media, true) + if (!mLoadedInitialPhotos) { + getCachedMedia(mPath) { + if (it.isEmpty()) { + media_refresh_layout.isRefreshing = true + } else { + gotMedia(it, true) + } + } } else { media_refresh_layout.isRefreshing = true } @@ -631,20 +636,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { }.start() mIsGettingMedia = false - media_refresh_layout.isRefreshing = false - - media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache) - media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache) - media_grid.beVisibleIf(media_empty_text_label.isGone()) - - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID - media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) - media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) checkLastMediaChanged() - mMedia = media + runOnUiThread { + media_refresh_layout.isRefreshing = false + media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache) + media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache) + media_grid.beVisibleIf(media_empty_text_label.isGone()) + + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) + media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) + setupAdapter() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index fd5abf97b..88845a539 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -33,12 +33,14 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() }) .create().apply { - activity.setupDialogStuff(view, this, R.string.select_photo) - } + activity.setupDialogStuff(view, this, R.string.select_photo) + } - val media = activity.getCachedMedia(path).filter { !it.isVideo() } as ArrayList - if (media.isNotEmpty()) { - gotMedia(media) + activity.getCachedMedia(path) { + val media = it.filter { !it.isVideo() } as ArrayList + if (media.isNotEmpty()) { + gotMedia(media) + } } GetMediaAsynctask(activity, path, false, true, false) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index bdcb171c2..172fc25e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -11,8 +11,6 @@ import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -256,7 +254,10 @@ fun Activity.getCachedDirectories(callback: (ArrayList) -> Unit) { }.start() } -fun Activity.getCachedMedia(path: String): ArrayList { - val token = object : TypeToken>() {}.type - return Gson().fromJson>(config.loadFolderMedia(path), token) ?: ArrayList(1) +fun Activity.getCachedMedia(path: String, callback: (ArrayList) -> Unit) { + Thread { + val mediumDao = galleryDB.MediumDao() + val media = mediumDao.getMediaFromPath(path) as ArrayList + callback(media) + }.start() } From 1a5ec41f8b20482af1151b5c618e1dea60aeb857 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 21:01:55 +0200 Subject: [PATCH 033/111] do not select ID at directories and media, for proper old/new comparing --- .../com/simplemobiletools/gallery/interfaces/DirectoryDao.kt | 2 +- .../com/simplemobiletools/gallery/interfaces/MediumDao.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index ed84a1319..6b6d0580b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory @Dao interface DirectoryDao { - @Query("SELECT * FROM directories") + @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card FROM directories") fun getAll(): List @Insert(onConflict = REPLACE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index c27a14dda..51d8d3b77 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -11,7 +11,7 @@ interface MediumDao { @Query("SELECT * FROM media") fun getAll(): List - @Query("SELECT * FROM media WHERE parent_path = :path") + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type FROM media WHERE parent_path = :path") fun getMediaFromPath(path: String): List @Insert(onConflict = REPLACE) From ee07da62774ce25ca749701a061c03078a846eec Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 21:11:12 +0200 Subject: [PATCH 034/111] move some extension functions from Activity to Context --- .../gallery/extensions/Activity.kt | 96 ------------------- .../gallery/extensions/Context.kt | 96 ++++++++++++++++++- 2 files changed, 93 insertions(+), 99 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index 172fc25e3..145013260 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -5,12 +5,6 @@ import android.content.Intent import android.provider.MediaStore import android.support.v7.app.AppCompatActivity import android.view.View -import android.widget.ImageView -import com.bumptech.glide.Glide -import com.bumptech.glide.load.DecodeFormat -import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions -import com.bumptech.glide.request.RequestOptions import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -21,13 +15,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.helpers.TYPE_GIF -import com.simplemobiletools.gallery.helpers.TYPE_IMAGE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEO -import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium -import com.simplemobiletools.gallery.views.MySquareImageView -import pl.droidsonroids.gif.GifDrawable import java.io.File import java.util.* @@ -166,33 +154,6 @@ fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, call } } -fun Activity.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) { - target.isHorizontalScrolling = horizontalScroll - if (type == TYPE_IMAGE || type == TYPE_VIDEO) { - if (type == TYPE_IMAGE && path.isPng()) { - loadPng(path, target, cropThumbnails) - } else { - loadJpg(path, target, cropThumbnails) - } - } else if (type == TYPE_GIF) { - 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 - } catch (e: Exception) { - loadJpg(path, target, cropThumbnails) - } catch (e: OutOfMemoryError) { - loadJpg(path, target, cropThumbnails) - } - } -} - fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, isCopyOperation: Boolean, callback: (destinationPath: String) -> Unit) { if (fileDirItems.isEmpty()) { toast(R.string.unknown_error_occurred) @@ -204,60 +165,3 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, copyMoveFilesTo(fileDirItems, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback) } } - -fun BaseSimpleActivity.addTempFolderIfNeeded(dirs: ArrayList): ArrayList { - val directories = ArrayList() - val tempFolderPath = config.tempFolderPath - if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath)) - directories.add(newFolder) - } - directories.addAll(dirs) - return directories -} - -fun Activity.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { - val options = RequestOptions() - .signature(path.getFileSignature()) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .format(DecodeFormat.PREFER_ARGB_8888) - - val builder = Glide.with(applicationContext) - .asBitmap() - .load(path) - - if (cropThumbnails) options.centerCrop() else options.fitCenter() - builder.apply(options).into(target) -} - -fun Activity.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean) { - val options = RequestOptions() - .signature(path.getFileSignature()) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - - val builder = Glide.with(applicationContext) - .load(path) - - if (cropThumbnails) options.centerCrop() else options.fitCenter() - builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target) -} - -fun Activity.getCachedDirectories(callback: (ArrayList) -> Unit) { - Thread { - val directoryDao = galleryDB.DirectoryDao() - val directories = directoryDao.getAll() as ArrayList - callback(directories) - - directories.filter { !File(it.path).exists() }.forEach { - directoryDao.deleteDir(it) - } - }.start() -} - -fun Activity.getCachedMedia(path: String, callback: (ArrayList) -> Unit) { - Thread { - val mediumDao = galleryDB.MediumDao() - val media = mediumDao.getMediaFromPath(path) as ArrayList - callback(media) - }.start() -} 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 75b6536bb..07cbaa91b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -9,6 +9,12 @@ import android.media.AudioManager import android.os.Build import android.provider.MediaStore import android.view.WindowManager +import android.widget.ImageView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions +import com.bumptech.glide.request.RequestOptions import com.google.gson.Gson import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH @@ -17,11 +23,11 @@ import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.databases.GalleryDataBase -import com.simplemobiletools.gallery.helpers.Config -import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.helpers.SAVE_MEDIA_CNT +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.views.MySquareImageView +import pl.droidsonroids.gif.GifDrawable import java.io.File val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT @@ -187,3 +193,87 @@ fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: dirName } } + +fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) { + target.isHorizontalScrolling = horizontalScroll + if (type == TYPE_IMAGE || type == TYPE_VIDEO) { + if (type == TYPE_IMAGE && path.isPng()) { + loadPng(path, target, cropThumbnails) + } else { + loadJpg(path, target, cropThumbnails) + } + } else if (type == TYPE_GIF) { + 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 + } catch (e: Exception) { + loadJpg(path, target, cropThumbnails) + } catch (e: OutOfMemoryError) { + loadJpg(path, target, cropThumbnails) + } + } +} + +fun Context.addTempFolderIfNeeded(dirs: ArrayList): ArrayList { + val directories = ArrayList() + val tempFolderPath = config.tempFolderPath + if (tempFolderPath.isNotEmpty()) { + val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath)) + directories.add(newFolder) + } + directories.addAll(dirs) + return directories +} + +fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { + val options = RequestOptions() + .signature(path.getFileSignature()) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .format(DecodeFormat.PREFER_ARGB_8888) + + val builder = Glide.with(applicationContext) + .asBitmap() + .load(path) + + if (cropThumbnails) options.centerCrop() else options.fitCenter() + builder.apply(options).into(target) +} + +fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean) { + val options = RequestOptions() + .signature(path.getFileSignature()) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + + val builder = Glide.with(applicationContext) + .load(path) + + if (cropThumbnails) options.centerCrop() else options.fitCenter() + builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target) +} + +fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { + Thread { + val directoryDao = galleryDB.DirectoryDao() + val directories = directoryDao.getAll() as ArrayList + callback(directories) + + directories.filter { !File(it.path).exists() }.forEach { + directoryDao.deleteDir(it) + } + }.start() +} + +fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) { + Thread { + val mediumDao = galleryDB.MediumDao() + val media = mediumDao.getMediaFromPath(path) as ArrayList + callback(media) + }.start() +} From cb5ac8510fddfdaab579c2174b9f4442538c37b5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 21:37:15 +0200 Subject: [PATCH 035/111] delete medium from the local db on delete too --- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/activities/MediaActivity.kt | 11 ++++++++++- .../gallery/activities/ViewPagerActivity.kt | 8 ++++---- .../simplemobiletools/gallery/extensions/Activity.kt | 12 +++++++++++- .../gallery/interfaces/MediumDao.kt | 3 +++ 5 files changed, 29 insertions(+), 7 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 fbe985495..fc2a3ed66 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -244,7 +244,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val newFolder = File(config.tempFolderPath) if (newFolder.exists() && newFolder.isDirectory) { if (newFolder.list()?.isEmpty() == true) { - deleteFile(newFolder.toFileDirItem(applicationContext), true) + tryDeleteFileDirItem(newFolder.toFileDirItem(applicationContext), true) } } config.tempFolderPath = "" 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 6bfaecad5..3833627b2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -444,7 +444,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun deleteDirectoryIfEmpty() { val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath()) if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) { - deleteFile(fileDirItem, true) + tryDeleteFileDirItem(fileDirItem, true) } } @@ -669,6 +669,15 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun deleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList deleteFiles(filtered) { + Thread { + val mediumDao = galleryDB.MediumDao() + filtered.forEach { + if (!File(it.path).exists()) { + mediumDao.deleteMediumPath(it.path) + } + } + }.start() + if (!it) { toast(R.string.unknown_error_occurred) } else if (mMedia.isEmpty()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index a262ade53..ec9ea974d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -547,7 +547,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) { - deleteFile(FileDirItem(newPath, newPath.getFilenameFromPath())) + tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath())) } copyFile(tmpFile, newFile) scanPath(newPath) @@ -575,7 +575,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } catch (e: Exception) { showErrorToast(e) } finally { - deleteFile(FileDirItem(tmpFile.absolutePath, tmpFile.absolutePath.getFilenameFromPath())) + tryDeleteFileDirItem(FileDirItem(tmpFile.absolutePath, tmpFile.absolutePath.getFilenameFromPath())) } } @@ -741,7 +741,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { val path = getCurrentMedia()[mPos].path - deleteFile(FileDirItem(path, path.getFilenameFromPath())) { + tryDeleteFileDirItem(FileDirItem(path, path.getFilenameFromPath())) { refreshViewPager() } } @@ -819,7 +819,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteDirectoryIfEmpty() { val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), getIsPathDirectory(mDirectory)) if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) { - deleteFile(fileDirItem, true) + tryDeleteFileDirItem(fileDirItem, true) } scanPath(mDirectory) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index 145013260..01a510955 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -134,7 +134,7 @@ fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = nul return } - deleteFile(file.toFileDirItem(applicationContext)) { + tryDeleteFileDirItem(file.toFileDirItem(applicationContext)) { callback?.invoke() } } @@ -165,3 +165,13 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, copyMoveFilesTo(fileDirItems, source.trimEnd('/'), it, isCopyOperation, true, config.shouldShowHidden, callback) } } + +fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) { + deleteFile(fileDirItem, allowDeleteFolder) { + callback?.invoke(it) + + Thread { + galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) + }.start() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index 51d8d3b77..8f04294a2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -19,4 +19,7 @@ interface MediumDao { @Insert(onConflict = REPLACE) fun insertAll(media: List) + + @Query("DELETE FROM media WHERE full_path = :path") + fun deleteMediumPath(path: String) } From af7108fd127521a59b152ba02780be3772e11f6f Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 22:21:00 +0200 Subject: [PATCH 036/111] remove the old way of caching media files --- .../gallery/activities/MediaActivity.kt | 12 ----- .../gallery/adapters/MediaAdapter.kt | 12 +---- .../gallery/extensions/Context.kt | 54 ++++++++----------- .../gallery/helpers/Config.kt | 6 --- .../gallery/helpers/Constants.kt | 2 - 5 files changed, 24 insertions(+), 62 deletions(-) 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 3833627b2..7ee09f1c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -652,18 +652,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { setupAdapter() } - - if (!isFromCache) { - storeFolder() - } - } - - private fun storeFolder() { - if (!config.temporarilyShowHidden) { - Thread { - storeFolderItems(mPath, mMedia) - }.start() - } } override fun deleteFiles(fileDirItems: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 6485ca21e..af8cc80e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -187,7 +187,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { config.tempFolderPath = "" - activity.applicationContext.updateStoredFolderItems(it) + activity.applicationContext.rescanFolderMedia(it) + activity.applicationContext.rescanFolderMedia(fileDirItems.first().getParentPath()) if (!isCopyOperation) { listener?.refreshItems() } @@ -237,7 +238,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, media.removeAll(removeMedia) listener?.deleteFiles(fileDirItems) removeSelectedItems() - updateStoredFolderItems() } } @@ -247,14 +247,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, return selectedMedia } - private fun updateStoredFolderItems() { - Thread { - if (media.isNotEmpty()) { - activity.applicationContext.storeFolderItems(media.first().parentPath, media as ArrayList) - } - }.start() - } - fun updateMedia(newMedia: ArrayList) { if (newMedia.hashCode() != currentMediaHash) { currentMediaHash = newMedia.hashCode() 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 07cbaa91b..1794b40f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -15,7 +15,6 @@ import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions -import com.google.gson.Gson import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.R @@ -106,7 +105,6 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList) -> Unit) { val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC" var cursor: Cursor? = null - try { cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder) if (cursor?.moveToFirst() == true) { @@ -126,37 +124,25 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList) -> Unit) { }.start() } -fun Context.isPathInMediaStore(path: String): Boolean { - if (path.startsWith(OTG_PATH)) { - return false - } +fun Context.rescanFolderMedia(path: String) { + Thread { + getCachedMedia(path) { + val cached = it + GetMediaAsynctask(applicationContext, path, false, false, false) { + Thread { + val newMedia = it + val mediumDao = galleryDB.MediumDao() + mediumDao.insertAll(newMedia) - val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED) - val uri = MediaStore.Files.getContentUri("external") - val selection = "${MediaStore.MediaColumns.DATA} = ?" - val selectionArgs = arrayOf(path) - val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) - - cursor?.use { - return cursor.moveToFirst() - } - return false -} - -fun Context.updateStoredFolderItems(path: String) { - GetMediaAsynctask(this, path, false, false, false) { - storeFolderItems(path, it) - }.execute() -} - -fun Context.storeFolderItems(path: String, items: ArrayList) { - try { - val subList = items.subList(0, Math.min(SAVE_MEDIA_CNT, items.size)) - val json = Gson().toJson(subList) - config.saveFolderMedia(path, json) - } catch (ignored: Exception) { - } catch (ignored: OutOfMemoryError) { - } + cached.forEach { + if (!newMedia.contains(it)) { + mediumDao.deleteMediumPath(it.path) + } + } + }.start() + }.execute() + } + }.start() } fun Context.updateStoredDirectories() { @@ -275,5 +261,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) val mediumDao = galleryDB.MediumDao() val media = mediumDao.getMediaFromPath(path) as ArrayList callback(media) + + media.filter { !File(it.path).exists() }.forEach { + mediumDao.deleteMediumPath(it.path) + } }.start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index edb79a028..cc9d07b0f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -131,12 +131,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getStringSet(INCLUDED_FOLDERS, HashSet()) set(includedFolders) = prefs.edit().remove(INCLUDED_FOLDERS).putStringSet(INCLUDED_FOLDERS, includedFolders).apply() - fun saveFolderMedia(path: String, json: String) { - prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply() - } - - fun loadFolderMedia(path: String) = prefs.getString(SAVE_FOLDER_PREFIX + path, "") - var autoplayVideos: Boolean get() = prefs.getBoolean(AUTOPLAY_VIDEOS, false) set(autoplay) = prefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 5dcbc4305..adff9c62b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -25,7 +25,6 @@ const val MEDIA_LANDSCAPE_COLUMN_CNT = "media_landscape_column_cnt" const val MEDIA_HORIZONTAL_COLUMN_CNT = "media_horizontal_column_cnt" const val MEDIA_LANDSCAPE_HORIZONTAL_COLUMN_CNT = "media_landscape_horizontal_column_cnt" const val SHOW_ALL = "show_all" // display images and videos from all folders together -const val SAVE_FOLDER_PREFIX = "folder2_" const val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown" const val EXCLUDED_FOLDERS = "excluded_folders" const val INCLUDED_FOLDERS = "included_folders" @@ -66,7 +65,6 @@ const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 600000L const val CLICK_MAX_DURATION = 150 const val DRAG_THRESHOLD = 8 -const val SAVE_MEDIA_CNT = 80 const val DIRECTORY = "directory" const val MEDIUM = "medium" From 21b1e427b4158471ae21198a686f701e5fb59b66 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 22:33:47 +0200 Subject: [PATCH 037/111] update kotlin to 1.2.40 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index af56fd918..a5b9d1ba6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.31' + ext.kotlin_version = '1.2.40' repositories { jcenter() From 3aa5f8216a7192aea1acf1ed3140f35a5c02e954 Mon Sep 17 00:00:00 2001 From: 10cents Date: Fri, 20 Apr 2018 23:21:34 +0200 Subject: [PATCH 038/111] New file - da --- app/src/main/res/values-da/strings.xml | 189 +++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 app/src/main/res/values-da/strings.xml diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml new file mode 100644 index 000000000..dfd763b29 --- /dev/null +++ b/app/src/main/res/values-da/strings.xml @@ -0,0 +1,189 @@ + + + Simple Gallery + Galleri + Rediger + Åbn kamera + (skjult) + (ekskluderet) + Pin folder + Unpin folder + Pin to the top + Vis indholdet af alle mappert + Alle mapper + Skift til mappevisning + Anden mappe + Vis på kort + Ukendt placering + Flere kolonner + Færre kolonner + Change cover image + Select photo + Use default + Volume + Brightness + Lås orientering + Lås orientering op + + + Filtrer medier + Billeder + Videoer + GIF\'er + Der blev ikke fundet nogen filer med det valgte filter. + Skift filter + + + Denne funktion skjuler mappen og dens eventueller undermapper ved at oprette en \'.nomedia\'-fil i den. Du kan se dem ved at klikke på \'Vis skjulte\' i indstillingerne. Fortsæt? + Ekskluder + Ekskluderede mapper + Administrer ekskluderede mapper + Dette vil kun ekskludere de valgte mapper (og deres undermapper) fra Simple Gallery. Du kan administrere ekskluderede mapper i indstillingerne. + Ekskluder en overliggende mappe i stedet? + Ekskludering af mapper vil skjule dem og eventuelle undermapper for Simple Gallery, de vil stadig være synlige for andre apps.\n\nHvis du også vil skjule dem for andre apps, skal du bruge funktionen Skjul. + Fjern alle + Fjern alle fra listen med ekskluderede mapper? Det vil ikke slette mapperne. + Skjulte mapper + Administrer skjulte mapper + Det ser ikke ud til at du har nogen skjulte mapper med en \".nomedia\"-fil. + + + Inkluderede mapper + Administrer inkluderede mapper + Tilføj mappe + Hvis du har mapper med mediefiler som appen ikke har fundet, kan du manuelt tilføje dem her.\n\nDet vil ikke ekskludere andre mapper. + + + Skaler + Resize selection and save + Width + Height + Keep aspect ratio + Please enter a valid resolution + + + Editor + Gem + Roter + Sti + Ugyldig sti til billede + Redigering af billede mislykkedes + Rediger billede med: + Der blev ikke fundet en editor til billedbehandling + Ukendt filplacering + Kunne ikke overskrive kildefilen + Roter mod venstre + Roter mod højre + Roter 180º + Spejlvend + Spejlvend vandret + Spejlvend lodret + Rediger med + + + Simple Wallpaper + Sæt som baggrundsbillede + Det mislykkedes at sætte billedet som baggrund + Sæt som baggrundsbillede med: + Sætter baggrundsbillede… + Sat som baggrundsbillede + Stående billedformat + Liggende billedformat + Hjemmeskærm + Låseskærm + Hjemme- og låseskærm + + + Slideshow + Frekvens (sekunder): + Inkluder billeder + Inkluder videoer/string> + Inkluder GIF\'er + Tilfældig rækkefølge + Use fade animations + Kør baglæns + Loop slideshow + Slideshowet endte + Der blev ikke funket nogen mediefiler til slideshowet + + + Skift visning + Gitter + Liste + + + Afspil automatisk videoer + Toggle filename visibility + Kør videoer i sløjfe + Animér GIF\'er i miniaturer + Maksimal lysstyrke ved fuldskærmsvisning af medier + Beskær miniaturer til kvadrater + Roter fuldskærmsmedier efter + Systemindstilling + Enhedens orientering + Billedformat + Sort baggrund og statuslinje ved medievisning i fuldskærm + Scroll miniaturer vandret + Skjul automatisk systemets brugerflade ved fuldskærmsvisning af medier + Slet tomme mapper efter sletning af deres indhold + Tillad kontrol af lysstyrke på billeder med lodrette bevægelser + Tillad kontrol af videolyd og lysstyrke med lodrette bevægelser + Vis antal filer i hver mappe i oversigten + Erstat Del med Roter i fuldskærmsmenuen + Vis udvidede oplysninger over medier i fuldskærm + Manage extended details + Tillad zoom med en finger når medier er i fuldskærm + Tillad skift af medie ved klik på skærmens sider + RErstat stærkt zoombare billeder med nogle i bedre kvalitet + Skjul udvidede oplysninger når statuslinjen er skjult + Tjek en ekstra gang for at undgå visning af ugyldige filer + + + Thumbnails + Fullscreen media + Extended details + + + How can I make Simple Gallery the default device gallery? + First you have to find the currently default gallery in the Apps section of your device settings, look for a button that says something like \"Open by default\", click on it, then select \"Clear defaults\". + The next time you will try opening an image or video you should see an app picker, where you can select Simple Gallery and make it the default app. + I locked the app with a password, but I forgot it. What can I do? + You can solve it in 2 ways. You can either reinstall the app, or find the app in your device settings and select \"Clear data\". It will reset all your settings, it will not remove any media files. + How can I make an album always appear at the top? + You can long press the desired album and select the Pin icon at the actionmenu, that will pin it to the top. You can pin multiple folders too, pinned items will be sorted by the default sorting method. + How can I fast-forward videos? + You can click on the current or max duration texts near the seekbar, that will move the video either backward, or forward. + What is the difference between hiding and excluding a folder? + Exclude prevents displaying the folder only in Simple Gallery, while Hide works system-wise and it hides the folder from other galleries too. It works by creating an empty \".nomedia\" file in the given folder, which you can then remove with any file manager too. + Why do folders with music cover art or stickers show up? + It can happen that you will see some unusual albums show up. You can easily exclude them by long pressing them and selecting Exclude. In the next dialog you can then select the parent folder, chances are it will prevent the other related albums showing up too. + A folder with images isn\'t showing up, what can I do? + That can have multiple reasons, but solving it is easy. Just go in Settings -> Manage Included Folders, select Plus and navigate to the required folder. + What if I want just a few particular folders visible? + Adding a folder at the Included Folders doesn\'t automatically exclude anything. What you can do is go in Settings -> Manage Excluded Folders, exclude the root folder \"/\", then add the desired folders at Settings -> Manage Included Folders. + That will make only the selected folders visible, as both excluding and including are recursive and if a folder is both excluded and included, it will show up. + Fullscreen images have weird artifacts, can I somehow improve the quality? + Yea, there is a toggle in Settings saying \"Replace deep zoomable images with better quality ones\", you can use that. It will improve the quality of the images, but they will get blurred once you try zooming in too much. + Can I crop images with this app? + Yes, you can crop images in the editor, by dragging the image corners. You can get to the editor either by long pressing an image thumbnail and selecting Edit, or selecting Edit from the fullscreen view. + + + + A gallery for viewing photos and videos without ads. + + A simple tool usable for viewing photos and videos. Items can be sorted by date, size, name both ascending or descending, photos can be zoomed in. Media files are shown in multiple columns depending on the size of the display, you can change the column count by pinch gestures. They can be renamed, shared, deleted, copied, moved. Images can also be cropped, rotated, flipped or set as Wallpaper directly from the app. + + The Gallery is also offered for third party usage for previewing images / videos, adding attachments at email clients etc. It\'s perfect for everyday usage. + + The fingerprint permission is needed for locking either hidden item visibility, or the whole app. + + Contains no ads or unnecessary permissions. It is fully opensource, provides customizable colors. + + This app is just one piece of a bigger series of apps. You can find the rest of them at https://www.simplemobiletools.com + + + + From 716e623af246fc99f8cceb27800a9da0da66c48f Mon Sep 17 00:00:00 2001 From: anthologist Date: Sat, 21 Apr 2018 11:24:16 +0200 Subject: [PATCH 039/111] italian update --- app/src/main/res/values-it/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index ec87162d8..eeeb3ccba 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -5,7 +5,7 @@ Modifica Apri fotocamera (nascosta) - (excluded) + (esclusa) Blocca cartella Sblocca cartella Fissa in alto @@ -165,7 +165,7 @@ Le immagini a schermo intero hanno strani artefatti, posso migliorarne la qualità in qualche modo? Sì, c\'è un\'opzione nelle impostazioni che dice \"Sostituisci le immagini ingrandibili a fondo con altre di migliore qualità\", puoi usare quella. Ciò migliorerà la qualità delle immagini, ma saranno sfuocate quando proverai a ingrandirle troppo. Posso ritagliare le immagini con questa app? - Sì, puoi ritagliare le immagini nell\'editor, trascinando gli angoli dell\'immagine. Puoi usare l\'editor sia premendo a lungo la miniatura di un'immagine e selezionando Modifica, o selezionando Modifica mentre la vedi a schermo intero. + Sì, puoi ritagliare le immagini nell\'editor, trascinando gli angoli dell\'immagine. Puoi usare l\'editor sia premendo a lungo la miniatura di un\'immagine e selezionando Modifica, o selezionando Modifica mentre la vedi a schermo intero. From 0039591a535edb77d3f2c6e60ce8c4d48b483400 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 22:19:27 +0200 Subject: [PATCH 040/111] properly update files after renaming in the local database --- app/build.gradle | 2 +- .../gallery/activities/MediaActivity.kt | 16 +++++++--------- .../gallery/activities/ViewPagerActivity.kt | 12 ++++++++++-- .../gallery/adapters/MediaAdapter.kt | 7 ++++++- .../gallery/extensions/Context.kt | 6 ++++++ .../gallery/interfaces/MediumDao.kt | 3 +++ app/src/main/res/values-da/strings.xml | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4e75f2a77..09ddc0234 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.5' + implementation 'com.simplemobiletools:commons:3.19.7' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 7ee09f1c0..d4e1b039d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -657,15 +657,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun deleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList deleteFiles(filtered) { - Thread { - val mediumDao = galleryDB.MediumDao() - filtered.forEach { - if (!File(it.path).exists()) { - mediumDao.deleteMediumPath(it.path) - } - } - }.start() - if (!it) { toast(R.string.unknown_error_occurred) } else if (mMedia.isEmpty()) { @@ -673,6 +664,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { finish() } else { updateStoredDirectories() + + Thread { + val mediumDao = galleryDB.MediumDao() + filtered.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index ec9ea974d..81ea68367 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -757,8 +757,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun renameFile() { - RenameItemDialog(this, getCurrentPath()) { - getCurrentMedia()[mPos].path = it + val oldPath = getCurrentPath() + RenameItemDialog(this, oldPath) { + getCurrentMedia()[mPos].apply { + path = it + name = it.getFilenameFromPath() + } + + Thread { + updateMediaPath(oldPath, it) + }.start() updateActionbarTitle() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index af8cc80e9..72fa360af 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -148,7 +148,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun renameFile() { - RenameItemDialog(activity, getCurrentPath()) { + val oldPath = getCurrentPath() + RenameItemDialog(activity, oldPath) { + Thread { + activity.updateMediaPath(oldPath, it) + }.start() + activity.runOnUiThread { listener?.refreshItems() finishActMode() 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 1794b40f0..5f7b9fa93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -267,3 +267,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) } }.start() } + +fun Context.updateMediaPath(oldPath: String, newPath: String) { + val newFilename = newPath.getFilenameFromPath() + val newParentPath = newPath.getParentPath() + galleryDB.MediumDao().updateMedia(oldPath, newParentPath, newFilename, newPath) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index 8f04294a2..cd2cb1564 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -22,4 +22,7 @@ interface MediumDao { @Query("DELETE FROM media WHERE full_path = :path") fun deleteMediumPath(path: String) + + @Query("UPDATE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath") + fun updateMedia(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) } diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index dfd763b29..3e07fbbae 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -97,7 +97,7 @@ Slideshow Frekvens (sekunder): Inkluder billeder - Inkluder videoer/string> + Inkluder videoer Inkluder GIF\'er Tilfældig rækkefølge Use fade animations From f08fd48d1fce5860f6ef10bfc0e46bcce5ab03e3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 22:23:42 +0200 Subject: [PATCH 041/111] properly handle deleting not existing directories from local db --- .../kotlin/com/simplemobiletools/gallery/extensions/Context.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5f7b9fa93..66fab4107 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -251,7 +251,7 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { callback(directories) directories.filter { !File(it.path).exists() }.forEach { - directoryDao.deleteDir(it) + directoryDao.deleteDirPath(it.path) } }.start() } From e237afe9162f7343cc1540046c6968f5aea88f0a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 22:49:29 +0200 Subject: [PATCH 042/111] update directories if one is renamed --- .../gallery/activities/MainActivity.kt | 6 +++++- .../gallery/adapters/DirectoryAdapter.kt | 9 +++------ .../simplemobiletools/gallery/extensions/Context.kt | 13 +++++++++---- 3 files changed, 17 insertions(+), 11 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 fc2a3ed66..20f529ee5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -681,8 +681,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { gotDirectories(directories, true) } else { mDirs = directories - storeDirectories() } + + Thread { + storeDirectoryItems(directories) + removeInvalidDirectories() + }.start() } private fun checkWhatsNewDialog() { 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 f290cdc87..96cddb557 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -155,7 +155,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) -> Unit) { val directoryDao = galleryDB.DirectoryDao() val directories = directoryDao.getAll() as ArrayList callback(directories) - - directories.filter { !File(it.path).exists() }.forEach { - directoryDao.deleteDirPath(it.path) - } + removeInvalidDirectories(directories, directoryDao) }.start() } @@ -268,6 +266,13 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) }.start() } +fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { + val dirsToCheck = dirs ?: directoryDao.getAll() + dirsToCheck.filter { !File(it.path).exists() }.forEach { + directoryDao.deleteDirPath(it.path) + } +} + fun Context.updateMediaPath(oldPath: String, newPath: String) { val newFilename = newPath.getFilenameFromPath() val newParentPath = newPath.getParentPath() From 570e471dec52d6751e617804445551b953b4a045 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 23:15:31 +0200 Subject: [PATCH 043/111] display cached dirs and media only when appropriate --- .../gallery/activities/MainActivity.kt | 20 ++++++++------ .../gallery/activities/MediaActivity.kt | 11 +++++--- .../gallery/extensions/String.kt | 21 +++++++++++++++ .../gallery/helpers/MediaFetcher.kt | 26 +++---------------- 4 files changed, 44 insertions(+), 34 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 20f529ee5..027ff2055 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -276,8 +276,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGettingDirs = true if (!mLoadedInitialPhotos) { getCachedDirectories { - if (it.isNotEmpty()) { - gotDirectories(it, true) + val shouldShowHidden = config.shouldShowHidden + val excludedPaths = config.excludedFolders + val includedPaths = config.includedFolders + val dirs = it.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList + + if (dirs.isNotEmpty()) { + gotDirectories(dirs, true) } } } @@ -566,17 +571,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val dirs = getSortedDirectories(newDirs) - directories_refresh_layout.isRefreshing = false mIsGettingDirs = false - - directories_empty_text_label.beVisibleIf(dirs.isEmpty() && !isFromCache) - directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache) - directories_grid.beVisibleIf(directories_empty_text_label.isGone()) - checkLastMediaChanged() mDirs = dirs runOnUiThread { + directories_refresh_layout.isRefreshing = false + directories_empty_text_label.beVisibleIf(dirs.isEmpty() && !isFromCache) + directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache) + directories_grid.beVisibleIf(directories_empty_text_label.isGone()) + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) 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 d4e1b039d..665c98558 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -456,10 +456,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mIsGettingMedia = true if (!mLoadedInitialPhotos) { getCachedMedia(mPath) { - if (it.isEmpty()) { + val shouldShowHidden = config.shouldShowHidden + var media = it + if (!shouldShowHidden) { + media = media.filter { !it.name.startsWith('.') } as ArrayList + } + + if (media.isEmpty()) { media_refresh_layout.isRefreshing = true } else { - gotMedia(it, true) + gotMedia(media, true) } } } else { @@ -636,7 +642,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { }.start() mIsGettingMedia = false - checkLastMediaChanged() mMedia = media diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt index db7b0ec87..dd28e208b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt @@ -11,3 +11,24 @@ fun String.getFileSignature(): ObjectKey { fun String.isThisOrParentIncluded(includedPaths: MutableSet) = includedPaths.any { startsWith(it, true) } fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = excludedPaths.any { startsWith(it, true) } + +fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean): Boolean { + val file = File(this) + return if (isEmpty()) { + false + } else if (!showHidden && file.containsNoMedia()) { + false + } else if (isThisOrParentIncluded(includedPaths)) { + true + } else if (isThisOrParentExcluded(excludedPaths)) { + false + } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { + var containsNoMediaOrDot = file.containsNoMedia() || contains("/.") + if (!containsNoMediaOrDot) { + containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia() + } + !containsNoMediaOrDot + } else { + true + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 8c5847192..ccb160104 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -8,7 +8,8 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.photoExtensions import com.simplemobiletools.commons.helpers.videoExtensions -import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.LinkedHashMap @@ -132,7 +133,7 @@ class MediaFetcher(val context: Context) { val curMedia = ArrayList() val showHidden = config.shouldShowHidden val excludedFolders = config.excludedFolders - foldersToScan.filter { shouldFolderBeVisible(it, excludedFolders, includedFolders, showHidden) }.toList().forEach { + foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden) }.toList().forEach { fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) } @@ -182,27 +183,6 @@ class MediaFetcher(val context: Context) { return directories } - private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean): Boolean { - val file = File(path) - return if (path.isEmpty()) { - false - } else if (!showHidden && file.containsNoMedia()) { - false - } else if (path.isThisOrParentIncluded(includedPaths)) { - true - } else if (path.isThisOrParentExcluded(excludedPaths)) { - false - } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { - var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.") - if (!containsNoMediaOrDot) { - containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia() - } - !containsNoMediaOrDot - } else { - true - } - } - private fun getMediaInFolder(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { val files = File(folder).listFiles() ?: return val doExtraCheck = context.config.doExtraCheck From ab589c52cfa1dcc9132e79392bc23a0cf8d83422 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 23:18:43 +0200 Subject: [PATCH 044/111] refresh directories at toggling Temporarily show hidden immediately --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 027ff2055..8eeadaa0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -356,6 +356,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun toggleTemporarilyShowHidden(show: Boolean) { + mLoadedInitialPhotos = false config.temporarilyShowHidden = show getDirectories() invalidateOptionsMenu() From d479baa625713b799ac8b99d91a0755ea2f6eaee Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 21 Apr 2018 23:21:45 +0200 Subject: [PATCH 045/111] refresh media instantly after toggling Temporarily show hidden too --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 665c98558..384af1343 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -500,6 +500,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun toggleTemporarilyShowHidden(show: Boolean) { + mLoadedInitialPhotos = false config.temporarilyShowHidden = show getMedia() invalidateOptionsMenu() From a90f48889d6be5fc8f8634ff1541f417ffac0318 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 10:20:32 +0200 Subject: [PATCH 046/111] do the hidden file filtering right inside getCachedMedia --- .../gallery/activities/MediaActivity.kt | 13 ++++--------- .../simplemobiletools/gallery/extensions/Context.kt | 7 ++++++- 2 files changed, 10 insertions(+), 10 deletions(-) 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 384af1343..7d167f334 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -456,16 +456,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mIsGettingMedia = true if (!mLoadedInitialPhotos) { getCachedMedia(mPath) { - val shouldShowHidden = config.shouldShowHidden - var media = it - if (!shouldShowHidden) { - media = media.filter { !it.name.startsWith('.') } as ArrayList - } - - if (media.isEmpty()) { + if (it.isEmpty()) { media_refresh_layout.isRefreshing = true } else { - gotMedia(media, true) + gotMedia(it, true) } } } else { @@ -485,8 +479,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { deleteDirectoryIfEmpty() finish() true - } else + } else { false + } } private fun tryToggleTemporarilyShowHidden() { 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 74718a1f7..906c0f026 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -258,7 +258,12 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) Thread { val mediumDao = galleryDB.MediumDao() val media = mediumDao.getMediaFromPath(path) as ArrayList - callback(media) + val shouldShowHidden = config.shouldShowHidden + var filteredMedia = media + if (!shouldShowHidden) { + filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList + } + callback(filteredMedia) media.filter { !File(it.path).exists() }.forEach { mediumDao.deleteMediumPath(it.path) From 8af103d98c67151dc4d26d65f2c2d25b2c367375 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 10:32:13 +0200 Subject: [PATCH 047/111] filter cached media by type too --- .../com/simplemobiletools/gallery/extensions/Context.kt | 8 ++++++++ .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 -- 2 files changed, 8 insertions(+), 2 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 906c0f026..bbc9f8129 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -263,6 +263,14 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) if (!shouldShowHidden) { filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList } + + val filterMedia = config.filterMedia + filteredMedia = filteredMedia.filter { + (filterMedia and IMAGES != 0 && it.type == TYPE_IMAGE) || + (filterMedia and VIDEOS != 0 && it.type == TYPE_VIDEO) || + (filterMedia and GIFS != 0 && it.type == TYPE_GIF) + } as ArrayList + callback(filteredMedia) media.filter { !File(it.path).exists() }.forEach { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index ccb160104..2068d35c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -167,7 +167,6 @@ class MediaFetcher(val context: Context) { private fun groupDirectories(media: ArrayList): HashMap> { val directories = LinkedHashMap>() - val hasOTG = context.hasOTGConnected() && context.config.OTGBasePath.isNotEmpty() for (medium in media) { if (shouldStop) { break @@ -226,7 +225,6 @@ class MediaFetcher(val context: Context) { else -> TYPE_GIF } - val parentPath = file.absolutePath.removeSuffix("/") val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type) curMedia.add(medium) } From 7f17aeda71ff7476e4c5bcb378be6634d8489654 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 10:39:00 +0200 Subject: [PATCH 048/111] refresh media thumbnails instantly after changing sorting or filtering --- .../simplemobiletools/gallery/activities/MediaActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 7d167f334..498a25994 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -274,7 +274,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val filtered = mMedia.filter { it.name.contains(text, true) } as ArrayList filtered.sortBy { !it.name.startsWith(text, true) } runOnUiThread { - (media_grid.adapter as? MediaAdapter)?.updateMedia(filtered) + getMediaAdapter()?.updateMedia(filtered) } }.start() } @@ -367,12 +367,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun showSortingDialog() { ChangeSortingDialog(this, false, !config.showAll, mPath) { + mLoadedInitialPhotos = false getMedia() } } private fun showFilterMediaDialog() { FilterMediaDialog(this) { + mLoadedInitialPhotos = false media_refresh_layout.isRefreshing = true getMedia() } @@ -380,8 +382,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun toggleFilenameVisibility() { config.displayFileNames = !config.displayFileNames - if (media_grid.adapter != null) - getMediaAdapter()?.updateDisplayFilenames(config.displayFileNames) + getMediaAdapter()?.updateDisplayFilenames(config.displayFileNames) } private fun switchToFolderView() { From 2eaff8568f7a99fbce4da0b0c7e8d31d671226a3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 20:01:48 +0200 Subject: [PATCH 049/111] properly filter cached directories by file type shown --- .../gallery/activities/MainActivity.kt | 10 +++----- .../asynctasks/GetDirectoriesAsynctask.kt | 24 ++++++++++++++++++- .../gallery/extensions/Context.kt | 16 +++++++++++-- .../gallery/interfaces/DirectoryDao.kt | 2 +- .../gallery/models/Directory.kt | 3 ++- 5 files changed, 43 insertions(+), 12 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 8eeadaa0c..c2f714519 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -276,13 +276,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGettingDirs = true if (!mLoadedInitialPhotos) { getCachedDirectories { - val shouldShowHidden = config.shouldShowHidden - val excludedPaths = config.excludedFolders - val includedPaths = config.includedFolders - val dirs = it.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList - - if (dirs.isNotEmpty()) { - gotDirectories(dirs, true) + if (it.isNotEmpty()) { + gotDirectories(it, true) } } } @@ -312,6 +307,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun showFilterMediaDialog() { FilterMediaDialog(this) { + mLoadedInitialPhotos = false directories_refresh_layout.isRefreshing = true getDirectories() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 55b127375..2ae5d3b46 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,7 +10,10 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.GIFS +import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.MediaFetcher +import com.simplemobiletools.gallery.helpers.VIDEOS import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -55,17 +58,36 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } } + val mediaTypes = getDirMediaTypes(curMedia) + val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders) val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) val size = curMedia.sumByLong { it.size } - val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir)) + val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir), mediaTypes) directories.add(directory) } return directories } + private fun getDirMediaTypes(media: ArrayList): Int { + var types = 0 + if (media.any { it.isImage() }) { + types += IMAGES + } + + if (media.any { it.isVideo() }) { + types += VIDEOS + } + + if (media.any { it.isGif() }) { + types += GIFS + } + + return types + } + override fun onPostExecute(dirs: ArrayList) { super.onPostExecute(dirs) callback(dirs) 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 bbc9f8129..0a0209975 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -212,7 +212,7 @@ fun Context.addTempFolderIfNeeded(dirs: ArrayList): ArrayList() val tempFolderPath = config.tempFolderPath if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath)) + val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath), 0) directories.add(newFolder) } directories.addAll(dirs) @@ -249,7 +249,19 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { Thread { val directoryDao = galleryDB.DirectoryDao() val directories = directoryDao.getAll() as ArrayList - callback(directories) + val shouldShowHidden = config.shouldShowHidden + val excludedPaths = config.excludedFolders + val includedPaths = config.includedFolders + var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList + val filterMedia = config.filterMedia + filteredDirectories = filteredDirectories.filter { + (filterMedia and IMAGES != 0 && it.types == TYPE_IMAGE) || + (filterMedia and VIDEOS != 0 && it.types == TYPE_VIDEO) || + (filterMedia and GIFS != 0 && it.types == TYPE_GIF) + } as ArrayList + + callback(filteredDirectories) + removeInvalidDirectories(directories, directoryDao) }.start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 6b6d0580b..a8172a8b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory @Dao interface DirectoryDao { - @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card FROM directories") + @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card, media_types FROM directories") fun getAll(): List @Insert(onConflict = REPLACE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 02b18d8d8..27c15d62e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -19,7 +19,8 @@ data class Directory( @ColumnInfo(name = "last_modified") val modified: Long, @ColumnInfo(name = "date_taken") val taken: Long, @ColumnInfo(name = "size") val size: Long, - @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean) : Serializable, Comparable { + @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean, + @ColumnInfo(name = "media_types") val types: Int) : Serializable, Comparable { companion object { private const val serialVersionUID = -6553345863555455L From d0f4f0d403a34b4c9b835924a3d5f76d4f594397 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 20:16:02 +0200 Subject: [PATCH 050/111] rename some media type related constants --- .../gallery/activities/PhotoVideoActivity.kt | 6 ++-- .../gallery/adapters/DirectoryAdapter.kt | 12 +++---- .../asynctasks/GetDirectoriesAsynctask.kt | 12 +++---- .../gallery/dialogs/FilterMediaDialog.kt | 22 ++++++------ .../gallery/extensions/Context.kt | 18 +++++----- .../gallery/helpers/Config.kt | 2 +- .../gallery/helpers/Constants.kt | 11 ++---- .../gallery/helpers/MediaFetcher.kt | 36 +++++++++---------- .../gallery/models/Medium.kt | 12 +++---- 9 files changed, 63 insertions(+), 68 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 0e16febe8..3cd1fcecc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -85,9 +85,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList val bundle = Bundle() val file = File(mUri.toString()) val type = when { - file.isImageFast() -> TYPE_IMAGE - file.isVideoFast() -> TYPE_VIDEO - else -> TYPE_GIF + file.isImageFast() -> TYPE_IMAGES + file.isVideoFast() -> TYPE_VIDEOS + else -> TYPE_GIFS } mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type) 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 96cddb557..1d0529e1c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -19,9 +19,9 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.TYPE_GIF -import com.simplemobiletools.gallery.helpers.TYPE_IMAGE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEO +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory @@ -413,9 +413,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList TYPE_IMAGE - directory.tmb.isVideoFast() -> TYPE_VIDEO - else -> TYPE_GIF + directory.tmb.isImageFast() -> TYPE_IMAGES + directory.tmb.isVideoFast() -> TYPE_VIDEOS + else -> TYPE_GIFS } activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 2ae5d3b46..f3c06916a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,10 +10,10 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.GIFS -import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.MediaFetcher -import com.simplemobiletools.gallery.helpers.VIDEOS +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -74,15 +74,15 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va private fun getDirMediaTypes(media: ArrayList): Int { var types = 0 if (media.any { it.isImage() }) { - types += IMAGES + types += TYPE_IMAGES } if (media.any { it.isVideo() }) { - types += VIDEOS + types += TYPE_VIDEOS } if (media.any { it.isGif() }) { - types += GIFS + types += TYPE_GIFS } return types diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt index b1f10323f..ec3cd7faa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt @@ -5,9 +5,9 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.GIFS -import com.simplemobiletools.gallery.helpers.IMAGES -import com.simplemobiletools.gallery.helpers.VIDEOS +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import kotlinx.android.synthetic.main.dialog_filter_media.view.* class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: Int) -> Unit) { @@ -16,27 +16,27 @@ class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: init { val filterMedia = activity.config.filterMedia view.apply { - filter_media_images.isChecked = filterMedia and IMAGES != 0 - filter_media_videos.isChecked = filterMedia and VIDEOS != 0 - filter_media_gifs.isChecked = filterMedia and GIFS != 0 + filter_media_images.isChecked = filterMedia and TYPE_IMAGES != 0 + filter_media_videos.isChecked = filterMedia and TYPE_VIDEOS != 0 + filter_media_gifs.isChecked = filterMedia and TYPE_GIFS != 0 } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.filter_media) - } + activity.setupDialogStuff(view, this, R.string.filter_media) + } } private fun dialogConfirmed() { var result = 0 if (view.filter_media_images.isChecked) - result += IMAGES + result += TYPE_IMAGES if (view.filter_media_videos.isChecked) - result += VIDEOS + result += TYPE_VIDEOS if (view.filter_media_gifs.isChecked) - result += GIFS + result += TYPE_GIFS activity.config.filterMedia = result callback(result) 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 0a0209975..6d8c64bb7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -183,13 +183,13 @@ fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) { target.isHorizontalScrolling = horizontalScroll - if (type == TYPE_IMAGE || type == TYPE_VIDEO) { - if (type == TYPE_IMAGE && path.isPng()) { + if (type == TYPE_IMAGES || type == TYPE_VIDEOS) { + if (type == TYPE_IMAGES && path.isPng()) { loadPng(path, target, cropThumbnails) } else { loadJpg(path, target, cropThumbnails) } - } else if (type == TYPE_GIF) { + } else if (type == TYPE_GIFS) { try { val gifDrawable = GifDrawable(path) target.setImageDrawable(gifDrawable) @@ -255,9 +255,9 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList val filterMedia = config.filterMedia filteredDirectories = filteredDirectories.filter { - (filterMedia and IMAGES != 0 && it.types == TYPE_IMAGE) || - (filterMedia and VIDEOS != 0 && it.types == TYPE_VIDEO) || - (filterMedia and GIFS != 0 && it.types == TYPE_GIF) + (filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) || + (filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) || + (filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0) } as ArrayList callback(filteredDirectories) @@ -278,9 +278,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) val filterMedia = config.filterMedia filteredMedia = filteredMedia.filter { - (filterMedia and IMAGES != 0 && it.type == TYPE_IMAGE) || - (filterMedia and VIDEOS != 0 && it.type == TYPE_VIDEO) || - (filterMedia and GIFS != 0 && it.type == TYPE_GIF) + (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || + (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || + (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) } as ArrayList callback(filteredMedia) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index cc9d07b0f..86cd7caf8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -164,7 +164,7 @@ class Config(context: Context) : BaseConfig(context) { set(darkBackground) = prefs.edit().putBoolean(DARK_BACKGROUND, darkBackground).apply() var filterMedia: Int - get() = prefs.getInt(FILTER_MEDIA, IMAGES or VIDEOS or GIFS) + get() = prefs.getInt(FILTER_MEDIA, TYPE_IMAGES or TYPE_VIDEOS or TYPE_GIFS) set(filterMedia) = prefs.edit().putInt(FILTER_MEDIA, filterMedia).apply() var dirColumnCnt: Int diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index adff9c62b..d75ce223d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -81,11 +81,6 @@ const val ROTATE_BY_SYSTEM_SETTING = 0 const val ROTATE_BY_DEVICE_ROTATION = 1 const val ROTATE_BY_ASPECT_RATIO = 2 -// filter media -const val IMAGES = 1 -const val VIDEOS = 2 -const val GIFS = 4 - // view types const val VIEW_TYPE_GRID = 1 const val VIEW_TYPE_LIST = 2 @@ -104,6 +99,6 @@ const val EXT_ARTIST = 512 const val EXT_ALBUM = 1024 // media types -const val TYPE_IMAGE = 1 -const val TYPE_VIDEO = 2 -const val TYPE_GIF = 3 +const val TYPE_IMAGES = 1 +const val TYPE_VIDEOS = 2 +const val TYPE_GIFS = 4 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 2068d35c0..172bbcc81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -58,19 +58,19 @@ class MediaFetcher(val context: Context) { } query.append("(") - if (filterMedia and IMAGES != 0) { + if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { query.append("${MediaStore.Images.Media.DATA} LIKE ? OR ") } } - if (filterMedia and VIDEOS != 0) { + if (filterMedia and TYPE_VIDEOS != 0) { videoExtensions.forEach { query.append("${MediaStore.Images.Media.DATA} LIKE ? OR ") } } - if (filterMedia and GIFS != 0) { + if (filterMedia and TYPE_GIFS != 0) { query.append("${MediaStore.Images.Media.DATA} LIKE ?") } @@ -86,19 +86,19 @@ class MediaFetcher(val context: Context) { args.add("$path/%/%") } - if (filterMedia and IMAGES != 0) { + if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { args.add("%$it") } } - if (filterMedia and VIDEOS != 0) { + if (filterMedia and TYPE_VIDEOS != 0) { videoExtensions.forEach { args.add("%$it") } } - if (filterMedia and GIFS != 0) { + if (filterMedia and TYPE_GIFS != 0) { args.add("%.gif") } @@ -200,13 +200,13 @@ class MediaFetcher(val context: Context) { if (!isImage && !isVideo && !isGif) continue - if (isVideo && (isPickImage || filterMedia and VIDEOS == 0)) + if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) continue - if (isImage && (isPickVideo || filterMedia and IMAGES == 0)) + if (isImage && (isPickVideo || filterMedia and TYPE_IMAGES == 0)) continue - if (isGif && filterMedia and GIFS == 0) + if (isGif && filterMedia and TYPE_GIFS == 0) continue if (!showHidden && filename.startsWith('.')) @@ -220,9 +220,9 @@ class MediaFetcher(val context: Context) { val dateModified = file.lastModified() val type = when { - isImage -> TYPE_IMAGE - isVideo -> TYPE_VIDEO - else -> TYPE_GIF + isImage -> TYPE_IMAGES + isVideo -> TYPE_VIDEOS + else -> TYPE_GIFS } val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type) @@ -248,13 +248,13 @@ class MediaFetcher(val context: Context) { if (!isImage && !isVideo && !isGif) continue - if (isVideo && (isPickImage || filterMedia and VIDEOS == 0)) + if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0)) continue - if (isImage && (isPickVideo || filterMedia and IMAGES == 0)) + if (isImage && (isPickVideo || filterMedia and TYPE_IMAGES == 0)) continue - if (isGif && filterMedia and GIFS == 0) + if (isGif && filterMedia and TYPE_GIFS == 0) continue if (!showHidden && filename.startsWith('.')) @@ -268,9 +268,9 @@ class MediaFetcher(val context: Context) { val dateModified = file.lastModified() val type = when { - isImage -> TYPE_IMAGE - isVideo -> TYPE_VIDEO - else -> TYPE_GIF + isImage -> TYPE_IMAGES + isVideo -> TYPE_VIDEOS + else -> TYPE_GIFS } val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 5dbfefcc2..2327feadb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -8,9 +8,9 @@ import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.extensions.isDng import com.simplemobiletools.commons.helpers.* -import com.simplemobiletools.gallery.helpers.TYPE_GIF -import com.simplemobiletools.gallery.helpers.TYPE_IMAGE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEO +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import java.io.Serializable @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) @@ -29,11 +29,11 @@ data class Medium( var sorting: Int = 0 } - fun isGif() = type == TYPE_GIF + fun isGif() = type == TYPE_GIFS - fun isImage() = type == TYPE_IMAGE + fun isImage() = type == TYPE_IMAGES - fun isVideo() = type == TYPE_VIDEO + fun isVideo() = type == TYPE_VIDEOS fun isDng() = path.isDng() From 37c31f813b63f0c0b487e56fc5afb322486d2f5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 22:01:05 +0200 Subject: [PATCH 051/111] make sure only the appropriate media files are shown at third party intents --- .../gallery/activities/MainActivity.kt | 7 ++- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/extensions/Context.kt | 63 ++++++++++--------- 3 files changed, 41 insertions(+), 31 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 c2f714519..e24681ea3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -274,8 +274,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } mIsGettingDirs = true + val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent + val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent + if (!mLoadedInitialPhotos) { - getCachedDirectories { + getCachedDirectories(getVideosOnly, getImagesOnly) { if (it.isNotEmpty()) { gotDirectories(it, true) } @@ -288,7 +291,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mLoadedInitialPhotos = true mCurrAsyncTask?.stopFetching() - mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) { + mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, getVideosOnly, getImagesOnly) { mCurrAsyncTask = null gotDirectories(addTempFolderIfNeeded(it), 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 498a25994..2d9becbeb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -456,7 +456,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mIsGettingMedia = true if (!mLoadedInitialPhotos) { - getCachedMedia(mPath) { + getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent) { if (it.isEmpty()) { media_refresh_layout.isRefreshing = true } 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 6d8c64bb7..944051624 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -245,7 +245,7 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target) } -fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { +fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { Thread { val directoryDao = galleryDB.DirectoryDao() val directories = directoryDao.getAll() as ArrayList @@ -254,11 +254,16 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { val includedPaths = config.includedFolders var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList val filterMedia = config.filterMedia - filteredDirectories = filteredDirectories.filter { - (filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) || - (filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) || - (filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0) - } as ArrayList + + filteredDirectories = (when { + getVideosOnly -> filteredDirectories.filter { it.types and TYPE_VIDEOS != 0 } + getImagesOnly -> filteredDirectories.filter { it.types and TYPE_IMAGES != 0 } + else -> filteredDirectories.filter { + (filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) || + (filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) || + (filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0) + } + }) as ArrayList callback(filteredDirectories) @@ -266,30 +271,32 @@ fun Context.getCachedDirectories(callback: (ArrayList) -> Unit) { }.start() } -fun Context.getCachedMedia(path: String, callback: (ArrayList) -> Unit) { - Thread { - val mediumDao = galleryDB.MediumDao() - val media = mediumDao.getMediaFromPath(path) as ArrayList - val shouldShowHidden = config.shouldShowHidden - var filteredMedia = media - if (!shouldShowHidden) { - filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList - } +fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) = + Thread { + val mediumDao = galleryDB.MediumDao() + val media = mediumDao.getMediaFromPath(path) as ArrayList + val shouldShowHidden = config.shouldShowHidden + var filteredMedia = media + if (!shouldShowHidden) { + filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList + } - val filterMedia = config.filterMedia - filteredMedia = filteredMedia.filter { - (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || - (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || - (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) - } as ArrayList + val filterMedia = config.filterMedia + filteredMedia = (when { + getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } + getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } + else -> filteredMedia.filter { + (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || + (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || + (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) + } + }) as ArrayList - callback(filteredMedia) - - media.filter { !File(it.path).exists() }.forEach { - mediumDao.deleteMediumPath(it.path) - } - }.start() -} + callback(filteredMedia) + media.filter { !File(it.path).exists() }.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() From b0a26d0bd8edd89153331d99b52e3eb20b90eb41 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 22:08:27 +0200 Subject: [PATCH 052/111] update UI at picker dialogs from the main thread --- .../simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt | 4 +++- .../com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index e31b4b260..1ee74ba96 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -42,7 +42,9 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri activity.getCachedDirectories { if (it.isNotEmpty()) { - gotDirectories(activity.addTempFolderIfNeeded(it)) + activity.runOnUiThread { + gotDirectories(activity.addTempFolderIfNeeded(it)) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 88845a539..0daec8e55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -39,7 +39,9 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c activity.getCachedMedia(path) { val media = it.filter { !it.isVideo() } as ArrayList if (media.isNotEmpty()) { - gotMedia(media) + activity.runOnUiThread { + gotMedia(media) + } } } From 302a7842c4cab7a364dc4101b84ffa4a1aa07a4c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 22:17:40 +0200 Subject: [PATCH 053/111] fetch all stored media files at "Show all folders content" --- .../gallery/extensions/Context.kt | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 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 944051624..cbf70ea24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -271,32 +271,33 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: }.start() } -fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) = - Thread { - val mediumDao = galleryDB.MediumDao() - val media = mediumDao.getMediaFromPath(path) as ArrayList - val shouldShowHidden = config.shouldShowHidden - var filteredMedia = media - if (!shouldShowHidden) { - filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList - } +fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { + Thread { + val mediumDao = galleryDB.MediumDao() + val media = (if (path == "/") mediumDao.getAll() else mediumDao.getMediaFromPath(path)) as ArrayList + val shouldShowHidden = config.shouldShowHidden + var filteredMedia = media + if (!shouldShowHidden) { + filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList + } - val filterMedia = config.filterMedia - filteredMedia = (when { - getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } - getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } - else -> filteredMedia.filter { - (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || - (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || - (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) - } - }) as ArrayList - - callback(filteredMedia) - media.filter { !File(it.path).exists() }.forEach { - mediumDao.deleteMediumPath(it.path) + val filterMedia = config.filterMedia + filteredMedia = (when { + getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS } + getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES } + else -> filteredMedia.filter { + (filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) || + (filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) || + (filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS) } - }.start() + }) as ArrayList + + callback(filteredMedia) + media.filter { !File(it.path).exists() }.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() +} fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() From 8ff9e7f6adabdabae84596bfeba36aa53113582b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:08:36 +0200 Subject: [PATCH 054/111] fix some Rename related glitches --- .../com/simplemobiletools/gallery/extensions/Activity.kt | 5 ++++- .../com/simplemobiletools/gallery/interfaces/MediumDao.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index 01a510955..b6ecd4d35 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -148,9 +148,12 @@ fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, call filename.substring(1, filename.length) } - val newPath = "$path$filename" + val newPath = "$path/$filename" renameFile(oldPath, newPath) { callback?.invoke(newPath) + Thread { + updateMediaPath(oldPath, newPath) + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index cd2cb1564..da7612e52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -23,6 +23,6 @@ interface MediumDao { @Query("DELETE FROM media WHERE full_path = :path") fun deleteMediumPath(path: String) - @Query("UPDATE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath") + @Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath") fun updateMedia(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) } From 04ab018a320bc0f66114ed0ab1b15cf9c0dc4cdc Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:15:57 +0200 Subject: [PATCH 055/111] make sure New Folder appears first on the list --- .../simplemobiletools/gallery/extensions/Context.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 cbf70ea24..7b261c90d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -78,12 +78,20 @@ fun Context.movePinnedDirectoriesToFront(dirs: ArrayList): ArrayList< val pinnedFolders = config.pinnedFolders dirs.forEach { - if (pinnedFolders.contains(it.path)) + if (pinnedFolders.contains(it.path)) { foundFolders.add(it) + } } dirs.removeAll(foundFolders) dirs.addAll(0, foundFolders) + if (config.tempFolderPath.isNotEmpty()) { + val newFolder = dirs.firstOrNull { it.path == config.tempFolderPath } + if (newFolder != null) { + dirs.remove(newFolder) + dirs.add(0, newFolder) + } + } return dirs } From 4949744677368ce1db899fd33be9988f1ee6d016 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:35:08 +0200 Subject: [PATCH 056/111] update commons to 3.19.8 --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/fragments/PhotoFragment.kt | 2 +- .../com/simplemobiletools/gallery/helpers/GlideDecoder.kt | 2 +- .../gallery/helpers/GlideRotateTransformation.kt | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 09ddc0234..c213f75b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.7' + implementation 'com.simplemobiletools:commons:3.19.8' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 7d299d026..09a0a976c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -275,7 +275,7 @@ class PhotoFragment : ViewPagerFragment() { } else { val options = RequestOptions() .diskCacheStrategy(DiskCacheStrategy.NONE) - .transform(GlideRotateTransformation(context!!, degrees)) + .transform(GlideRotateTransformation(degrees)) Glide.with(this) .asBitmap() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt index 326b6011c..5c0bd41b8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt @@ -31,7 +31,7 @@ class GlideDecoder : ImageDecoder { val degrees = getRotationDegrees(orientation) if (degrees != 0) { - options.transform(GlideRotateTransformation(context, getRotationDegrees(orientation))) + options.transform(GlideRotateTransformation(getRotationDegrees(orientation))) } val drawable = Glide.with(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideRotateTransformation.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideRotateTransformation.kt index 84ee4c49f..5f34c6ced 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideRotateTransformation.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideRotateTransformation.kt @@ -1,13 +1,12 @@ package com.simplemobiletools.gallery.helpers -import android.content.Context import android.graphics.Bitmap import android.graphics.Matrix import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool import com.bumptech.glide.load.resource.bitmap.BitmapTransformation import java.security.MessageDigest -class GlideRotateTransformation(context: Context, val rotateRotationAngle: Int) : BitmapTransformation(context) { +class GlideRotateTransformation(val rotateRotationAngle: Int) : BitmapTransformation() { override fun transform(pool: BitmapPool, bitmap: Bitmap, outWidth: Int, outHeight: Int): Bitmap { if (rotateRotationAngle % 360 == 0) return bitmap From 508a3b8b196c2281263ca7b5f6fbe6d6dbdbdb4b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:35:53 +0200 Subject: [PATCH 057/111] removing the unused GlideDecoder class --- .../gallery/helpers/GlideDecoder.kt | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt deleted file mode 100644 index 5c0bd41b8..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.simplemobiletools.gallery.helpers - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.Drawable -import android.media.ExifInterface -import android.net.Uri -import com.bumptech.glide.Glide -import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.request.RequestOptions -import com.bumptech.glide.request.target.Target -import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder -import com.simplemobiletools.gallery.activities.ViewPagerActivity -import com.simplemobiletools.gallery.extensions.getFileSignature - -class GlideDecoder : ImageDecoder { - override fun decode(context: Context, uri: Uri): Bitmap { - val exif = android.media.ExifInterface(uri.path) - val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL) - - val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth - val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight - - ViewPagerActivity.wasDecodedByGlide = true - val options = RequestOptions() - .signature(uri.path.getFileSignature()) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .override(targetWidth, targetHeight) - - val degrees = getRotationDegrees(orientation) - if (degrees != 0) { - options.transform(GlideRotateTransformation(getRotationDegrees(orientation))) - } - - val drawable = Glide.with(context) - .load(uri) - .apply(options) - .submit() - .get() - - return drawableToBitmap(drawable) - } - - private fun drawableToBitmap(drawable: Drawable): Bitmap { - if (drawable is BitmapDrawable && drawable.bitmap != null) { - return drawable.bitmap - } - - val bitmap = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) { - Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) - } else { - Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888) - } - - val canvas = Canvas(bitmap) - drawable.setBounds(0, 0, canvas.width, canvas.height) - drawable.draw(canvas) - return bitmap - } - - // rotating backwards intentionally, as SubsamplingScaleImageView will rotate it properly at displaying - private fun getRotationDegrees(orientation: Int) = when (orientation) { - ExifInterface.ORIENTATION_ROTATE_270 -> 90 - ExifInterface.ORIENTATION_ROTATE_180 -> 180 - ExifInterface.ORIENTATION_ROTATE_90 -> 270 - else -> 0 - } -} From 470a0c5ea2d43bb71407abda25cace91bf526ef5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:46:57 +0200 Subject: [PATCH 058/111] update commons to 3.19.9 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index c213f75b6..18ab2bf1a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.8' + implementation 'com.simplemobiletools:commons:3.19.9' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' From a75a50358ac3f9d606c7685707918f407fb0bce6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:47:04 +0200 Subject: [PATCH 059/111] update version to 3.8.0 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 18ab2bf1a..c1e93b509 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 173 - versionName "3.7.3" + versionCode 174 + versionName "3.8.0" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From ee4b92a2c544f648b62fd98f3030bc8283f2020f Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Apr 2018 23:47:10 +0200 Subject: [PATCH 060/111] updating changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1babfb9c4..3822d1105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========== +Version 3.8.0 *(2018-04-22)* +---------------------------- + + * Rewrote media caching for better performance + * Cache all media items, not just 80 per folder + * Some additional performance and stability improvements + Version 3.7.3 *(2018-04-15)* ---------------------------- From 3aaa17a02d050b137a5751772bba18d6ad70dc40 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 10:10:34 +0200 Subject: [PATCH 061/111] fixing a couple crashes --- .../gallery/activities/MediaActivity.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 2d9becbeb..aa9580b9a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -42,6 +42,7 @@ import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException +import java.util.* class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private val LAST_MEDIA_CHECK_PERIOD = 3000L @@ -458,7 +459,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { if (!mLoadedInitialPhotos) { getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent) { if (it.isEmpty()) { - media_refresh_layout.isRefreshing = true + runOnUiThread { + media_refresh_layout.isRefreshing = true + } } else { gotMedia(it, true) } @@ -634,7 +637,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - galleryDB.MediumDao().insertAll(media) + try { + galleryDB.MediumDao().insertAll(media) + } catch (e: ConcurrentModificationException) { + } } }.start() From 4f724786b2ea80d01ee349025e7fe640d62c8994 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 13:31:26 +0200 Subject: [PATCH 062/111] fix media inserting ConcurrentModificationException in a proper way --- .../simplemobiletools/gallery/activities/MediaActivity.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 aa9580b9a..6d2ae0170 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -633,14 +633,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun gotMedia(media: ArrayList, isFromCache: Boolean = false) { + val mediaToInsert = media.clone() as ArrayList Thread { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - try { - galleryDB.MediumDao().insertAll(media) - } catch (e: ConcurrentModificationException) { - } + galleryDB.MediumDao().insertAll(mediaToInsert) } }.start() From a4f62ffcd9d61e1a6e03e42829e7d41c33f7a765 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 16:05:54 +0200 Subject: [PATCH 063/111] recheck cached folders at startup one by one --- .../gallery/activities/MainActivity.kt | 70 +++++++++++++++++-- .../asynctasks/GetDirectoriesAsynctask.kt | 24 +------ .../gallery/extensions/ArrayList.kt | 23 ++++++ .../gallery/extensions/Context.kt | 42 ++++++----- .../gallery/interfaces/DirectoryDao.kt | 3 + .../gallery/interfaces/MediumDao.kt | 2 +- .../gallery/models/Directory.kt | 8 +-- 7 files changed, 123 insertions(+), 49 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt 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 e24681ea3..a1c8d58a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -16,10 +16,7 @@ import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.PERMISSION_READ_STORAGE -import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE -import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED -import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release @@ -34,6 +31,7 @@ import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory +import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_main.* import java.io.* @@ -587,7 +585,69 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { setupAdapter() } - if (!isFromCache) { + if (isFromCache) { + Thread { + val mediaFetcher = MediaFetcher(applicationContext) + val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent + val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent + val hidden = getString(R.string.hidden) + val albumCovers = config.parseAlbumCovers() + val hasOTG = hasOTGConnected() && config.OTGBasePath.isNotEmpty() + val includedFolders = config.includedFolders + + for (directory in dirs) { + val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly) + Medium.sorting = config.getFileSorting(directory.path) + curMedia.sort() + + val firstItem = curMedia.first() + val lastItem = curMedia.last() + val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { + firstItem.parentPath + } else { + File(firstItem.path).parent + } ?: continue + + var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: "" + if (thumbnail.startsWith(OTG_PATH)) { + thumbnail = thumbnail.getOTGPublicPath(applicationContext) + } + + albumCovers.forEach { + if (it.path == parentDir && getDoesFilePathExist(it.tmb)) { + thumbnail = it.tmb + } + } + + val mediaTypes = curMedia.getDirMediaTypes() + val dirName = checkAppendingHidden(parentDir, hidden, includedFolders) + val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) + val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) + val size = curMedia.sumByLong { it.size } + val newDir = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(parentDir), mediaTypes) + directory.mediaCnt = curMedia.size + if (directory == newDir) { + continue + } + + directory.apply { + tmb = thumbnail + mediaCnt = curMedia.size + modified = lastModified + taken = dateTaken + this@apply.size = size + types = mediaTypes + } + + updateDirectory(directory) + rescanFolderMediaSync(directory.path) + val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + runOnUiThread { + (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) + } + } + }.start() + } else { storeDirectories() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index f3c06916a..64b8d9756 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,10 +10,8 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.getDirMediaTypes import com.simplemobiletools.gallery.helpers.MediaFetcher -import com.simplemobiletools.gallery.helpers.TYPE_GIFS -import com.simplemobiletools.gallery.helpers.TYPE_IMAGES -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -58,8 +56,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } } - val mediaTypes = getDirMediaTypes(curMedia) - + val mediaTypes = curMedia.getDirMediaTypes() val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders) val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) @@ -71,23 +68,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va return directories } - private fun getDirMediaTypes(media: ArrayList): Int { - var types = 0 - if (media.any { it.isImage() }) { - types += TYPE_IMAGES - } - - if (media.any { it.isVideo() }) { - types += TYPE_VIDEOS - } - - if (media.any { it.isGif() }) { - types += TYPE_GIFS - } - - return types - } - override fun onPostExecute(dirs: ArrayList) { super.onPostExecute(dirs) callback(dirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt new file mode 100644 index 000000000..afd1c36e5 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/ArrayList.kt @@ -0,0 +1,23 @@ +package com.simplemobiletools.gallery.extensions + +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS +import com.simplemobiletools.gallery.models.Medium + +fun ArrayList.getDirMediaTypes(): Int { + var types = 0 + if (any { it.isImage() }) { + types += TYPE_IMAGES + } + + if (any { it.isVideo() }) { + types += TYPE_VIDEOS + } + + if (any { it.isGif() }) { + types += TYPE_GIFS + } + + return types +} 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 7b261c90d..6c13c28eb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -135,25 +135,29 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList) -> Unit) { fun Context.rescanFolderMedia(path: String) { Thread { - getCachedMedia(path) { - val cached = it - GetMediaAsynctask(applicationContext, path, false, false, false) { - Thread { - val newMedia = it - val mediumDao = galleryDB.MediumDao() - mediumDao.insertAll(newMedia) - - cached.forEach { - if (!newMedia.contains(it)) { - mediumDao.deleteMediumPath(it.path) - } - } - }.start() - }.execute() - } + rescanFolderMediaSync(path) }.start() } +fun Context.rescanFolderMediaSync(path: String) { + getCachedMedia(path) { + val cached = it + GetMediaAsynctask(applicationContext, path, false, false, false) { + Thread { + val newMedia = it + val mediumDao = galleryDB.MediumDao() + mediumDao.insertAll(newMedia) + + cached.forEach { + if (!newMedia.contains(it)) { + mediumDao.deleteMediumPath(it.path) + } + } + }.start() + }.execute() + } +} + fun Context.updateStoredDirectories() { GetDirectoriesAsynctask(this, false, false) { if (!config.temporarilyShowHidden) { @@ -317,5 +321,9 @@ fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directo fun Context.updateMediaPath(oldPath: String, newPath: String) { val newFilename = newPath.getFilenameFromPath() val newParentPath = newPath.getParentPath() - galleryDB.MediumDao().updateMedia(oldPath, newParentPath, newFilename, newPath) + galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath) +} + +fun Context.updateDirectory(directory: Directory) { + galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index a8172a8b5..0d996ad3d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -23,4 +23,7 @@ interface DirectoryDao { @Query("DELETE FROM directories WHERE path = :path") fun deleteDirPath(path: String) + + @Query("UPDATE OR REPLACE directories SET thumbnail = :thumbnail, media_count = :mediaCnt, last_modified = :lastModified, date_taken = :dateTaken, size = :size, media_types = :mediaTypes WHERE path = :path") + fun updateDirectory(path: String, thumbnail: String, mediaCnt: Int, lastModified: Long, dateTaken: Long, size: Long, mediaTypes: Int) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index da7612e52..eee0430c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -24,5 +24,5 @@ interface MediumDao { fun deleteMediumPath(path: String) @Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath") - fun updateMedia(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) + fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 27c15d62e..ef02bdfc8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -16,11 +16,11 @@ data class Directory( @ColumnInfo(name = "thumbnail") var tmb: String, @ColumnInfo(name = "filename") var name: String, @ColumnInfo(name = "media_count") var mediaCnt: Int, - @ColumnInfo(name = "last_modified") val modified: Long, - @ColumnInfo(name = "date_taken") val taken: Long, - @ColumnInfo(name = "size") val size: Long, + @ColumnInfo(name = "last_modified") var modified: Long, + @ColumnInfo(name = "date_taken") var taken: Long, + @ColumnInfo(name = "size") var size: Long, @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean, - @ColumnInfo(name = "media_types") val types: Int) : Serializable, Comparable { + @ColumnInfo(name = "media_types") var types: Int) : Serializable, Comparable { companion object { private const val serialVersionUID = -6553345863555455L From 64fe17d1b95ab4b1b9edfc85e253f7efd0129bda Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 16:16:46 +0200 Subject: [PATCH 064/111] store fetched media in db right after getting folders --- .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 64b8d9756..cb2436672 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.galleryDB import com.simplemobiletools.gallery.extensions.getDirMediaTypes import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Directory @@ -45,6 +46,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va File(firstItem.path).parent } ?: continue + context.galleryDB.MediumDao().insertAll(curMedia) var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: "" if (thumbnail.startsWith(OTG_PATH)) { thumbnail = thumbnail.getOTGPublicPath(context) From cfa2f82066a4a46a531aab3100269b14f0565c7f Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 16:42:45 +0200 Subject: [PATCH 065/111] small code cleanup at MediaFetcher --- .../gallery/helpers/MediaFetcher.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 172bbcc81..2b093ec75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -14,7 +14,6 @@ import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.LinkedHashMap import kotlin.collections.ArrayList -import kotlin.collections.HashSet import kotlin.collections.set class MediaFetcher(val context: Context) { @@ -44,7 +43,15 @@ class MediaFetcher(val context: Context) { return try { val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - parseCursor(context, cursor, isPickImage, isPickVideo, curPath, filterMedia) + val curMedia = ArrayList() + val foldersToScan = getFoldersToScan(context, cursor, curPath) + foldersToScan.forEach { + fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) + } + + Medium.sorting = context.config.getFileSorting(curPath) + curMedia.sort() + curMedia } catch (e: Exception) { ArrayList() } @@ -105,10 +112,10 @@ class MediaFetcher(val context: Context) { return args } - private fun parseCursor(context: Context, cursor: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String, filterMedia: Int): ArrayList { + private fun getFoldersToScan(context: Context, cursor: Cursor, curPath: String): ArrayList { val config = context.config val includedFolders = config.includedFolders - val foldersToScan = HashSet() + var foldersToScan = ArrayList() cursor.use { if (cursor.moveToFirst()) { @@ -130,24 +137,17 @@ class MediaFetcher(val context: Context) { } } - val curMedia = ArrayList() val showHidden = config.shouldShowHidden val excludedFolders = config.excludedFolders - foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden) }.toList().forEach { - fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) + foldersToScan = foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden) } as ArrayList + if (config.isThirdPartyIntent && curPath.isNotEmpty()) { + foldersToScan.add(curPath) } - if (config.isThirdPartyIntent && curPath.isNotEmpty() && curMedia.isEmpty()) { - getMediaInFolder(curPath, curMedia, isPickImage, isPickVideo, filterMedia) - } - - Medium.sorting = config.getFileSorting(curPath) - curMedia.sort() - - return curMedia + return foldersToScan } - private fun addFolder(curFolders: HashSet, folder: String) { + private fun addFolder(curFolders: ArrayList, folder: String) { curFolders.add(folder) val files = File(folder).listFiles() ?: return for (file in files) { From 8399b4fccdd035e1c1c716c5fbedecc4f86bd234 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 16:50:17 +0200 Subject: [PATCH 066/111] refactoring MediaFetcher once again --- .../gallery/helpers/MediaFetcher.kt | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 2b093ec75..82109e20c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -30,32 +30,35 @@ class MediaFetcher(val context: Context) { return ArrayList() } + val curMedia = ArrayList() if (curPath.startsWith(OTG_PATH)) { - val curMedia = ArrayList() getMediaOnOTG(curPath, curMedia, isPickImage, isPickVideo, filterMedia) - return curMedia } else { - val projection = arrayOf(MediaStore.Images.Media.DATA) - val uri = MediaStore.Files.getContentUri("external") - - val selection = "${getSelectionQuery(curPath, filterMedia)} ${MediaStore.Images.ImageColumns.BUCKET_ID} IS NOT NULL) GROUP BY (${MediaStore.Images.ImageColumns.BUCKET_ID}" - val selectionArgs = getSelectionArgsQuery(curPath, filterMedia).toTypedArray() - - return try { - val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - val curMedia = ArrayList() - val foldersToScan = getFoldersToScan(context, cursor, curPath) - foldersToScan.forEach { - fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) - } - - Medium.sorting = context.config.getFileSorting(curPath) - curMedia.sort() - curMedia - } catch (e: Exception) { - ArrayList() + val foldersToScan = getFoldersToScan(curPath) + foldersToScan.forEach { + fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) } } + + Medium.sorting = context.config.getFileSorting(curPath) + curMedia.sort() + return curMedia + } + + private fun getFoldersToScan(path: String): ArrayList { + val filterMedia = context.config.filterMedia + val projection = arrayOf(MediaStore.Images.Media.DATA) + val uri = MediaStore.Files.getContentUri("external") + + val selection = "${getSelectionQuery(path, filterMedia)} ${MediaStore.Images.ImageColumns.BUCKET_ID} IS NOT NULL) GROUP BY (${MediaStore.Images.ImageColumns.BUCKET_ID}" + val selectionArgs = getSelectionArgsQuery(path, filterMedia).toTypedArray() + + return try { + val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) + parseCursor(cursor, path) + } catch (e: Exception) { + ArrayList() + } } private fun getSelectionQuery(path: String, filterMedia: Int): String { @@ -112,7 +115,7 @@ class MediaFetcher(val context: Context) { return args } - private fun getFoldersToScan(context: Context, cursor: Cursor, curPath: String): ArrayList { + private fun parseCursor(cursor: Cursor, curPath: String): ArrayList { val config = context.config val includedFolders = config.includedFolders var foldersToScan = ArrayList() From a6437181cb1561032f7b889427d920851c18b389 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 22:43:01 +0200 Subject: [PATCH 067/111] rewrite the way directories are fetched --- .../gallery/activities/MainActivity.kt | 219 ++++++++++-------- .../gallery/activities/MediaActivity.kt | 2 - .../gallery/activities/ViewPagerActivity.kt | 2 +- .../gallery/adapters/MediaAdapter.kt | 2 +- .../asynctasks/GetDirectoriesAsynctask.kt | 2 - .../gallery/extensions/Activity.kt | 2 +- .../gallery/extensions/Context.kt | 13 +- .../gallery/helpers/MediaFetcher.kt | 36 +-- 8 files changed, 143 insertions(+), 135 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 a1c8d58a7..9522b8bc3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -25,11 +25,11 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter -import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* +import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_main.* @@ -58,7 +58,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mLatestMediaDateId = 0L private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() - private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mStoredAnimateGifs = true @@ -185,10 +184,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.temporarilyShowHidden = false mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() - - if (!mDirs.isEmpty()) { - mCurrAsyncTask?.stopFetching() - } } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -275,25 +270,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent - if (!mLoadedInitialPhotos) { - getCachedDirectories(getVideosOnly, getImagesOnly) { - if (it.isNotEmpty()) { - gotDirectories(it, true) + getCachedDirectories(getVideosOnly, getImagesOnly) { + if (!mLoadedInitialPhotos) { + runOnUiThread { + directories_refresh_layout.isRefreshing = true } } + gotDirectories(it) } - - if (!mLoadedInitialPhotos) { - directories_refresh_layout.isRefreshing = true - } - - mLoadedInitialPhotos = true - mCurrAsyncTask?.stopFetching() - mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, getVideosOnly, getImagesOnly) { - mCurrAsyncTask = null - gotDirectories(addTempFolderIfNeeded(it), false) - } - mCurrAsyncTask!!.execute() } private fun showSortingDialog() { @@ -301,7 +285,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) { getDirectories() } else { - gotDirectories(mDirs, true) + gotDirectories(mDirs) } } } @@ -338,7 +322,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { invalidateOptionsMenu() setupLayoutManager() directories_grid.adapter = null - setupAdapter() + setupAdapter(getCurrentlyDisplayedDirs()) } } @@ -365,6 +349,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { runOnUiThread { refreshItems() } + Thread { folders.filter { !it.exists() }.forEach { galleryDB.DirectoryDao().deleteDirPath(it.absolutePath) @@ -429,7 +414,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden) { CreateNewFolderDialog(this, it) { config.tempFolderPath = it - gotDirectories(addTempFolderIfNeeded(mDirs), true) + gotDirectories(addTempFolderIfNeeded(mDirs)) } } } @@ -561,116 +546,146 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - private fun gotDirectories(newDirs: ArrayList, isFromCache: Boolean) { - if (!isFromCache) { - Thread { - galleryDB.DirectoryDao().insertAll(newDirs) - }.start() - } - + private fun gotDirectories(newDirs: ArrayList) { val dirs = getSortedDirectories(newDirs) - mIsGettingDirs = false - checkLastMediaChanged() - mDirs = dirs + var isPlaceholderVisible = dirs.isEmpty() runOnUiThread { - directories_refresh_layout.isRefreshing = false - directories_empty_text_label.beVisibleIf(dirs.isEmpty() && !isFromCache) - directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache) + directories_empty_text_label.beVisibleIf(dirs.isEmpty()) + directories_empty_text.beVisibleIf(dirs.isEmpty()) directories_grid.beVisibleIf(directories_empty_text_label.isGone()) val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) - setupAdapter() + setupAdapter(dirs) } - if (isFromCache) { - Thread { - val mediaFetcher = MediaFetcher(applicationContext) - val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent - val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent - val hidden = getString(R.string.hidden) - val albumCovers = config.parseAlbumCovers() - val hasOTG = hasOTGConnected() && config.OTGBasePath.isNotEmpty() - val includedFolders = config.includedFolders + // cached folders have been loaded, recheck folders one by one starting with the first displayed + Thread { + val mediaFetcher = MediaFetcher(applicationContext) + val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent + val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent + val hiddenString = getString(R.string.hidden) + val albumCovers = config.parseAlbumCovers() + val includedFolders = config.includedFolders + val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 + val mediumDao = galleryDB.MediumDao() + val directoryDao = galleryDB.DirectoryDao() - for (directory in dirs) { - val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly) - Medium.sorting = config.getFileSorting(directory.path) - curMedia.sort() + for (directory in dirs) { + val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly) + val newDir = createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) - val firstItem = curMedia.first() - val lastItem = curMedia.last() - val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { - firstItem.parentPath - } else { - File(firstItem.path).parent - } ?: continue + // we are looping through the already displayed folders looking for changes, do not do anything if nothing changed + if (directory == newDir) { + continue + } - var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: "" - if (thumbnail.startsWith(OTG_PATH)) { - thumbnail = thumbnail.getOTGPublicPath(applicationContext) - } + directory.apply { + tmb = newDir.tmb + mediaCnt = newDir.mediaCnt + modified = newDir.modified + taken = newDir.taken + this@apply.size = newDir.size + types = newDir.types + } - albumCovers.forEach { - if (it.path == parentDir && getDoesFilePathExist(it.tmb)) { - thumbnail = it.tmb + showSortedDirs(dirs) + + // update directories and media files in the local db, delete invalid items + updateDBDirectory(directory) + mediumDao.insertAll(curMedia) + getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { + it.forEach { + if (!curMedia.contains(it)) { + mediumDao.deleteMediumPath(it.path) } } + } + } - val mediaTypes = curMedia.getDirMediaTypes() - val dirName = checkAppendingHidden(parentDir, hidden, includedFolders) - val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) - val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) - val size = curMedia.sumByLong { it.size } - val newDir = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(parentDir), mediaTypes) - directory.mediaCnt = curMedia.size - if (directory == newDir) { - continue - } + val foldersToScan = mediaFetcher.getFoldersToScan("") + dirs.forEach { + foldersToScan.remove(it.path) + } - directory.apply { - tmb = thumbnail - mediaCnt = curMedia.size - modified = lastModified - taken = dateTaken - this@apply.size = size - types = mediaTypes - } + for (folder in foldersToScan) { + val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly) + if (newMedia.isEmpty()) { + continue + } - updateDirectory(directory) - rescanFolderMediaSync(directory.path) - val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + if (isPlaceholderVisible) { + isPlaceholderVisible = false runOnUiThread { - (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) + directories_empty_text_label.beGone() + directories_empty_text.beGone() + directories_grid.beVisible() } } - }.start() - } else { - storeDirectories() + + val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + dirs.add(newDir) + showSortedDirs(dirs) + directoryDao.insert(newDir) + mediumDao.insertAll(newMedia) + } + + mIsGettingDirs = false + mLoadedInitialPhotos = true + + runOnUiThread { + directories_refresh_layout.isRefreshing = false + directories_vertical_fastscroller.measureRecyclerView() + } + }.start() + } + + private fun showSortedDirs(dirs: ArrayList) { + val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + runOnUiThread { + (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) } } - private fun storeDirectories() { - if (!config.temporarilyShowHidden && config.tempFolderPath.isEmpty()) { - storeDirectoryItems(mDirs) + private fun createDirectoryFromMedia(path: String, curMedia: ArrayList, albumCovers: ArrayList, hiddenString: String, + includedFolders: MutableSet, isSortingAscending: Boolean): Directory { + var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: "" + if (thumbnail.startsWith(OTG_PATH)) { + thumbnail = thumbnail.getOTGPublicPath(applicationContext) } + + albumCovers.forEach { + if (it.path == path && getDoesFilePathExist(it.tmb)) { + thumbnail = it.tmb + } + } + + val mediaTypes = curMedia.getDirMediaTypes() + val dirName = checkAppendingHidden(path, hiddenString, includedFolders) + + val firstItem = curMedia.first() + val lastItem = curMedia.last() + val lastModified = if (!isSortingAscending) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) + val dateTaken = if (!isSortingAscending) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) + val size = curMedia.sumByLong { it.size } + return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes) } - private fun setupAdapter() { + private fun setupAdapter(dirs: ArrayList) { val currAdapter = directories_grid.adapter if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller - DirectoryAdapter(this, mDirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { + DirectoryAdapter(this, dirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { itemClicked((it as Directory).path) }.apply { setupZoomListener(mZoomListener) directories_grid.adapter = this } } else { - (currAdapter as DirectoryAdapter).updateDirs(mDirs) + (currAdapter as DirectoryAdapter).updateDirs(dirs) } setupScrollDirection() @@ -698,6 +713,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList() + private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" private fun setupLatestMediaId() { @@ -714,7 +731,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { return } - mLastMediaHandler.postDelayed({ + /*mLastMediaHandler.postDelayed({ Thread { val mediaId = getLatestMediaId() val mediaDateId = getLatestMediaByDateId() @@ -729,7 +746,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { checkLastMediaChanged() } }.start() - }, LAST_MEDIA_CHECK_PERIOD) + }, LAST_MEDIA_CHECK_PERIOD)*/ } override fun refreshItems() { @@ -737,12 +754,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } override fun recheckPinnedFolders() { - gotDirectories(movePinnedDirectoriesToFront(mDirs), true) + gotDirectories(movePinnedDirectoriesToFront(mDirs)) } override fun updateDirectories(directories: ArrayList, refreshList: Boolean) { if (refreshList) { - gotDirectories(directories, true) + gotDirectories(directories) } else { mDirs = directories } 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 6d2ae0170..471c57b2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -669,8 +669,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { deleteDirectoryIfEmpty() finish() } else { - updateStoredDirectories() - Thread { val mediumDao = galleryDB.MediumDao() filtered.forEach { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 81ea68367..d483b3928 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -765,7 +765,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } Thread { - updateMediaPath(oldPath, it) + updateDBMediaPath(oldPath, it) }.start() updateActionbarTitle() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 72fa360af..46369f095 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -151,7 +151,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val oldPath = getCurrentPath() RenameItemDialog(activity, oldPath) { Thread { - activity.updateMediaPath(oldPath, it) + activity.updateDBMediaPath(oldPath, it) }.start() activity.runOnUiThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index cb2436672..64b8d9756 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -10,7 +10,6 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.checkAppendingHidden import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.galleryDB import com.simplemobiletools.gallery.extensions.getDirMediaTypes import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Directory @@ -46,7 +45,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va File(firstItem.path).parent } ?: continue - context.galleryDB.MediumDao().insertAll(curMedia) var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: "" if (thumbnail.startsWith(OTG_PATH)) { thumbnail = thumbnail.getOTGPublicPath(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index b6ecd4d35..a311c9a22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -152,7 +152,7 @@ fun BaseSimpleActivity.toggleFileVisibility(oldPath: String, hide: Boolean, call renameFile(oldPath, newPath) { callback?.invoke(newPath) Thread { - updateMediaPath(oldPath, newPath) + updateDBMediaPath(oldPath, newPath) }.start() } } 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 6c13c28eb..9c0afe20b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -19,7 +19,6 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SettingsActivity -import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.helpers.* @@ -158,14 +157,6 @@ fun Context.rescanFolderMediaSync(path: String) { } } -fun Context.updateStoredDirectories() { - GetDirectoriesAsynctask(this, false, false) { - if (!config.temporarilyShowHidden) { - storeDirectoryItems(it) - } - }.execute() -} - fun Context.storeDirectoryItems(items: ArrayList) { Thread { galleryDB.DirectoryDao().insertAll(items) @@ -318,12 +309,12 @@ fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directo } } -fun Context.updateMediaPath(oldPath: String, newPath: String) { +fun Context.updateDBMediaPath(oldPath: String, newPath: String) { val newFilename = newPath.getFilenameFromPath() val newParentPath = newPath.getParentPath() galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath) } -fun Context.updateDirectory(directory: Directory) { +fun Context.updateDBDirectory(directory: Directory) { galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 82109e20c..0ce4332a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -32,12 +32,11 @@ class MediaFetcher(val context: Context) { val curMedia = ArrayList() if (curPath.startsWith(OTG_PATH)) { - getMediaOnOTG(curPath, curMedia, isPickImage, isPickVideo, filterMedia) + val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia) + curMedia.addAll(newMedia) } else { - val foldersToScan = getFoldersToScan(curPath) - foldersToScan.forEach { - fetchFolderContent(it, curMedia, isPickImage, isPickVideo, filterMedia) - } + val newMedia = fetchFolderContent(curPath, isPickImage, isPickVideo, filterMedia) + curMedia.addAll(newMedia) } Medium.sorting = context.config.getFileSorting(curPath) @@ -45,7 +44,7 @@ class MediaFetcher(val context: Context) { return curMedia } - private fun getFoldersToScan(path: String): ArrayList { + fun getFoldersToScan(path: String): ArrayList { val filterMedia = context.config.filterMedia val projection = arrayOf(MediaStore.Images.Media.DATA) val uri = MediaStore.Files.getContentUri("external") @@ -160,11 +159,11 @@ class MediaFetcher(val context: Context) { } } - private fun fetchFolderContent(path: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { - if (path.startsWith(OTG_PATH)) { - getMediaOnOTG(path, curMedia, isPickImage, isPickVideo, filterMedia) + private fun fetchFolderContent(path: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList { + return if (path.startsWith(OTG_PATH)) { + getMediaOnOTG(path, isPickImage, isPickVideo, filterMedia) } else { - getMediaInFolder(path, curMedia, isPickImage, isPickVideo, filterMedia) + getMediaInFolder(path, isPickImage, isPickVideo, filterMedia) } } @@ -185,8 +184,9 @@ class MediaFetcher(val context: Context) { return directories } - private fun getMediaInFolder(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { - val files = File(folder).listFiles() ?: return + private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList { + val media = ArrayList() + val files = File(folder).listFiles() ?: return media val doExtraCheck = context.config.doExtraCheck val showHidden = context.config.shouldShowHidden @@ -229,12 +229,14 @@ class MediaFetcher(val context: Context) { } val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type) - curMedia.add(medium) + media.add(medium) } + return media } - private fun getMediaOnOTG(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { - val files = context.getDocumentFile(folder)?.listFiles() ?: return + private fun getMediaOnOTG(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList { + val media = ArrayList() + val files = context.getDocumentFile(folder)?.listFiles() ?: return media val doExtraCheck = context.config.doExtraCheck val showHidden = context.config.shouldShowHidden @@ -278,7 +280,9 @@ class MediaFetcher(val context: Context) { val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type) - curMedia.add(medium) + media.add(medium) } + + return media } } From cde57f35b84fa1ed52e5d810720838e137662e94 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 23:05:57 +0200 Subject: [PATCH 068/111] store new images from refresh_media broadcast in the local db --- app/build.gradle | 2 +- .../gallery/receivers/RefreshMediaReceiver.kt | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c1e93b509..61e0ff749 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.9' + implementation 'com.simplemobiletools:commons:3.19.10' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt index 7163a5af5..8b3f9921e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -3,13 +3,32 @@ package com.simplemobiletools.gallery.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.extensions.storeDirectoryItems +import com.simplemobiletools.commons.extensions.getFilenameFromPath +import com.simplemobiletools.commons.extensions.getParentPath +import com.simplemobiletools.commons.extensions.isImageFast +import com.simplemobiletools.commons.extensions.isVideoFast +import com.simplemobiletools.commons.helpers.REFRESH_PATH +import com.simplemobiletools.gallery.extensions.galleryDB +import com.simplemobiletools.gallery.helpers.TYPE_GIFS +import com.simplemobiletools.gallery.helpers.TYPE_IMAGES +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS +import com.simplemobiletools.gallery.models.Medium +import java.io.File class RefreshMediaReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - GetDirectoriesAsynctask(context, false, false) { - context.storeDirectoryItems(it) - }.execute() + val path = intent.getStringExtra(REFRESH_PATH) ?: return + + Thread { + val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(), + File(path).length(), getFileType(path)) + context.galleryDB.MediumDao().insert(medium) + }.start() + } + + private fun getFileType(path: String) = when { + path.isImageFast() -> TYPE_IMAGES + path.isVideoFast() -> TYPE_VIDEOS + else -> TYPE_GIFS } } From 24f14fffc45b15312f676245b5493e42f82208eb Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 23 Apr 2018 23:35:07 +0200 Subject: [PATCH 069/111] remove GetDirectoriesAsynctask --- .../gallery/activities/MainActivity.kt | 2 + .../asynctasks/GetDirectoriesAsynctask.kt | 80 ------------------- .../gallery/asynctasks/GetMediaAsynctask.kt | 8 +- .../gallery/dialogs/PickDirectoryDialog.kt | 5 -- .../gallery/helpers/MediaFetcher.kt | 25 ------ 5 files changed, 6 insertions(+), 114 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt 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 9522b8bc3..e43b63b56 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -25,6 +25,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter +import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* @@ -184,6 +185,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.temporarilyShowHidden = false mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() + GalleryDataBase.destroyInstance() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt deleted file mode 100644 index 64b8d9756..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.simplemobiletools.gallery.asynctasks - -import android.content.Context -import android.os.AsyncTask -import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH -import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE -import com.simplemobiletools.commons.helpers.SORT_DESCENDING -import com.simplemobiletools.commons.helpers.sumByLong -import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.extensions.checkAppendingHidden -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.getDirMediaTypes -import com.simplemobiletools.gallery.helpers.MediaFetcher -import com.simplemobiletools.gallery.models.Directory -import com.simplemobiletools.gallery.models.Medium -import java.io.File - -class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, val isPickImage: Boolean, - val callback: (dirs: ArrayList) -> Unit) : AsyncTask>() { - private val mediaFetcher = MediaFetcher(context) - - override fun doInBackground(vararg params: Void): ArrayList { - if (!context.hasPermission(PERMISSION_WRITE_STORAGE)) { - return ArrayList() - } - - val config = context.config - val groupedMedia = mediaFetcher.getMediaByDirectories(isPickVideo, isPickImage) - val directories = ArrayList() - val hidden = context.getString(R.string.hidden) - val albumCovers = config.parseAlbumCovers() - val hasOTG = context.hasOTGConnected() && context.config.OTGBasePath.isNotEmpty() - val includedFolders = config.includedFolders - - for ((path, curMedia) in groupedMedia) { - Medium.sorting = config.getFileSorting(path) - curMedia.sort() - - val firstItem = curMedia.first() - val lastItem = curMedia.last() - val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { - firstItem.parentPath - } else { - File(firstItem.path).parent - } ?: continue - - var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: "" - if (thumbnail.startsWith(OTG_PATH)) { - thumbnail = thumbnail.getOTGPublicPath(context) - } - - albumCovers.forEach { - if (it.path == parentDir && context.getDoesFilePathExist(it.tmb)) { - thumbnail = it.tmb - } - } - - val mediaTypes = curMedia.getDirMediaTypes() - val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders) - val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) - val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) - val size = curMedia.sumByLong { it.size } - val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir), mediaTypes) - directories.add(directory) - } - - return directories - } - - override fun onPostExecute(dirs: ArrayList) { - super.onPostExecute(dirs) - callback(dirs) - } - - fun stopFetching() { - mediaFetcher.shouldStop = true - cancel(true) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index a3b8a2b5d..d59ee1850 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -14,11 +14,11 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo override fun doInBackground(vararg params: Void): ArrayList { return if (showAll) { - val mediaMap = mediaFetcher.getMediaByDirectories(isPickVideo, isPickImage) + val foldersToScan = mediaFetcher.getFoldersToScan("") val media = ArrayList() - - mediaMap.values.forEach { - media.addAll(it) + for (folder in foldersToScan) { + val newMedia = mediaFetcher.getFilesFrom(folder, isPickImage, isPickVideo) + media.addAll(newMedia) } Medium.sorting = context.config.getFileSorting("") diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index 1ee74ba96..372a0483c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -11,7 +11,6 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter -import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.extensions.addTempFolderIfNeeded import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedDirectories @@ -47,10 +46,6 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri } } } - - GetDirectoriesAsynctask(activity, false, false) { - gotDirectories(activity.addTempFolderIfNeeded(it)) - }.execute() } private fun showOtherFolder() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 0ce4332a5..179262e30 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -12,18 +12,10 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.models.Medium import java.io.File -import java.util.LinkedHashMap -import kotlin.collections.ArrayList -import kotlin.collections.set class MediaFetcher(val context: Context) { var shouldStop = false - fun getMediaByDirectories(isPickVideo: Boolean, isPickImage: Boolean): HashMap> { - val media = getFilesFrom("", isPickImage, isPickVideo) - return groupDirectories(media) - } - fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean): ArrayList { val filterMedia = context.config.filterMedia if (filterMedia == 0) { @@ -167,23 +159,6 @@ class MediaFetcher(val context: Context) { } } - private fun groupDirectories(media: ArrayList): HashMap> { - val directories = LinkedHashMap>() - for (medium in media) { - if (shouldStop) { - break - } - - val parentDir = medium.parentPath.toLowerCase() - if (directories.containsKey(parentDir)) { - directories[parentDir]!!.add(medium) - } else { - directories[parentDir] = arrayListOf(medium) - } - } - return directories - } - private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList { val media = ArrayList() val files = File(folder).listFiles() ?: return media From 49b1a2408916f50e22465d228c969395a0d47c4b Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 09:30:51 +0200 Subject: [PATCH 070/111] do not show the No Media placeholders at first run --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 e43b63b56..ce85caaa2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -553,8 +553,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { var isPlaceholderVisible = dirs.isEmpty() runOnUiThread { - directories_empty_text_label.beVisibleIf(dirs.isEmpty()) - directories_empty_text.beVisibleIf(dirs.isEmpty()) + directories_empty_text_label.beVisibleIf(dirs.isEmpty() && config.appRunCount > 1) + directories_empty_text.beVisibleIf(dirs.isEmpty() && config.appRunCount > 1) directories_grid.beVisibleIf(directories_empty_text_label.isGone()) val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID From 07629186738a3bdd129108065b57359897a6c1ae Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 09:35:31 +0200 Subject: [PATCH 071/111] fix switching between grid and list view types --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ce85caaa2..ffc071dcd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -323,8 +323,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.viewTypeFolders = it as Int invalidateOptionsMenu() setupLayoutManager() + val dirs = getCurrentlyDisplayedDirs() directories_grid.adapter = null - setupAdapter(getCurrentlyDisplayedDirs()) + setupAdapter(dirs) } } From b4e1e0c0971ed44dc9fb2ccd646e14d5b952d2a3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 09:42:13 +0200 Subject: [PATCH 072/111] remove mDirs from the MainActivity --- .../gallery/activities/MainActivity.kt | 17 ++++------------- .../gallery/adapters/DirectoryAdapter.kt | 8 ++++---- 2 files changed, 8 insertions(+), 17 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 ffc071dcd..f64d84277 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -42,8 +42,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private val LAST_MEDIA_CHECK_PERIOD = 3000L private val NEW_APP_PACKAGE = "com.simplemobiletools.clock" - lateinit var mDirs: ArrayList - private var mIsPickImageIntent = false private var mIsPickVideoIntent = false private var mIsGetImageContentIntent = false @@ -86,7 +84,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { removeTempFolder() directories_refresh_layout.setOnRefreshListener { getDirectories() } - mDirs = ArrayList() storeStateVariables() checkWhatsNewDialog() @@ -287,7 +284,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) { getDirectories() } else { - gotDirectories(mDirs) + gotDirectories(getCurrentlyDisplayedDirs()) } } } @@ -417,7 +414,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden) { CreateNewFolderDialog(this, it) { config.tempFolderPath = it - gotDirectories(addTempFolderIfNeeded(mDirs)) + gotDirectories(addTempFolderIfNeeded(getCurrentlyDisplayedDirs())) } } } @@ -757,16 +754,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } override fun recheckPinnedFolders() { - gotDirectories(movePinnedDirectoriesToFront(mDirs)) + gotDirectories(movePinnedDirectoriesToFront(getCurrentlyDisplayedDirs())) } - override fun updateDirectories(directories: ArrayList, refreshList: Boolean) { - if (refreshList) { - gotDirectories(directories) - } else { - mDirs = directories - } - + override fun updateDirectories(directories: ArrayList) { Thread { storeDirectoryItems(directories) removeInvalidDirectories() 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 1d0529e1c..2da3bc1b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -171,7 +171,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList, refreshList: Boolean) + fun updateDirectories(directories: ArrayList) } } From b56d4d660026a628005e2f2a894aadf7430e54e7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 09:55:41 +0200 Subject: [PATCH 073/111] do not try parsing media files of empty lists --- .../gallery/activities/MainActivity.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 f64d84277..55a9aee4f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -575,7 +575,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { for (directory in dirs) { val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly) - val newDir = createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + val newDir = if (curMedia.isEmpty()) { + directory + } else { + createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + } // we are looping through the already displayed folders looking for changes, do not do anything if nothing changed if (directory == newDir) { @@ -667,8 +671,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val firstItem = curMedia.first() val lastItem = curMedia.last() - val lastModified = if (!isSortingAscending) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) - val dateTaken = if (!isSortingAscending) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) + val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified) + val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken) val size = curMedia.sumByLong { it.size } return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes) } From bd077cba8cd295dbda708f1b2599913fddb4619f Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 10:04:49 +0200 Subject: [PATCH 074/111] disable media pull-to-refresh while Search is open --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 2 ++ 1 file changed, 2 insertions(+) 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 471c57b2a..4b91853fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -260,11 +260,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem?): Boolean { mIsSearchOpen = true + media_refresh_layout.isEnabled = false return true } override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { mIsSearchOpen = false + media_refresh_layout.isEnabled = config.enablePullToRefresh return true } }) From e2fe74ea335b4b8b53d46fe24bd24e240d642b46 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 10:12:49 +0200 Subject: [PATCH 075/111] flip getImage and getVideo arguments at getMedia async task --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt | 2 +- .../com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 4b91853fa..c5357e42f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -474,7 +474,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLoadedInitialPhotos = true mCurrAsyncTask?.stopFetching() - mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mShowAll) { + mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) { gotMedia(it) } mCurrAsyncTask!!.execute() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index d59ee1850..8f82b4c00 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -7,7 +7,7 @@ import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium import java.util.* -class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo: Boolean = false, val isPickImage: Boolean = false, +class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage: Boolean = false, val isPickVideo: Boolean = false, val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : AsyncTask>() { private val mediaFetcher = MediaFetcher(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 0daec8e55..a717c3cfa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -45,7 +45,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c } } - GetMediaAsynctask(activity, path, false, true, false) { + GetMediaAsynctask(activity, path, true, false, false) { gotMedia(it) }.execute() } From 5d756b5a60f5bd72dc585b821f46d43e318e2eea Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 10:34:21 +0200 Subject: [PATCH 076/111] change the way allowBubbleDisplay is set on resume --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 +++- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 4 +++- 2 files changed, 6 insertions(+), 2 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 55a9aee4f..8c988eec6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -122,7 +122,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { getRecyclerAdapter()?.updateShowMediaCount(config.showMediaCount) } - if (mStoredScrollHorizontally != config.scrollHorizontally || mStoredShowInfoBubble != config.showInfoBubble) { + if (mStoredScrollHorizontally != config.scrollHorizontally) { getRecyclerAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally) setupScrollDirection() } @@ -139,6 +139,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_horizontal_fastscroller.updateBubbleColors() directories_vertical_fastscroller.updateBubbleColors() + directories_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble + directories_vertical_fastscroller.allowBubbleDisplay = config.showInfoBubble directories_refresh_layout.isEnabled = config.enablePullToRefresh invalidateOptionsMenu() directories_empty_text_label.setTextColor(config.textColor) 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 c5357e42f..4bc667bc5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -120,7 +120,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { getMediaAdapter()?.updateCropThumbnails(config.cropThumbnails) } - if (mStoredScrollHorizontally != config.scrollHorizontally || mStoredShowInfoBubble != config.showInfoBubble) { + if (mStoredScrollHorizontally != config.scrollHorizontally) { getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally) setupScrollDirection() } @@ -137,6 +137,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_horizontal_fastscroller.updateBubbleColors() media_vertical_fastscroller.updateBubbleColors() + media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble + media_vertical_fastscroller.allowBubbleDisplay = config.showInfoBubble media_refresh_layout.isEnabled = config.enablePullToRefresh tryloadGallery() invalidateOptionsMenu() From db2e0dc7766026773e0fd855fe49fa149dd3a211 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 10:36:50 +0200 Subject: [PATCH 077/111] disable Pull-to-refresh automatically at enabling horizontal scroll --- .../simplemobiletools/gallery/activities/SettingsActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 939e68f1d..e50c30caf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -203,6 +203,11 @@ class SettingsActivity : SimpleActivity() { settings_scroll_horizontally_holder.setOnClickListener { settings_scroll_horizontally.toggle() config.scrollHorizontally = settings_scroll_horizontally.isChecked + + if (config.scrollHorizontally) { + config.enablePullToRefresh = false + settings_enable_pull_to_refresh.isChecked = false + } } } From 85a0a69599c58552aa30cf40834b6679e73e9d06 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 13:15:41 +0200 Subject: [PATCH 078/111] show an icon at the folder for OTG devices too --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/adapters/DirectoryAdapter.kt | 13 +++++++------ .../gallery/databases/GalleryDataBase.kt | 6 ++++-- .../simplemobiletools/gallery/extensions/Context.kt | 10 +++++++++- .../simplemobiletools/gallery/helpers/Constants.kt | 4 ++++ .../gallery/interfaces/DirectoryDao.kt | 2 +- .../simplemobiletools/gallery/models/Directory.kt | 2 +- app/src/main/res/layout/directory_item_grid.xml | 2 +- app/src/main/res/layout/directory_item_list.xml | 2 +- 10 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 61e0ff749..7f7228180 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.10' + implementation 'com.simplemobiletools:commons:3.19.11' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 8c988eec6..9787cfbb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -676,7 +676,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified) val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken) val size = curMedia.sumByLong { it.size } - return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes) + return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes) } private fun setupAdapter(dirs: 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 2da3bc1b3..b49a9421f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -19,10 +19,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.TYPE_GIFS -import com.simplemobiletools.gallery.helpers.TYPE_IMAGES -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS -import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item_list.view.* @@ -420,7 +417,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList): ArrayList() val tempFolderPath = config.tempFolderPath if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath), 0) + val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, getPathLocation(tempFolderPath), 0) directories.add(newFolder) } directories.addAll(dirs) return directories } +fun Context.getPathLocation(path: String): Int { + return when { + isPathOnSD(path) -> LOCATION_SD + path.startsWith(OTG_PATH) -> LOCATION_OTG + else -> LOCAITON_INTERNAL + } +} + fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { val options = RequestOptions() .signature(path.getFileSignature()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index d75ce223d..12352ebf9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -102,3 +102,7 @@ const val EXT_ALBUM = 1024 const val TYPE_IMAGES = 1 const val TYPE_VIDEOS = 2 const val TYPE_GIFS = 4 + +const val LOCAITON_INTERNAL = 1 +const val LOCATION_SD = 2 +const val LOCATION_OTG = 3 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 0d996ad3d..7df52c96f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory @Dao interface DirectoryDao { - @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card, media_types FROM directories") + @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, location, media_types FROM directories") fun getAll(): List @Insert(onConflict = REPLACE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index ef02bdfc8..6d8c217a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -19,7 +19,7 @@ data class Directory( @ColumnInfo(name = "last_modified") var modified: Long, @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") var size: Long, - @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean, + @ColumnInfo(name = "location") val location: Int, @ColumnInfo(name = "media_types") var types: Int) : Serializable, Comparable { companion object { diff --git a/app/src/main/res/layout/directory_item_grid.xml b/app/src/main/res/layout/directory_item_grid.xml index 78ebc25e2..31d52f574 100644 --- a/app/src/main/res/layout/directory_item_grid.xml +++ b/app/src/main/res/layout/directory_item_grid.xml @@ -82,7 +82,7 @@ Date: Tue, 24 Apr 2018 14:32:21 +0200 Subject: [PATCH 079/111] use the more advanced way of checking if a file exists --- .../com/simplemobiletools/gallery/extensions/Context.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 27fe78b8b..c82f1d3b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -304,7 +304,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag }) as ArrayList callback(filteredMedia) - media.filter { !File(it.path).exists() }.forEach { + media.filter { !getDoesFilePathExist(it.path) }.forEach { mediumDao.deleteMediumPath(it.path) } }.start() @@ -312,7 +312,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !File(it.path).exists() }.forEach { + dirsToCheck.filter { !getDoesFilePathExist(it.path) }.forEach { directoryDao.deleteDirPath(it.path) } } From f9632749423758980c3840f1e00f0da4cc6303ab Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 14:34:51 +0200 Subject: [PATCH 080/111] ignore files with null name --- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 179262e30..2c3ea3dae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -220,7 +220,7 @@ class MediaFetcher(val context: Context) { break } - val filename = file.name + val filename = file.name ?: continue val isImage = filename.isImageFast() val isVideo = if (isImage) false else filename.isVideoFast() val isGif = if (isImage || isVideo) false else filename.isGif() From ddfbdaa275bbcb007099b9129ed55a9ebf4de928 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 14:54:28 +0200 Subject: [PATCH 081/111] look for invalid directories after loading --- .../gallery/activities/MainActivity.kt | 21 ++++++++++++++++++- .../gallery/extensions/Context.kt | 4 ++-- 2 files changed, 22 insertions(+), 3 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 9787cfbb8..ac235a8a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -30,6 +30,7 @@ import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* +import com.simplemobiletools.gallery.interfaces.DirectoryDao import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium @@ -640,6 +641,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGettingDirs = false mLoadedInitialPhotos = true + checkInvalidDirectories(dirs, directoryDao) runOnUiThread { directories_refresh_layout.isRefreshing = false @@ -719,6 +721,23 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + private fun checkInvalidDirectories(dirs: ArrayList, directoryDao: DirectoryDao) { + val invalidDirs = ArrayList() + dirs.forEach { + if (!getDoesFilePathExist(it.path)) { + invalidDirs.add(it) + } + } + + if (invalidDirs.isNotEmpty()) { + dirs.removeAll(invalidDirs) + showSortedDirs(dirs) + invalidDirs.forEach { + directoryDao.deleteDirPath(it.path) + } + } + } + private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList() private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" @@ -766,7 +785,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun updateDirectories(directories: ArrayList) { Thread { storeDirectoryItems(directories) - removeInvalidDirectories() + removeInvalidDBDirectories() }.start() } 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 c82f1d3b4..f2b48b5bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -278,7 +278,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: callback(filteredDirectories) - removeInvalidDirectories(directories, directoryDao) + removeInvalidDBDirectories(directories, directoryDao) }.start() } @@ -310,7 +310,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag }.start() } -fun Context.removeInvalidDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { +fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() dirsToCheck.filter { !getDoesFilePathExist(it.path) }.forEach { directoryDao.deleteDirPath(it.path) From cb17ab5b974bf5021cc5639db683687b033522ab Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 15:01:24 +0200 Subject: [PATCH 082/111] make sure the directory placeholder is visible only when appropriate --- .../gallery/activities/MainActivity.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 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 ac235a8a5..29a18a406 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -554,9 +554,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { var isPlaceholderVisible = dirs.isEmpty() runOnUiThread { - directories_empty_text_label.beVisibleIf(dirs.isEmpty() && config.appRunCount > 1) - directories_empty_text.beVisibleIf(dirs.isEmpty() && config.appRunCount > 1) - directories_grid.beVisibleIf(directories_empty_text_label.isGone()) + checkPlaceholderVisibility(dirs) val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) @@ -646,10 +644,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { runOnUiThread { directories_refresh_layout.isRefreshing = false directories_vertical_fastscroller.measureRecyclerView() + checkPlaceholderVisibility(dirs) } }.start() } + private fun checkPlaceholderVisibility(dirs: ArrayList) { + directories_empty_text_label.beVisibleIf(dirs.isEmpty() && mLoadedInitialPhotos) + directories_empty_text.beVisibleIf(dirs.isEmpty() && mLoadedInitialPhotos) + directories_grid.beVisibleIf(directories_empty_text_label.isGone()) + } + private fun showSortedDirs(dirs: ArrayList) { val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList runOnUiThread { From 6464c7eee4ae8aa805255bbb2daeee339322e550 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 17:08:41 +0200 Subject: [PATCH 083/111] try adding OTG automatically once --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 19 +++++++++++++++++++ .../gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 7f7228180..08a215ce4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.11' + implementation 'com.simplemobiletools:commons:3.19.12' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 29a18a406..357f5d184 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -100,6 +100,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.wasNewAppShown = true NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") }*/ + + if (hasPermission(PERMISSION_WRITE_STORAGE)) { + checkOTGInclusion() + } } override fun onStart() { @@ -246,6 +250,21 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + private fun checkOTGInclusion() { + if (!config.wasOTGHandled) { + Thread { + if (hasOTGConnected()) { + runOnUiThread { + handleOTGPermission { + config.addIncludedFolder(OTG_PATH) + } + } + config.wasOTGHandled = true + } + }.start() + } + } + private fun tryLoadGallery() { handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 86cd7caf8..596a672ab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -327,4 +327,8 @@ class Config(context: Context) : BaseConfig(context) { var lastFilepickerPath: String get() = prefs.getString(LAST_FILEPICKER_PATH, "") set(lastFilepickerPath) = prefs.edit().putString(LAST_FILEPICKER_PATH, lastFilepickerPath).apply() + + var wasOTGHandled: Boolean + get() = prefs.getBoolean(WAS_OTG_HANDLED, false) + set(wasOTGHandled) = prefs.edit().putBoolean(WAS_OTG_HANDLED, wasOTGHandled).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 12352ebf9..23d190fab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -47,6 +47,7 @@ const val REPLACE_ZOOMABLE_IMAGES = "replace_zoomable_images" const val DO_EXTRA_CHECK = "do_extra_check" const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock" const val LAST_FILEPICKER_PATH = "last_filepicker_path" +const val WAS_OTG_HANDLED = "was_otg_handled" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" From bab2b4e5a060bb22fba4e630b3cd09076739da38 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 17:47:24 +0200 Subject: [PATCH 084/111] check null folder children at DirectoryAdapter --- app/build.gradle | 2 +- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 4 +++- build.gradle | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08a215ce4..e8a87599d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.12' + implementation 'com.simplemobiletools:commons:3.19.14' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 b49a9421f..91d21b847 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -280,7 +280,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() selectedPositions.forEach { val dir = File(dirs[it].path) - paths.addAll(dir.listFiles().filter { !activity.getIsPathDirectory(it.absolutePath) && it.absolutePath.isImageVideoGif() }.map { it.absolutePath }) + val childrenFiles = dir.listFiles()?.filter { !activity.getIsPathDirectory(it.absolutePath) && it.absolutePath.isImageVideoGif() }?.map { it.absolutePath } + ?: ArrayList() + paths.addAll(childrenFiles) } val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList diff --git a/build.gradle b/build.gradle index a5b9d1ba6..1a38f0b61 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong From 0148465e7530d043427f50be6848734c986d35c2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 17:54:11 +0200 Subject: [PATCH 085/111] ignore REAL_FILE_PATH on OTG files --- .../com/simplemobiletools/gallery/activities/EditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 96f3e20ae..e54ba3251 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -66,7 +66,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (intent.extras?.containsKey(REAL_FILE_PATH) == true) { val realPath = intent.extras.getString(REAL_FILE_PATH) uri = when { - realPath.startsWith(OTG_PATH) -> Uri.parse(realPath) + realPath.startsWith(OTG_PATH) -> uri realPath.startsWith("file:/") -> Uri.parse(realPath) else -> Uri.fromFile(File(realPath)) } From 0b5005e0d014da454b2e8b70e43e3e31893ec953 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 19:02:55 +0200 Subject: [PATCH 086/111] couple SaveAs dialog related fixes --- app/build.gradle | 2 +- .../gallery/dialogs/SaveAsDialog.kt | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e8a87599d..36f8a1ffe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.14' + implementation 'com.simplemobiletools:commons:3.19.15' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt index 9fbd49fde..3199ff9d7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -7,7 +7,6 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import kotlinx.android.synthetic.main.dialog_save_as.view.* -import java.io.File class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) { @@ -15,7 +14,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appen var realPath = path.getParentPath() val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply { - save_as_path.text = activity.humanizePath(realPath) + save_as_path.text = "${activity.humanizePath(realPath).trimEnd('/')}/" val fullName = path.getFilenameFromPath() val dotAt = fullName.lastIndexOf(".") @@ -60,20 +59,21 @@ class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appen return@setOnClickListener } - val newFile = File(realPath, "$filename.$extension") - if (!newFile.name.isAValidFilename()) { + val newFilename = "$filename.$extension" + val newPath = "${realPath.trimEnd('/')}/$newFilename" + if (!newFilename.isAValidFilename()) { activity.toast(R.string.filename_invalid_characters) return@setOnClickListener } - if (newFile.exists()) { - val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name) + if (activity.getDoesFilePathExist(newPath)) { + val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) ConfirmationDialog(activity, title) { - callback(newFile.absolutePath) + callback(newPath) dismiss() } } else { - callback(newFile.absolutePath) + callback(newPath) dismiss() } } From bfc1d3d0fd6f4cdf1c79e663b0cce2a5e2aae0b4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 21:44:10 +0200 Subject: [PATCH 087/111] show a toast when deleting the empty new folder --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 ++ 1 file changed, 2 insertions(+) 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 357f5d184..a90ed9e49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -12,6 +12,7 @@ import android.view.Menu import android.view.MenuItem import android.view.ViewGroup import android.widget.FrameLayout +import android.widget.Toast import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog @@ -243,6 +244,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val newFolder = File(config.tempFolderPath) if (newFolder.exists() && newFolder.isDirectory) { if (newFolder.list()?.isEmpty() == true) { + toast(String.format(getString(R.string.deleting_folder), config.tempFolderPath), Toast.LENGTH_LONG) tryDeleteFileDirItem(newFolder.toFileDirItem(applicationContext), true) } } From 3f097a409be9322d5958e5cd8a4dbd2d688b0eff Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 21:44:47 +0200 Subject: [PATCH 088/111] couple improvements related to saving edited images --- .../gallery/activities/ViewPagerActivity.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index d483b3928..88a91869f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -45,7 +45,10 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_medium.* -import java.io.* +import java.io.File +import java.io.FileOutputStream +import java.io.InputStream +import java.io.OutputStream import java.util.* class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { @@ -527,7 +530,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - val newFile = File(newPath) val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}") try { @@ -539,22 +541,24 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val oldLastModified = getCurrentFile().lastModified() if (oldPath.isJpg()) { - copyFile(getCurrentFile(), tmpFile) + copyFile(getCurrentPath(), tmpFile.absolutePath) saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees) } else { - val bitmap = BitmapFactory.decodeFile(oldPath) + val inputstream = getFileInputStreamSync(oldPath) + val bitmap = BitmapFactory.decodeStream(inputstream) saveFile(tmpFile, bitmap, it as FileOutputStream) } if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) { tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath())) } - copyFile(tmpFile, newFile) + + copyFile(tmpFile.absolutePath, newPath) scanPath(newPath) toast(R.string.file_saved) if (config.keepLastModified) { - newFile.setLastModified(oldLastModified) + File(newPath).setLastModified(oldLastModified) updateLastModified(newPath, oldLastModified) } @@ -596,14 +600,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun copyFile(source: File, destination: File) { + private fun copyFile(source: String, destination: String) { var inputStream: InputStream? = null var out: OutputStream? = null try { - val fileDocument = if (isPathOnSD(destination.absolutePath)) getDocumentFile(destination.parent) else null - out = getFileOutputStreamSync(destination.absolutePath, source.getMimeType(), fileDocument) - inputStream = FileInputStream(source) - inputStream.copyTo(out!!) + out = getFileOutputStreamSync(destination, source.getMimeType()) + inputStream = getFileInputStreamSync(source) + inputStream?.copyTo(out!!) } finally { inputStream?.close() out?.close() From 68412e848080d489be4ef2c0a211d9c8af8e94ef Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 21:53:41 +0200 Subject: [PATCH 089/111] do not allow opening the freshly created folder while empty --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 a90ed9e49..86a61e771 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -713,7 +713,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller DirectoryAdapter(this, dirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { - itemClicked((it as Directory).path) + val path = (it as Directory).path + if (path != config.tempFolderPath) { + itemClicked(path) + } }.apply { setupZoomListener(mZoomListener) directories_grid.adapter = this From 55d7ccfe0363f01de3cd43e1e237c780e8606299 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 22:19:11 +0200 Subject: [PATCH 090/111] fix saving rotated otg files --- app/build.gradle | 2 +- .../gallery/activities/ViewPagerActivity.kt | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 36f8a1ffe..491206a45 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.15' + implementation 'com.simplemobiletools:commons:3.19.17' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 88a91869f..1c6a30d40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -530,10 +530,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}") - + val tmpPath = "$filesDir/.tmp_${newPath.getFilenameFromPath()}" + val tmpFileDirItem = FileDirItem(tmpPath, tmpPath.getFilenameFromPath()) try { - getFileOutputStream(tmpFile.toFileDirItem(applicationContext)) { + getFileOutputStream(tmpFileDirItem) { if (it == null) { toast(R.string.unknown_error_occurred) return@getFileOutputStream @@ -541,19 +541,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val oldLastModified = getCurrentFile().lastModified() if (oldPath.isJpg()) { - copyFile(getCurrentPath(), tmpFile.absolutePath) - saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees) + copyFile(getCurrentPath(), tmpPath) + saveExifRotation(ExifInterface(tmpPath), mRotationDegrees) } else { val inputstream = getFileInputStreamSync(oldPath) val bitmap = BitmapFactory.decodeStream(inputstream) - saveFile(tmpFile, bitmap, it as FileOutputStream) + saveFile(tmpPath, bitmap, it as FileOutputStream) } - if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) { + if (getDoesFilePathExist(newPath)) { tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath())) } - copyFile(tmpFile.absolutePath, newPath) + copyFile(tmpPath, newPath) scanPath(newPath) toast(R.string.file_saved) @@ -579,7 +579,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } catch (e: Exception) { showErrorToast(e) } finally { - tryDeleteFileDirItem(FileDirItem(tmpFile.absolutePath, tmpFile.absolutePath.getFilenameFromPath())) + tryDeleteFileDirItem(tmpFileDirItem) } } @@ -613,11 +613,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun saveFile(file: File, bitmap: Bitmap, out: FileOutputStream) { + private fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream) { val matrix = Matrix() matrix.postRotate(mRotationDegrees.toFloat()) val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) - bmp.compress(file.absolutePath.getCompressionFormat(), 90, out) + bmp.compress(path.getCompressionFormat(), 90, out) } private fun isShowHiddenFlagNeeded(): Boolean { From 240ed105862cda1671ed900e29df8671da056a33 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 23:55:47 +0200 Subject: [PATCH 091/111] update commons to 3.19.18 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 491206a45..064040a57 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.17' + implementation 'com.simplemobiletools:commons:3.19.18' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' From 957545ab4dd1ce1085f88576366c0f7e32baa502 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 23:59:36 +0200 Subject: [PATCH 092/111] update version to 3.8.1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 064040a57..aaa799cca 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 174 - versionName "3.8.0" + versionCode 175 + versionName "3.8.1" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From 577cb8dffec6d573584926226225363f3ae7c609 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 23:59:42 +0200 Subject: [PATCH 093/111] updating changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3822d1105..172cec63a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========== +Version 3.8.1 *(2018-04-24)* +---------------------------- + + * Rewrote media caching and new file discovery for better performance + * Some OTG file handling improvements + Version 3.8.0 *(2018-04-22)* ---------------------------- From e2fa9646d9f0a43bf91df8aba68a4f1f14a7fec1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 25 Apr 2018 23:01:23 +0200 Subject: [PATCH 094/111] update commons to 3.19.20 --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index aaa799cca..b1ce3ff87 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.18' + implementation 'com.simplemobiletools:commons:3.19.20' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 2c3ea3dae..9ef0f82e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -253,7 +253,7 @@ class MediaFetcher(val context: Context) { else -> TYPE_GIFS } - val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) + val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH)) val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type) media.add(medium) } From b4f44df18352d039b00afda4a54c98fecf332155 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 25 Apr 2018 23:41:44 +0200 Subject: [PATCH 095/111] avoid showing the same folder twice, with different casing --- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 9ef0f82e5..9cf121e75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -138,7 +138,7 @@ class MediaFetcher(val context: Context) { foldersToScan.add(curPath) } - return foldersToScan + return foldersToScan.distinctBy { it.toLowerCase() } as ArrayList } private fun addFolder(curFolders: ArrayList, folder: String) { From 688b0e26242031343bebea6a807b85989e8251d2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 25 Apr 2018 23:59:17 +0200 Subject: [PATCH 096/111] add an extra check to avoid showing duplicate folders --- .../kotlin/com/simplemobiletools/gallery/extensions/Context.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f2b48b5bd..0f4673fa5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -276,7 +276,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: } }) as ArrayList - callback(filteredDirectories) + callback(filteredDirectories.distinctBy { it.path.toLowerCase() } as ArrayList) removeInvalidDBDirectories(directories, directoryDao) }.start() From 9aade59c073e6fcbae42f8eda7088be4405f3d0f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 09:41:15 +0200 Subject: [PATCH 097/111] destroy the Gallery database instance only if the user exits the app --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 86a61e771..40ae7d726 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -190,7 +190,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.temporarilyShowHidden = false mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() - GalleryDataBase.destroyInstance() + if (!isChangingConfigurations) { + GalleryDataBase.destroyInstance() + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { From db278b4aa24ca34012f3ff6a128aa514bb979901 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 09:48:05 +0200 Subject: [PATCH 098/111] add another extra check to avoid showing duplicate folders --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 40ae7d726..a6fec1db6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -679,7 +679,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun showSortedDirs(dirs: ArrayList) { - val sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + var sortedDirs = getSortedDirectories(dirs).clone() as ArrayList + sortedDirs = sortedDirs.distinctBy { it.path.toLowerCase() } as ArrayList + runOnUiThread { (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) } From d2e2e315e123bb86f0095736efb37f9dfb716342 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 10:35:32 +0200 Subject: [PATCH 099/111] make sure we filter out empty folders --- .../simplemobiletools/gallery/activities/MainActivity.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 a6fec1db6..a0a4e3984 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -759,6 +759,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { dirs.forEach { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) + } else { + val children = File(it.path).list() + val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false + if (!hasMediaFile) { + invalidDirs.add(it) + } } } From bb943daf38b91c6c2b0ee0e21d409324f8338f0a Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 10:46:35 +0200 Subject: [PATCH 100/111] remove a directory from local db if it is empty --- .../simplemobiletools/gallery/activities/MediaActivity.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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 4bc667bc5..63ce77841 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -485,6 +485,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun isDirEmpty(): Boolean { return if (mMedia.size <= 0 && config.filterMedia > 0) { deleteDirectoryIfEmpty() + deleteDBDirectory() finish() true } else { @@ -492,6 +493,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun deleteDBDirectory() { + Thread { + galleryDB.DirectoryDao().deleteDirPath(mPath) + }.start() + } + private fun tryToggleTemporarilyShowHidden() { if (config.temporarilyShowHidden) { toggleTemporarilyShowHidden(false) @@ -671,6 +678,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { toast(R.string.unknown_error_occurred) } else if (mMedia.isEmpty()) { deleteDirectoryIfEmpty() + deleteDBDirectory() finish() } else { Thread { From 617412a3bcbbf6d244169cc85b38a7584bf8e12a Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 10:49:26 +0200 Subject: [PATCH 101/111] check invalid directories as the last thing on the new thread --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a0a4e3984..a931acfb6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -662,13 +662,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGettingDirs = false mLoadedInitialPhotos = true - checkInvalidDirectories(dirs, directoryDao) runOnUiThread { directories_refresh_layout.isRefreshing = false directories_vertical_fastscroller.measureRecyclerView() checkPlaceholderVisibility(dirs) } + checkInvalidDirectories(dirs, directoryDao) }.start() } From be54d59bd0354b3057d3a03236e7eeaf52db3bf5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 11:30:58 +0200 Subject: [PATCH 102/111] properly look for empty OTG folders too --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 a931acfb6..0fd59ddd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -760,7 +760,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) } else { - val children = File(it.path).list() + val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildren(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false if (!hasMediaFile) { invalidDirs.add(it) @@ -777,6 +777,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + private fun getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()?.map { it.name }?.toList() + private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList() private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" From 7600fa68b4992c14e9d2f2d7298feb0a15a71b5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 11:51:17 +0200 Subject: [PATCH 103/111] improve file deleting from thumbnails view --- .../gallery/activities/MediaActivity.kt | 23 +++++++++++-------- .../gallery/adapters/MediaAdapter.kt | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) 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 63ce77841..68aca393e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -671,22 +671,27 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - override fun deleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList deleteFiles(filtered) { if (!it) { toast(R.string.unknown_error_occurred) - } else if (mMedia.isEmpty()) { + return@deleteFiles + } + + mMedia.removeAll { filtered.map { it.path }.contains(it.path) } + + Thread { + val mediumDao = galleryDB.MediumDao() + filtered.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() + + if (mMedia.isEmpty()) { deleteDirectoryIfEmpty() deleteDBDirectory() finish() - } else { - Thread { - val mediumDao = galleryDB.MediumDao() - filtered.forEach { - mediumDao.deleteMediumPath(it.path) - } - }.start() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 46369f095..a20c58a82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -241,7 +241,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } media.removeAll(removeMedia) - listener?.deleteFiles(fileDirItems) + listener?.tryDeleteFiles(fileDirItems) removeSelectedItems() } } @@ -327,7 +327,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, interface MediaOperationsListener { fun refreshItems() - fun deleteFiles(fileDirItems: ArrayList) + fun tryDeleteFiles(fileDirItems: ArrayList) fun selectedPaths(paths: ArrayList) } From c0f600c451e2d43bfd11dd003e35af4d111fa820 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 11:54:39 +0200 Subject: [PATCH 104/111] do not refresh media thumbnails twice --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 3 --- 1 file changed, 3 deletions(-) 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 68aca393e..7ef0ac69b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -698,9 +698,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun refreshItems() { getMedia() - Handler().postDelayed({ - getMedia() - }, 1000) } override fun selectedPaths(paths: ArrayList) { From a24050c98da4f0a0dd21c533d73f809e239b6e8b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 13:59:24 +0200 Subject: [PATCH 105/111] make sure folder inclusion is recursive on OTG too --- .../gallery/activities/MainActivity.kt | 4 +--- .../gallery/extensions/Context.kt | 4 ++++ .../gallery/helpers/MediaFetcher.kt | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 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 0fd59ddd8..5d27d06a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -760,7 +760,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) } else { - val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildren(it.path) else File(it.path).list()?.asList() + val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false if (!hasMediaFile) { invalidDirs.add(it) @@ -777,8 +777,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - private fun getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()?.map { it.name }?.toList() - private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList() private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" 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 0f4673fa5..0cfd4d85a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -326,3 +326,7 @@ fun Context.updateDBMediaPath(oldPath: String, newPath: String) { fun Context.updateDBDirectory(directory: Directory) { galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types) } + +fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles() + +fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)?.map { it.name }?.toList() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 9cf121e75..41d876701 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.photoExtensions import com.simplemobiletools.commons.helpers.videoExtensions import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.getOTGFolderChildren import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -143,10 +144,20 @@ class MediaFetcher(val context: Context) { private fun addFolder(curFolders: ArrayList, folder: String) { curFolders.add(folder) - val files = File(folder).listFiles() ?: return - for (file in files) { - if (file.isDirectory) { - addFolder(curFolders, file.absolutePath) + if (folder.startsWith(OTG_PATH)) { + val files = context.getOTGFolderChildren(folder) ?: return + for (file in files) { + if (file.isDirectory) { + val relativePath = file.uri.path.substringAfterLast("${context.config.OTGPartition}:") + addFolder(curFolders, "$OTG_PATH$relativePath") + } + } + } else { + val files = File(folder).listFiles() ?: return + for (file in files) { + if (file.isDirectory) { + addFolder(curFolders, file.absolutePath) + } } } } From 71a378d5bda1c9529cf2ebfb93dd95443a839317 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 14:53:20 +0200 Subject: [PATCH 106/111] fix copying folders from OTG devices --- app/build.gradle | 2 +- .../gallery/adapters/DirectoryAdapter.kt | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b1ce3ff87..c17829920 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.20' + implementation 'com.simplemobiletools:commons:3.19.21' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 91d21b847..dc37d0e49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -279,10 +280,14 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() selectedPositions.forEach { - val dir = File(dirs[it].path) - val childrenFiles = dir.listFiles()?.filter { !activity.getIsPathDirectory(it.absolutePath) && it.absolutePath.isImageVideoGif() }?.map { it.absolutePath } - ?: ArrayList() - paths.addAll(childrenFiles) + val childrenPaths = ArrayList() + val path = dirs[it].path + if (path.startsWith(OTG_PATH)) { + paths.addAll(getOTGFilePaths(path)) + } else { + File(path).list()?.filter { !activity.getIsPathDirectory(it) && it.isImageVideoGif() }?.mapTo(childrenPaths, { it }) + } + paths.addAll(childrenPaths) } val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList @@ -293,6 +298,17 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { + val paths = ArrayList() + activity.getOTGFolderChildren(path)?.forEach { + if (!it.isDirectory && it.name.isImageVideoGif()) { + val relativePath = it.uri.path.substringAfterLast("${activity.config.OTGPartition}:") + paths.add("$OTG_PATH$relativePath") + } + } + return paths + } + private fun askConfirmDelete() { if (config.skipDeleteConfirmation) { deleteFiles() From d83df54a41afed0eeec4b19cf6dd064371795c7d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 15:11:28 +0200 Subject: [PATCH 107/111] copy hidden files only when they are visible --- .../gallery/adapters/DirectoryAdapter.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 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 dc37d0e49..06d14443c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -279,15 +279,16 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() + val showHidden = activity.config.shouldShowHidden selectedPositions.forEach { - val childrenPaths = ArrayList() val path = dirs[it].path if (path.startsWith(OTG_PATH)) { - paths.addAll(getOTGFilePaths(path)) + paths.addAll(getOTGFilePaths(path, showHidden)) } else { - File(path).list()?.filter { !activity.getIsPathDirectory(it) && it.isImageVideoGif() }?.mapTo(childrenPaths, { it }) + File(path).listFiles()?.filter { + !activity.getIsPathDirectory(it.absolutePath) && it.isImageVideoGif() && (showHidden || !it.name.startsWith('.')) + }?.mapTo(paths, { it.absolutePath }) } - paths.addAll(childrenPaths) } val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList @@ -298,10 +299,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { + private fun getOTGFilePaths(path: String, showHidden: Boolean): ArrayList { val paths = ArrayList() activity.getOTGFolderChildren(path)?.forEach { - if (!it.isDirectory && it.name.isImageVideoGif()) { + if (!it.isDirectory && it.name.isImageVideoGif() && (showHidden || !it.name.startsWith('.'))) { val relativePath = it.uri.path.substringAfterLast("${activity.config.OTGPartition}:") paths.add("$OTG_PATH$relativePath") } From a0cf205c8c6c9ecd6fe670610a396f515787b21f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 15:42:14 +0200 Subject: [PATCH 108/111] check new media every couple seconds --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 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 5d27d06a1..9bbaa26b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -662,6 +662,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { mIsGettingDirs = false mLoadedInitialPhotos = true + checkLastMediaChanged() runOnUiThread { directories_refresh_layout.isRefreshing = false @@ -795,7 +796,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { return } - /*mLastMediaHandler.postDelayed({ + mLastMediaHandler.postDelayed({ Thread { val mediaId = getLatestMediaId() val mediaDateId = getLatestMediaByDateId() @@ -810,7 +811,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { checkLastMediaChanged() } }.start() - }, LAST_MEDIA_CHECK_PERIOD)*/ + }, LAST_MEDIA_CHECK_PERIOD) } override fun refreshItems() { From 7b2a3d6365300cf2faf9bac3382a02b042eaea14 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 16:08:20 +0200 Subject: [PATCH 109/111] avoid deleting newly created temporary folder too early --- .../gallery/activities/MainActivity.kt | 27 +++++++++---------- .../gallery/extensions/Context.kt | 2 +- .../gallery/interfaces/DirectoryDao.kt | 4 --- 3 files changed, 14 insertions(+), 19 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 9bbaa26b3..33c1ab8f8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -102,7 +102,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") }*/ - if (hasPermission(PERMISSION_WRITE_STORAGE)) { + if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE)) { checkOTGInclusion() } } @@ -255,18 +255,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun checkOTGInclusion() { - if (!config.wasOTGHandled) { - Thread { - if (hasOTGConnected()) { - runOnUiThread { - handleOTGPermission { - config.addIncludedFolder(OTG_PATH) - } + Thread { + if (hasOTGConnected()) { + runOnUiThread { + handleOTGPermission { + config.addIncludedFolder(OTG_PATH) } - config.wasOTGHandled = true } - }.start() - } + config.wasOTGHandled = true + } + }.start() } private fun tryLoadGallery() { @@ -301,7 +299,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_refresh_layout.isRefreshing = true } } - gotDirectories(it) + gotDirectories(addTempFolderIfNeeded(it)) } } @@ -377,8 +375,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } Thread { + val directoryDao = galleryDB.DirectoryDao() folders.filter { !it.exists() }.forEach { - galleryDB.DirectoryDao().deleteDirPath(it.absolutePath) + directoryDao.deleteDirPath(it.absolutePath) } }.start() } @@ -760,7 +759,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { dirs.forEach { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) - } else { + } else if (it.path != config.tempFolderPath) { val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false if (!hasMediaFile) { 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 0cfd4d85a..8ef8e068c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -312,7 +312,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !getDoesFilePathExist(it.path) }.forEach { + dirsToCheck.filter { !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { directoryDao.deleteDirPath(it.path) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 7df52c96f..62bef007a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.gallery.interfaces import android.arch.persistence.room.Dao -import android.arch.persistence.room.Delete import android.arch.persistence.room.Insert import android.arch.persistence.room.OnConflictStrategy.REPLACE import android.arch.persistence.room.Query @@ -18,9 +17,6 @@ interface DirectoryDao { @Insert(onConflict = REPLACE) fun insertAll(directories: List) - @Delete - fun deleteDir(directory: Directory) - @Query("DELETE FROM directories WHERE path = :path") fun deleteDirPath(path: String) From 163cedfa44d3eb58a86f73ed6bbfb7473189d18c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 20:08:36 +0200 Subject: [PATCH 110/111] update version to 3.8.2 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c17829920..5584b3101 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 175 - versionName "3.8.1" + versionCode 176 + versionName "3.8.2" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From 55ee8c710b524cbdc9d8c8ee5d857898af99152f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 20:08:41 +0200 Subject: [PATCH 111/111] updating changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 172cec63a..914c2a716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========== +Version 3.8.2 *(2018-04-26)* +---------------------------- + + * Rewrote media caching and new file discovery for better performance + * Many OTG file handling improvements + Version 3.8.1 *(2018-04-24)* ----------------------------