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