From 85a0a69599c58552aa30cf40834b6679e73e9d06 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 13:15:41 +0200 Subject: [PATCH] show an icon at the folder for OTG devices too --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/adapters/DirectoryAdapter.kt | 13 +++++++------ .../gallery/databases/GalleryDataBase.kt | 6 ++++-- .../simplemobiletools/gallery/extensions/Context.kt | 10 +++++++++- .../simplemobiletools/gallery/helpers/Constants.kt | 4 ++++ .../gallery/interfaces/DirectoryDao.kt | 2 +- .../simplemobiletools/gallery/models/Directory.kt | 2 +- app/src/main/res/layout/directory_item_grid.xml | 2 +- app/src/main/res/layout/directory_item_list.xml | 2 +- 10 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 61e0ff749..7f7228180 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.10' + implementation 'com.simplemobiletools:commons:3.19.11' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 8c988eec6..9787cfbb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -676,7 +676,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified) val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken) val size = curMedia.sumByLong { it.size } - return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes) + return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes) } private fun setupAdapter(dirs: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 2da3bc1b3..b49a9421f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -19,10 +19,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.TYPE_GIFS -import com.simplemobiletools.gallery.helpers.TYPE_IMAGES -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS -import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item_list.view.* @@ -420,7 +417,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList): ArrayList() val tempFolderPath = config.tempFolderPath if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath), 0) + val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, getPathLocation(tempFolderPath), 0) directories.add(newFolder) } directories.addAll(dirs) return directories } +fun Context.getPathLocation(path: String): Int { + return when { + isPathOnSD(path) -> LOCATION_SD + path.startsWith(OTG_PATH) -> LOCATION_OTG + else -> LOCAITON_INTERNAL + } +} + fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { val options = RequestOptions() .signature(path.getFileSignature()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index d75ce223d..12352ebf9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -102,3 +102,7 @@ const val EXT_ALBUM = 1024 const val TYPE_IMAGES = 1 const val TYPE_VIDEOS = 2 const val TYPE_GIFS = 4 + +const val LOCAITON_INTERNAL = 1 +const val LOCATION_SD = 2 +const val LOCATION_OTG = 3 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 0d996ad3d..7df52c96f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory @Dao interface DirectoryDao { - @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card, media_types FROM directories") + @Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, location, media_types FROM directories") fun getAll(): List @Insert(onConflict = REPLACE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index ef02bdfc8..6d8c217a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -19,7 +19,7 @@ data class Directory( @ColumnInfo(name = "last_modified") var modified: Long, @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") var size: Long, - @ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean, + @ColumnInfo(name = "location") val location: Int, @ColumnInfo(name = "media_types") var types: Int) : Serializable, Comparable { companion object { diff --git a/app/src/main/res/layout/directory_item_grid.xml b/app/src/main/res/layout/directory_item_grid.xml index 78ebc25e2..31d52f574 100644 --- a/app/src/main/res/layout/directory_item_grid.xml +++ b/app/src/main/res/layout/directory_item_grid.xml @@ -82,7 +82,7 @@