From 73000aa6118e507e6bc9b09ce8164da52a651d56 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 20 Apr 2018 11:46:50 +0200 Subject: [PATCH] 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,