From 58877df88ecf5f9c200f075c06f5c7d07978470b Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 15:44:39 +0200 Subject: [PATCH 001/163] couple improvements related to the Favorites folder --- .../gallery/activities/MainActivity.kt | 16 ++++++++++++++-- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/extensions/Context.kt | 2 +- .../gallery/interfaces/MediumDao.kt | 3 +++ .../gallery/models/Directory.kt | 3 +++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index cfb34cdad..c0bc57dac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -613,6 +613,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { try { for (directory in dirs) { + if (directory.areFavorites()) { + continue + } + val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) val newDir = if (curMedia.isEmpty()) { directory @@ -656,6 +660,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { foldersToScan.remove(it.path) } + val favoriteMedia = mediumDao.getFavorites() as ArrayList + if (favoriteMedia.isNotEmpty() && dirs.none { it.areFavorites() }) { + val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + dirs.add(favorites) + showSortedDirs(dirs) + directoryDao.insert(favorites) + } + // check the remaining folders which were not cached at all yet for (folder in foldersToScan) { val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) @@ -721,7 +733,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val mediaTypes = curMedia.getDirMediaTypes() - val dirName = checkAppendingHidden(path, hiddenString, includedFolders) + val dirName = if (path == FAVORITES) getString(R.string.favorites) else checkAppendingHidden(path, hiddenString, includedFolders) val firstItem = curMedia.first() val lastItem = curMedia.last() @@ -776,7 +788,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun checkInvalidDirectories(dirs: ArrayList, directoryDao: DirectoryDao) { val invalidDirs = ArrayList() - dirs.forEach { + dirs.filter { !it.areFavorites() }.forEach { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) } else if (it.path != 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 29c5d956b..b0bca34cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -488,7 +488,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun isDirEmpty(): Boolean { - return if (mMedia.size <= 0 && config.filterMedia > 0) { + return if (mPath != FAVORITES && mMedia.size <= 0 && config.filterMedia > 0) { deleteDirectoryIfEmpty() deleteDBDirectory() finish() 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 1fb50627e..3a29c2568 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -356,7 +356,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { + dirsToCheck.filter { !it.areFavorites() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { directoryDao.deleteDirPath(it.path) } } 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 451f92e27..13c0278e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -11,6 +11,9 @@ interface MediumDao { @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path") fun getMediaFromPath(path: String): List + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE is_favorite = 1") + fun getFavorites(): List + @Query("SELECT full_path FROM media WHERE is_favorite = 1") fun getFavoritePaths(): List 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 3c4dd01a0..85835f165 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE +import com.simplemobiletools.gallery.helpers.FAVORITES import java.io.Serializable @Entity(tableName = "directories", indices = [Index(value = "path", unique = true)]) @@ -36,4 +37,6 @@ data class Directory( sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() else -> taken.formatDate() } + + fun areFavorites() = path == FAVORITES } From 5677367fbfee345017c037c69dac325010d26d11 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 16:22:11 +0200 Subject: [PATCH 002/163] adding a couple more Favorite improvements --- .../gallery/activities/MainActivity.kt | 9 ++++++++- .../gallery/activities/MediaActivity.kt | 10 +++++++--- .../gallery/activities/ViewPagerActivity.kt | 8 ++++++-- .../gallery/asynctasks/GetMediaAsynctask.kt | 8 +++++++- .../simplemobiletools/gallery/extensions/Context.kt | 4 ++++ .../com/simplemobiletools/gallery/helpers/Constants.kt | 1 + 6 files changed, 33 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 c0bc57dac..c55b5837a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -661,11 +661,18 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val favoriteMedia = mediumDao.getFavorites() as ArrayList - if (favoriteMedia.isNotEmpty() && dirs.none { it.areFavorites() }) { + if (favoriteMedia.isNotEmpty()) { val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) dirs.add(favorites) showSortedDirs(dirs) directoryDao.insert(favorites) + } else if (dirs.any { it.areFavorites() }) { + val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } + if (currentFavoriteDir != null) { + dirs.remove(currentFavoriteDir) + showSortedDirs(dirs) + directoryDao.deleteDirPath(FAVORITES) + } } // check the remaining folders which were not cached at all yet 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 b0bca34cf..25f0a2e63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -290,6 +290,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { val dirName = when { + mPath == FAVORITES -> getString(R.string.favorites) mPath == OTG_PATH -> getString(R.string.otg) mPath.startsWith(OTG_PATH) -> mPath.trimEnd('/').substringAfterLast('/') else -> getHumanizedFilename(mPath) @@ -488,9 +489,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun isDirEmpty(): Boolean { - return if (mPath != FAVORITES && mMedia.size <= 0 && config.filterMedia > 0) { - deleteDirectoryIfEmpty() - deleteDBDirectory() + return if (mMedia.size <= 0 && config.filterMedia > 0) { + if (mPath != FAVORITES) { + deleteDirectoryIfEmpty() + deleteDBDirectory() + } finish() true } else { @@ -642,6 +645,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { Intent(this, ViewPagerActivity::class.java).apply { putExtra(PATH, path) putExtra(SHOW_ALL, mShowAll) + putExtra(SHOW_FAVORITES, mPath == FAVORITES) startActivity(this) } } 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 dfd2b21d5..295e15c9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -59,6 +59,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mPos = -1 private var mShowAll = false private var mIsSlideshowActive = false + private var mIsShowingFavorites = false private var mRotationDegrees = 0 private var mPrevHashcode = 0 @@ -84,6 +85,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) mMediaFiles = MediaActivity.mMedia.clone() as ArrayList + mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { @@ -198,7 +200,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (!getDoesFilePathExist(mPath)) { Thread { - scanPathRecursively(mPath) + if (!getIsPathDirectory(mPath)) { + scanPathRecursively(mPath) + } }.start() finish() return @@ -216,7 +220,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View showSystemUI() - mDirectory = mPath.getParentPath() + mDirectory = if (mIsShowingFavorites) FAVORITES else mPath.getParentPath() if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { mDirectory += "/" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 07b9bb630..fcd89b099 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -4,7 +4,9 @@ import android.content.Context import android.os.AsyncTask import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.galleryDB import com.simplemobiletools.gallery.extensions.getFavoritePaths +import com.simplemobiletools.gallery.helpers.FAVORITES import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium import java.util.* @@ -28,7 +30,11 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) media } else { - mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) + if (mPath == FAVORITES) { + context.galleryDB.MediumDao().getFavorites() as ArrayList + } else { + mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) + } } } 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 3a29c2568..49743ba99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -320,6 +320,10 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag val mediumDao = galleryDB.MediumDao() val foldersToScan = if (path == "/") MediaFetcher(this).getFoldersToScan() else arrayListOf(path) var media = ArrayList() + if (path == FAVORITES) { + media.addAll(mediumDao.getFavorites()) + } + val shouldShowHidden = config.shouldShowHidden foldersToScan.forEach { try { 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 39fdd8a4b..e0f3c7085 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -64,6 +64,7 @@ const val SLIDESHOW_SCROLL_DURATION = 500L const val NOMEDIA = ".nomedia" const val FAVORITES = "favorites" +const val SHOW_FAVORITES = "show_favorites" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 300000L const val CLICK_MAX_DURATION = 150 From e508030496cf0394ad958323d7e6d0e9ab1f68ac Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 20:47:08 +0200 Subject: [PATCH 003/163] remove the path scanning at ViewPager activity --- .../gallery/activities/ViewPagerActivity.kt | 5 ----- 1 file changed, 5 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 295e15c9b..d6db52d6b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -199,11 +199,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (!getDoesFilePathExist(mPath)) { - Thread { - if (!getIsPathDirectory(mPath)) { - scanPathRecursively(mPath) - } - }.start() finish() return } From 40dc05602cec89f91d5d8a894db607d2db810236 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 21:09:51 +0200 Subject: [PATCH 004/163] allow batch favorite toggling by long pressing items --- .../gallery/adapters/MediaAdapter.kt | 32 +++++++++++++++++++ app/src/main/res/menu/cab_media.xml | 10 ++++++ 2 files changed, 42 insertions(+) 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 2e2199529..a2e963800 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -80,6 +80,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 checkHideBtnVisibility(this) + checkFavoriteBtnVisibility(this) } } @@ -95,6 +96,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, R.id.cab_edit -> editFile() R.id.cab_hide -> toggleFileVisibility(true) R.id.cab_unhide -> toggleFileVisibility(false) + R.id.cab_add_to_favorites -> toggleFavorites(true) + R.id.cab_remove_from_favorites -> toggleFavorites(false) R.id.cab_share -> shareMedia() R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) @@ -131,6 +134,21 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 } + private fun checkFavoriteBtnVisibility(menu: Menu) { + var favoriteCnt = 0 + var nonFavoriteCnt = 0 + selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + if (it.isFavorite) { + favoriteCnt++ + } else { + nonFavoriteCnt++ + } + } + + menu.findItem(R.id.cab_add_to_favorites).isVisible = nonFavoriteCnt > 0 + menu.findItem(R.id.cab_remove_from_favorites).isVisible = favoriteCnt > 0 + } + private fun confirmSelection() { val paths = getSelectedMedia().map { it.path } as ArrayList listener?.selectedPaths(paths) @@ -177,6 +195,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, }.start() } + private fun toggleFavorites(add: Boolean) { + Thread { + val mediumDao = activity.galleryDB.MediumDao() + getSelectedMedia().forEach { + it.isFavorite = add + mediumDao.updateFavorite(it.path, add) + } + activity.runOnUiThread { + listener?.refreshItems() + finishActMode() + } + }.start() + } + private fun shareMedia() { if (selectedPositions.size == 1 && selectedPositions.first() != -1) { activity.shareMedium(getSelectedMedia()[0]) diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index 8ebb87f08..748d13541 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -46,6 +46,16 @@ android:icon="@drawable/ic_select_all" android:title="@string/select_all" app:showAsAction="ifRoom"/> + + Date: Wed, 20 Jun 2018 21:40:10 +0200 Subject: [PATCH 005/163] make sure Favorites folder is not shown twice --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index c55b5837a..e50ee4eea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -662,6 +662,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val favoriteMedia = mediumDao.getFavorites() as ArrayList if (favoriteMedia.isNotEmpty()) { + // avoid adding Favorites twice + val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } + if (currentFavoriteDir != null) { + dirs.remove(currentFavoriteDir) + } val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) dirs.add(favorites) showSortedDirs(dirs) From cc5fbecabd9515a43c5b5e28b91e455445f662be Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 21:42:31 +0200 Subject: [PATCH 006/163] do not store actual item array lists in adapters, pass clones only --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +++-- .../simplemobiletools/gallery/activities/MediaActivity.kt | 5 +++-- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- 4 files changed, 8 insertions(+), 6 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 e50ee4eea..2399a6aa1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -757,10 +757,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun setupAdapter(dirs: ArrayList) { val currAdapter = directories_grid.adapter + val directories = dirs.clone() as ArrayList if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller - DirectoryAdapter(this, dirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { + DirectoryAdapter(this, directories, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { val path = (it as Directory).path if (path != config.tempFolderPath) { itemClicked(path) @@ -770,7 +771,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_grid.adapter = this } } else { - (currAdapter as DirectoryAdapter).updateDirs(dirs) + (currAdapter as DirectoryAdapter).updateDirs(directories) } setupScrollDirection() 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 25f0a2e63..adcbc7484 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -312,18 +312,19 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return } + val media = mMedia.clone() as ArrayList val currAdapter = media_grid.adapter if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { + MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) media_grid.adapter = this } } else { - (currAdapter as MediaAdapter).updateMedia(mMedia) + (currAdapter as MediaAdapter).updateMedia(media) } setupScrollDirection() } 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 b44e0f7f4..2a5712912 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -409,7 +409,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) { if (newDirs.hashCode() != currentDirectoriesHash) { currentDirectoriesHash = newDirs.hashCode() - dirs = newDirs.clone() as ArrayList + dirs = newDirs notifyDataSetChanged() finishActMode() fastScroller?.measureRecyclerView() 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 a2e963800..c501eb471 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -288,7 +288,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, if (newMedia.hashCode() != currentMediaHash) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ - media = newMedia.clone() as ArrayList + media = newMedia enableInstantLoad() notifyDataSetChanged() finishActMode() From d4fe872a3a3f5b03d8a5953acb4583481d23c5c2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 21:49:54 +0200 Subject: [PATCH 007/163] make sure the Favorites folder is pinned by default --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +++++ .../kotlin/com/simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../com/simplemobiletools/gallery/helpers/Constants.kt | 1 + 3 files changed, 10 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 2399a6aa1..550e97aa4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -109,6 +109,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE)) { checkOTGInclusion() } + + if (!config.wereFavoritesPinned) { + config.addPinnedFolders(hashSetOf(FAVORITES)) + config.wereFavoritesPinned = true + } } override fun onStart() { 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 73d6db933..59fcde108 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -322,4 +322,8 @@ class Config(context: Context) : BaseConfig(context) { var tempSkipDeleteConfirmation: Boolean get() = prefs.getBoolean(TEMP_SKIP_DELETE_CONFIRMATION, false) set(tempSkipDeleteConfirmation) = prefs.edit().putBoolean(TEMP_SKIP_DELETE_CONFIRMATION, tempSkipDeleteConfirmation).apply() + + var wereFavoritesPinned: Boolean + get() = prefs.getBoolean(WERE_FAVORITES_PINNED, false) + set(wereFavoritesPinned) = prefs.edit().putBoolean(WERE_FAVORITES_PINNED, wereFavoritesPinned).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 e0f3c7085..3fd37fcf0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -49,6 +49,7 @@ const val LAST_FILEPICKER_PATH = "last_filepicker_path" const val WAS_OTG_HANDLED = "was_otg_handled" const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" const val BOTTOM_ACTIONS = "bottom_actions" +const val WERE_FAVORITES_PINNED = "were_favorites_pinned" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" From b81e1c2172b741d5d0ca46063cf9ea181f9fe7b3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 21:55:41 +0200 Subject: [PATCH 008/163] make sure we sort the Favorites properly --- .../simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index fcd89b099..9d5ff6a15 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -31,7 +31,9 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage media } else { if (mPath == FAVORITES) { - context.galleryDB.MediumDao().getFavorites() as ArrayList + val media = context.galleryDB.MediumDao().getFavorites() as ArrayList + mediaFetcher.sortMedia(media, context.config.getFileSorting(mPath)) + media } else { mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } From 8af3b1eee354535732c440d1ff4ecb7fdfed7ab1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 22:20:43 +0200 Subject: [PATCH 009/163] fix some Favorites glitches, try treating it more like other folders --- .../gallery/activities/MainActivity.kt | 32 +++++-------------- .../gallery/asynctasks/GetMediaAsynctask.kt | 10 +----- .../gallery/helpers/MediaFetcher.kt | 10 ++++-- 3 files changed, 17 insertions(+), 35 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 550e97aa4..a1fa7534a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -618,10 +618,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { try { for (directory in dirs) { - if (directory.areFavorites()) { - continue - } - val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) val newDir = if (curMedia.isEmpty()) { directory @@ -661,30 +657,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val foldersToScan = mediaFetcher.getFoldersToScan() + foldersToScan.add(FAVORITES) dirs.forEach { foldersToScan.remove(it.path) } - val favoriteMedia = mediumDao.getFavorites() as ArrayList - if (favoriteMedia.isNotEmpty()) { - // avoid adding Favorites twice - val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } - if (currentFavoriteDir != null) { - dirs.remove(currentFavoriteDir) - } - val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) - dirs.add(favorites) - showSortedDirs(dirs) - directoryDao.insert(favorites) - } else if (dirs.any { it.areFavorites() }) { - val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } - if (currentFavoriteDir != null) { - dirs.remove(currentFavoriteDir) - showSortedDirs(dirs) - directoryDao.deleteDirPath(FAVORITES) - } - } - // check the remaining folders which were not cached at all yet for (folder in foldersToScan) { val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) @@ -818,6 +795,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + if (getFavoritePaths().isEmpty()) { + val dirsFolder = dirs.firstOrNull { it.areFavorites() } + if (dirsFolder != null) { + invalidDirs.add(dirsFolder) + } + } + if (invalidDirs.isNotEmpty()) { dirs.removeAll(invalidDirs) showSortedDirs(dirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 9d5ff6a15..07b9bb630 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -4,9 +4,7 @@ import android.content.Context import android.os.AsyncTask import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.galleryDB import com.simplemobiletools.gallery.extensions.getFavoritePaths -import com.simplemobiletools.gallery.helpers.FAVORITES import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium import java.util.* @@ -30,13 +28,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) media } else { - if (mPath == FAVORITES) { - val media = context.galleryDB.MediumDao().getFavorites() as ArrayList - mediaFetcher.sortMedia(media, context.config.getFileSorting(mPath)) - media - } else { - mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) - } + mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } } 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 9afb95ccf..670523e2e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -159,7 +159,13 @@ class MediaFetcher(val context: Context) { private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean, favoritePaths: ArrayList): ArrayList { val media = ArrayList() - val files = File(folder).listFiles() ?: return media + + val files = if (folder == FAVORITES) { + favoritePaths.map { File(it) }.toTypedArray() + } else { + File(folder).listFiles() ?: return media + } + val doExtraCheck = context.config.doExtraCheck val showHidden = context.config.shouldShowHidden val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap() @@ -213,7 +219,7 @@ class MediaFetcher(val context: Context) { val path = file.absolutePath val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, folder, lastModified, dateTaken, size, type, isFavorite) + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite) media.add(medium) } return media From cc5bf379c4dff205b66fd4ebea780333c658dea1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 22:42:53 +0200 Subject: [PATCH 010/163] hide some menu items at the Favorites folder --- .../simplemobiletools/gallery/activities/MediaActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index adcbc7484..266a85431 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -188,9 +188,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val isFolderHidden = File(mPath).containsNoMedia() menu.apply { - findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll - findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll - findItem(R.id.exclude_folder).isVisible = !mShowAll + findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES + findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES + findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES findItem(R.id.folder_view).isVisible = mShowAll findItem(R.id.open_camera).isVisible = mShowAll From 283a8254dcdcbd7d9bd73d887f8489dbcd763f7f Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 23:09:42 +0200 Subject: [PATCH 011/163] avoid some folder operations on Favorites --- .../gallery/adapters/DirectoryAdapter.kt | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 2a5712912..3eb4fd15d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -144,11 +144,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() - selectedPositions.forEach { paths.add(dirs[it].path) } - PropertiesDialog(activity, paths, config.shouldShowHidden) + PropertiesDialog(activity, getSelectedPaths().filter { it != FAVORITES }.toList(), config.shouldShowHidden) } } @@ -178,7 +179,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList 1) { activity.config.addExcludedFolders(paths) listener?.refreshItems() finishActMode() @@ -293,7 +294,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Wed, 20 Jun 2018 23:12:09 +0200 Subject: [PATCH 012/163] move the bottom actions a bit up --- app/src/main/res/values/dimens.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index dc4653591..78adecbeb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -10,5 +10,5 @@ 60dp 30dp 72dp - 54dp + 60dp From fad04b406e30ae94bc2f9da26bc84d8236c58b99 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 23:22:17 +0200 Subject: [PATCH 013/163] update commons to 4.2.9 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 01162895e..06c12df8d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.2.8' + implementation 'com.simplemobiletools:commons:4.2.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 a76c716173a9e156405a53c43e532fb1398f11cf Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 23:22:46 +0200 Subject: [PATCH 014/163] add Favorites to release notes --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 1 + app/src/main/res/values/donottranslate.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index a1fa7534a..c27fff363 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -910,6 +910,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { add(Release(177, R.string.release_177)) add(Release(178, R.string.release_178)) add(Release(180, R.string.release_180)) + add(Release(181, R.string.release_181)) checkWhatsNew(this, BuildConfig.VERSION_CODE) } } diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index b27383d5b..fd84ddea6 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -2,6 +2,7 @@ + Allow selecting Favorite items for easy access Allow filtering out RAW images separately Added sorting by Date Taken Allow customizing the app launcher icon color From 5b0438daa51b3982d3a8ae491fa554996a927f52 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 23:23:04 +0200 Subject: [PATCH 015/163] update version to 4.2.1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 06c12df8d..8e3541d06 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.simplemobiletools.gallery" minSdkVersion 16 targetSdkVersion 27 - versionCode 180 - versionName "4.2.0" + versionCode 181 + versionName "4.2.1" multiDexEnabled true setProperty("archivesBaseName", "gallery") } From 2c9103f323ae62b6ac573696c6714a710c098a92 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jun 2018 23:23:10 +0200 Subject: [PATCH 016/163] updating changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b43279c0..719acca53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========== +Version 4.2.1 *(2018-06-20)* +---------------------------- + + * Allow selecting Favorite items for easy access + * Fix sorting by Date Taken after files have been copied + * Couple other stability and UX improvements + Version 4.2.0 *(2018-06-18)* ---------------------------- From 28f7d4eb6c99a9337a9b9cb9e0529a956d04d39a Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 09:06:25 +0200 Subject: [PATCH 017/163] adding some null checks --- .../gallery/activities/PhotoVideoActivity.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 516b24a16..912f7541b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -182,11 +182,15 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList bottom_delete.beGone() bottom_edit.setOnClickListener { - openEditor(mUri!!.toString()) + if (mUri != null) { + openEditor(mUri!!.toString()) + } } bottom_share.setOnClickListener { - sharePath(mUri!!.toString()) + if (mUri != null) { + sharePath(mUri!!.toString()) + } } } From a374f40e92b9acdd313fb9482e451c9582c769aa Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 14:33:31 +0200 Subject: [PATCH 018/163] use an empty path at ShowAll --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index c27fff363..c6d324019 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -341,7 +341,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun showAllMedia() { config.showAll = true Intent(this, MediaActivity::class.java).apply { - putExtra(DIRECTORY, "/") + putExtra(DIRECTORY, "") if (mIsThirdPartyIntent) { handleMediaIntent(this) From 05d37cbfcc6df8a8fc4ad98489f361fd925a7453 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 14:35:52 +0200 Subject: [PATCH 019/163] add a dialog for selecting folder thumbnail grouping --- .../gallery/activities/MediaActivity.kt | 22 +++++++++++++++++++ .../gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 8 +++++++ app/src/main/res/menu/menu_media.xml | 4 ++++ 4 files changed, 38 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 266a85431..b29caf3e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -217,6 +217,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { R.id.open_camera -> launchCamera() R.id.folder_view -> switchToFolderView() R.id.change_view_type -> changeViewType() + R.id.group -> showGroupByDialog() R.id.hide_folder -> tryHideFolder() R.id.unhide_folder -> unhideFolder() R.id.exclude_folder -> tryExcludeFolder() @@ -416,6 +417,27 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun showGroupByDialog() { + val items = arrayListOf( + RadioItem(GROUP_BY_NONE, getString(R.string.do_not_group_files)), + RadioItem(GROUP_BY_LAST_MODIFIED, getString(R.string.by_last_modified)), + RadioItem(GROUP_BY_DATE_TAKEN, getString(R.string.by_date_taken)), + RadioItem(GROUP_BY_FILE_TYPE, getString(R.string.by_file_type)), + RadioItem(GROUP_BY_EXTENSION, getString(R.string.by_extension)) + ) + + if (mShowAll) { + items.add(RadioItem(GROUP_BY_FOLDER, getString(R.string.by_folder))) + } + + RadioGroupDialog(this, items, config.groupBy) { + config.groupBy = it as Int + invalidateOptionsMenu() + media_grid.adapter = null + setupAdapter() + } + } + private fun tryHideFolder() { if (config.wasHideFolderTooltipShown) { hideFolder() 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 59fcde108..cf291465c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -326,4 +326,8 @@ class Config(context: Context) : BaseConfig(context) { var wereFavoritesPinned: Boolean get() = prefs.getBoolean(WERE_FAVORITES_PINNED, false) set(wereFavoritesPinned) = prefs.edit().putBoolean(WERE_FAVORITES_PINNED, wereFavoritesPinned).apply() + + var groupBy: Int + get() = prefs.getInt(GROUP_BY, GROUP_BY_NONE) + set(groupBy) = prefs.edit().putInt(GROUP_BY, groupBy).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 3fd37fcf0..de9e4e7ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -50,6 +50,7 @@ const val WAS_OTG_HANDLED = "was_otg_handled" const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" const val BOTTOM_ACTIONS = "bottom_actions" const val WERE_FAVORITES_PINNED = "were_favorites_pinned" +const val GROUP_BY = "group_by" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" @@ -112,3 +113,10 @@ const val TYPE_RAWS = 8 const val LOCAITON_INTERNAL = 1 const val LOCATION_SD = 2 const val LOCATION_OTG = 3 + +const val GROUP_BY_NONE = 0 +const val GROUP_BY_LAST_MODIFIED = 1 +const val GROUP_BY_DATE_TAKEN = 2 +const val GROUP_BY_FILE_TYPE = 3 +const val GROUP_BY_EXTENSION = 4 +const val GROUP_BY_FOLDER = 5 diff --git a/app/src/main/res/menu/menu_media.xml b/app/src/main/res/menu/menu_media.xml index de3b01776..f59adabec 100644 --- a/app/src/main/res/menu/menu_media.xml +++ b/app/src/main/res/menu/menu_media.xml @@ -31,6 +31,10 @@ android:icon="@drawable/ic_camera" android:title="@string/open_camera" app:showAsAction="ifRoom"/> + Date: Thu, 21 Jun 2018 21:26:09 +0200 Subject: [PATCH 020/163] create a separate dialog for Group By for more flexibility --- .../gallery/activities/MediaActivity.kt | 21 +--- .../gallery/dialogs/ChangeGroupingDialog.kt | 87 ++++++++++++++ .../gallery/helpers/Config.kt | 22 ++++ .../gallery/helpers/Constants.kt | 14 ++- .../res/layout/dialog_change_grouping.xml | 113 ++++++++++++++++++ 5 files changed, 234 insertions(+), 23 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt create mode 100644 app/src/main/res/layout/dialog_change_grouping.xml 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 b29caf3e3..d9c674e9c 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.dialogs.ChangeGroupingDialog import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog @@ -418,23 +419,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun showGroupByDialog() { - val items = arrayListOf( - RadioItem(GROUP_BY_NONE, getString(R.string.do_not_group_files)), - RadioItem(GROUP_BY_LAST_MODIFIED, getString(R.string.by_last_modified)), - RadioItem(GROUP_BY_DATE_TAKEN, getString(R.string.by_date_taken)), - RadioItem(GROUP_BY_FILE_TYPE, getString(R.string.by_file_type)), - RadioItem(GROUP_BY_EXTENSION, getString(R.string.by_extension)) - ) - - if (mShowAll) { - items.add(RadioItem(GROUP_BY_FOLDER, getString(R.string.by_folder))) - } - - RadioGroupDialog(this, items, config.groupBy) { - config.groupBy = it as Int - invalidateOptionsMenu() - media_grid.adapter = null - setupAdapter() + ChangeGroupingDialog(this, mShowAll, mPath) { + mLoadedInitialPhotos = false + getMedia() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt new file mode 100644 index 000000000..63cecbc2f --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeGroupingDialog.kt @@ -0,0 +1,87 @@ +package com.simplemobiletools.gallery.dialogs + +import android.content.DialogInterface +import android.support.v7.app.AlertDialog +import android.view.View +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.* +import kotlinx.android.synthetic.main.dialog_change_grouping.view.* + +class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: Boolean, val path: String = "", val callback: () -> Unit) : + DialogInterface.OnClickListener { + private var currGrouping = 0 + private var config = activity.config + private var view: View + + init { + view = activity.layoutInflater.inflate(R.layout.dialog_change_grouping, null).apply { + use_for_this_folder_divider.beVisibleIf(!isShowingAll) + grouping_dialog_use_for_this_folder.beVisibleIf(!isShowingAll) + grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(path) + grouping_dialog_radio_folder.beVisibleIf(isShowingAll) + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, this) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.group_by) + } + + currGrouping = config.getFolderGrouping(path) + setupGroupRadio() + setupOrderRadio() + } + + private fun setupGroupRadio() { + val groupingRadio = view.grouping_dialog_radio_grouping + + val groupBtn = when { + currGrouping and GROUP_BY_NONE != 0 -> groupingRadio.grouping_dialog_radio_none + currGrouping and GROUP_BY_LAST_MODIFIED != 0 -> groupingRadio.grouping_dialog_radio_last_modified + currGrouping and GROUP_BY_DATE_TAKEN != 0 -> groupingRadio.grouping_dialog_radio_date_taken + currGrouping and GROUP_BY_FILE_TYPE != 0 -> groupingRadio.grouping_dialog_radio_file_type + currGrouping and GROUP_BY_EXTENSION != 0 -> groupingRadio.grouping_dialog_radio_extension + else -> groupingRadio.grouping_dialog_radio_folder + } + groupBtn.isChecked = true + } + + private fun setupOrderRadio() { + val orderRadio = view.grouping_dialog_radio_order + var orderBtn = orderRadio.grouping_dialog_radio_ascending + + if (currGrouping and GROUP_DESCENDING != 0) { + orderBtn = orderRadio.grouping_dialog_radio_descending + } + orderBtn.isChecked = true + } + + override fun onClick(dialog: DialogInterface, which: Int) { + val groupingRadio = view.grouping_dialog_radio_grouping + var grouping = when (groupingRadio.checkedRadioButtonId) { + R.id.grouping_dialog_radio_none -> GROUP_BY_NONE + R.id.grouping_dialog_radio_last_modified -> GROUP_BY_LAST_MODIFIED + R.id.grouping_dialog_radio_date_taken -> GROUP_BY_DATE_TAKEN + R.id.grouping_dialog_radio_file_type -> GROUP_BY_FILE_TYPE + R.id.grouping_dialog_radio_extension -> GROUP_BY_EXTENSION + else -> GROUP_BY_FOLDER + } + + if (view.grouping_dialog_radio_order.checkedRadioButtonId == R.id.grouping_dialog_radio_descending) { + grouping = grouping or GROUP_DESCENDING + } + + if (view.grouping_dialog_use_for_this_folder.isChecked) { + config.saveFolderGrouping(path, grouping) + } else { + config.removeFolderGrouping(path) + config.groupBy = grouping + } + callback() + } +} 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 cf291465c..40b22e446 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -36,6 +36,28 @@ class Config(context: Context) : BaseConfig(context) { fun hasCustomSorting(path: String) = prefs.contains(SORT_FOLDER_PREFIX + path.toLowerCase()) + fun saveFolderGrouping(path: String, value: Int) { + if (path.isEmpty()) { + groupBy = value + } else { + prefs.edit().putInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), value).apply() + } + } + + fun getFolderGrouping(path: String): Int { + var groupBy = prefs.getInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), groupBy) + if (path.isNotEmpty() && groupBy and GROUP_BY_FOLDER != 0) { + groupBy -= GROUP_BY_FOLDER + 1 + } + return groupBy + } + + fun removeFolderGrouping(path: String) { + prefs.edit().remove(GROUP_FOLDER_PREFIX + path.toLowerCase()).apply() + } + + fun hasCustomGrouping(path: String) = prefs.contains(GROUP_FOLDER_PREFIX + path.toLowerCase()) + var wasHideFolderTooltipShown: Boolean get() = prefs.getBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, false) set(wasShown) = prefs.edit().putBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, wasShown).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 de9e4e7ec..3e8c478b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.helpers // shared preferences const val DIRECTORY_SORT_ORDER = "directory_sort_order" const val SORT_FOLDER_PREFIX = "sort_folder_" +const val GROUP_FOLDER_PREFIX = "group_folder_" const val SHOW_HIDDEN_MEDIA = "show_hidden_media" const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden" const val IS_THIRD_PARTY_INTENT = "is_third_party_intent" @@ -114,9 +115,10 @@ const val LOCAITON_INTERNAL = 1 const val LOCATION_SD = 2 const val LOCATION_OTG = 3 -const val GROUP_BY_NONE = 0 -const val GROUP_BY_LAST_MODIFIED = 1 -const val GROUP_BY_DATE_TAKEN = 2 -const val GROUP_BY_FILE_TYPE = 3 -const val GROUP_BY_EXTENSION = 4 -const val GROUP_BY_FOLDER = 5 +const val GROUP_BY_NONE = 1 +const val GROUP_BY_LAST_MODIFIED = 2 +const val GROUP_BY_DATE_TAKEN = 4 +const val GROUP_BY_FILE_TYPE = 8 +const val GROUP_BY_EXTENSION = 16 +const val GROUP_BY_FOLDER = 32 +const val GROUP_DESCENDING = 1024 diff --git a/app/src/main/res/layout/dialog_change_grouping.xml b/app/src/main/res/layout/dialog_change_grouping.xml new file mode 100644 index 000000000..21292ec5d --- /dev/null +++ b/app/src/main/res/layout/dialog_change_grouping.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1a04a98040d189b48e127c27ef54fcb0f779dac8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 21:39:15 +0200 Subject: [PATCH 021/163] fix fetching cached files at Show All Folders Content --- .../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 49743ba99..c4049327e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -318,7 +318,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { Thread { val mediumDao = galleryDB.MediumDao() - val foldersToScan = if (path == "/") MediaFetcher(this).getFoldersToScan() else arrayListOf(path) + val foldersToScan = if (path.isEmpty()) MediaFetcher(this).getFoldersToScan() else arrayListOf(path) var media = ArrayList() if (path == FAVORITES) { media.addAll(mediumDao.getFavorites()) From 9eedf64c1b852e595816b86215a4acd4c17cc822 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:00:59 +0200 Subject: [PATCH 022/163] handle medium grouping at the MediaAdapter --- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/adapters/MediaAdapter.kt | 23 ++++++++++++++++++- .../gallery/dialogs/PickMediumDialog.kt | 2 +- .../gallery/models/Medium.kt | 17 ++++++++++---- 4 files changed, 37 insertions(+), 7 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 d9c674e9c..fdb2b876d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -319,7 +319,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { + MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller, mPath) { itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) 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 c501eb471..3e40cc918 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -18,12 +18,15 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.photo_video_item_grid.view.* +import java.util.HashMap +import kotlin.collections.ArrayList class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, + val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, val path: String, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private val INSTANT_LOAD_DURATION = 2000L @@ -36,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() private val hasOTGConnected = activity.hasOTGConnected() + private var mediumGroups = HashMap>() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -44,6 +48,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, init { setupDragListener(true) + groupMedia() enableInstantLoad() } @@ -289,6 +294,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia + groupMedia() enableInstantLoad() notifyDataSetChanged() finishActMode() @@ -325,6 +331,21 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, }, INSTANT_LOAD_DURATION) } + private fun groupMedia() { + val grouping = activity.config.getFolderGrouping(path) + if (grouping and GROUP_BY_NONE != 0) { + return + } + + media.forEach { + val key = it.getGroupingKey(grouping) + if (!mediumGroups.containsKey(key)) { + mediumGroups[key] = ArrayList() + } + mediumGroups[key]!!.add(it) + } + } + private fun setupView(view: View, medium: Medium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) 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 3998ec75d..8a2fb0f4b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -62,7 +62,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c return shownMedia = media - val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid) { + val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid, null, path) { callback((it as Medium).path) dialog.dismiss() } 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 60e551038..e4441f6d5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -6,14 +6,12 @@ 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.getFilenameExtension import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE -import com.simplemobiletools.gallery.helpers.TYPE_GIFS -import com.simplemobiletools.gallery.helpers.TYPE_IMAGES -import com.simplemobiletools.gallery.helpers.TYPE_RAWS -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS +import com.simplemobiletools.gallery.helpers.* import java.io.Serializable @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) @@ -47,4 +45,15 @@ data class Medium( sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() else -> taken.formatDate() } + + fun getGroupingKey(groupBy: Int): String { + return when { + groupBy and GROUP_BY_LAST_MODIFIED != 0 -> modified.toString() + groupBy and GROUP_BY_DATE_TAKEN != 0 -> taken.toString() + groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString() + groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase() + groupBy and GROUP_BY_FOLDER != 0 -> parentPath + else -> "" + } + } } From e3fde0a6eb4247a38c5c62979bfb1f024b0f74d9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:26:05 +0200 Subject: [PATCH 023/163] obtain the start of the day TS at grouping by date taken and last modified --- .../simplemobiletools/gallery/models/Medium.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 e4441f6d5..1097f935f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.* import java.io.Serializable +import java.util.* @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) data class Medium( @@ -48,12 +49,24 @@ data class Medium( fun getGroupingKey(groupBy: Int): String { return when { - groupBy and GROUP_BY_LAST_MODIFIED != 0 -> modified.toString() - groupBy and GROUP_BY_DATE_TAKEN != 0 -> taken.toString() + groupBy and GROUP_BY_LAST_MODIFIED != 0 -> getDayStartTS(modified) + groupBy and GROUP_BY_DATE_TAKEN != 0 -> getDayStartTS(taken) groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString() groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase() groupBy and GROUP_BY_FOLDER != 0 -> parentPath else -> "" } } + + private fun getDayStartTS(ts: Long): String { + val calendar = Calendar.getInstance(Locale.ENGLISH).apply { + timeInMillis = ts + set(Calendar.HOUR_OF_DAY, 0) + set(Calendar.MINUTE, 0) + set(Calendar.SECOND, 0) + set(Calendar.MILLISECOND, 0) + } + + return calendar.timeInMillis.toString() + } } From 2a23632333533c0195b1d77d96fef40ccae69501 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:41:34 +0200 Subject: [PATCH 024/163] sort medium groups appropriately --- .../gallery/adapters/MediaAdapter.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 3e40cc918..c6fc604af 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -19,10 +19,11 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE +import com.simplemobiletools.gallery.helpers.GROUP_DESCENDING import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.photo_video_item_grid.view.* -import java.util.HashMap +import java.util.* import kotlin.collections.ArrayList class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, @@ -39,7 +40,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() private val hasOTGConnected = activity.hasOTGConnected() - private var mediumGroups = HashMap>() + private var mediumGroups = LinkedHashMap>() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -344,6 +345,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } mediumGroups[key]!!.add(it) } + + val sortDescending = grouping and GROUP_DESCENDING != 0 + val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) + mediumGroups.clear() + sorted.forEach { key, value -> + mediumGroups[key] = value + } } private fun setupView(view: View, medium: Medium) { From f47190b9e128912ec548149c727cf3929e953c0f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:48:50 +0200 Subject: [PATCH 025/163] refresh media thumbnails if only the grouping changes --- .../gallery/adapters/MediaAdapter.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 c6fc604af..49a0e47d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -39,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() + private var currentGrouping = GROUP_BY_NONE private val hasOTGConnected = activity.hasOTGConnected() private var mediumGroups = LinkedHashMap>() @@ -291,7 +292,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash) { + if (newMedia.hashCode() != currentMediaHash || currentGrouping != getCurrentFolderGrouping()) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia @@ -333,20 +334,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun groupMedia() { - val grouping = activity.config.getFolderGrouping(path) - if (grouping and GROUP_BY_NONE != 0) { + currentGrouping = getCurrentFolderGrouping() + if (currentGrouping and GROUP_BY_NONE != 0) { return } media.forEach { - val key = it.getGroupingKey(grouping) + val key = it.getGroupingKey(currentGrouping) if (!mediumGroups.containsKey(key)) { mediumGroups[key] = ArrayList() } mediumGroups[key]!!.add(it) } - val sortDescending = grouping and GROUP_DESCENDING != 0 + val sortDescending = currentGrouping and GROUP_DESCENDING != 0 val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) mediumGroups.clear() sorted.forEach { key, value -> @@ -354,6 +355,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + private fun getCurrentFolderGrouping() = activity.config.getFolderGrouping(path) + private fun setupView(view: View, medium: Medium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) From 139e9fc06fd2476a23b0a974bd477c4c84e1afb4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 10:01:48 +0200 Subject: [PATCH 026/163] renaming a function for getting folder grouping --- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 49a0e47d6..c09b7604e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -292,7 +292,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash || currentGrouping != getCurrentFolderGrouping()) { + if (newMedia.hashCode() != currentMediaHash || currentGrouping != getFolderGrouping()) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia @@ -334,7 +334,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun groupMedia() { - currentGrouping = getCurrentFolderGrouping() + currentGrouping = getFolderGrouping() if (currentGrouping and GROUP_BY_NONE != 0) { return } @@ -355,7 +355,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - private fun getCurrentFolderGrouping() = activity.config.getFolderGrouping(path) + private fun getFolderGrouping() = activity.config.getFolderGrouping(path) private fun setupView(view: View, medium: Medium) { view.apply { From 9bfb83dba24e4a11864854fbef7a210de1001fc4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 10:03:02 +0200 Subject: [PATCH 027/163] removing a helper function --- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 c09b7604e..53a4ca619 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -292,7 +292,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash || currentGrouping != getFolderGrouping()) { + if (newMedia.hashCode() != currentMediaHash || currentGrouping != config.getFolderGrouping(path)) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia @@ -334,7 +334,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun groupMedia() { - currentGrouping = getFolderGrouping() + currentGrouping = config.getFolderGrouping(path) if (currentGrouping and GROUP_BY_NONE != 0) { return } @@ -355,8 +355,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - private fun getFolderGrouping() = activity.config.getFolderGrouping(path) - private fun setupView(view: View, medium: Medium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) From 232073b22718621ccf665f31ca599ac39f989f7f Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 10:25:24 +0200 Subject: [PATCH 028/163] create a ThumbnailItem parent class for media and sections --- .../gallery/adapters/MediaAdapter.kt | 36 +++++++++++++++---- .../gallery/models/ThumbnailItem.kt | 3 ++ .../gallery/models/ThumbnailMedium.kt | 8 +++++ .../gallery/models/ThumbnailSection.kt | 3 ++ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt 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 53a4ca619..dc636309e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -22,6 +22,9 @@ import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE import com.simplemobiletools.gallery.helpers.GROUP_DESCENDING import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem +import com.simplemobiletools.gallery.models.ThumbnailMedium +import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import java.util.* import kotlin.collections.ArrayList @@ -32,10 +35,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private val INSTANT_LOAD_DURATION = 2000L private val IMAGE_LOAD_DELAY = 100L + private val ITEM_SECTION = 0 + private val ITEM_MEDIUM = 1 private val config = activity.config private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST private var visibleItemPaths = ArrayList() + private var thumbnailItems = ArrayList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() @@ -70,15 +76,22 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { - val medium = media.getOrNull(position) ?: return - visibleItemPaths.add(medium.path) - val view = holder.bindView(medium, !allowMultiplePicks) { itemView, adapterPosition -> - setupView(itemView, medium) + val tmbItem = thumbnailItems.getOrNull(position) ?: return + if (tmbItem is ThumbnailMedium) { + visibleItemPaths.add(tmbItem.path) + } + + val view = holder.bindView(tmbItem, !allowMultiplePicks) { itemView, adapterPosition -> + if (tmbItem is ThumbnailMedium) { + setupThumbnailMedium(itemView, tmbItem) + } else { + setupThumbnailSection(itemView, tmbItem as ThumbnailSection) + } } bindViewHolder(holder, position, view) } - override fun getItemCount() = media.size + override fun getItemCount() = thumbnailItems.size override fun prepareActionMode(menu: Menu) { menu.apply { @@ -353,9 +366,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, sorted.forEach { key, value -> mediumGroups[key] = value } + + media.forEach { + val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + thumbnailItems.add(thumbnailMedium) + } } - private fun setupView(view: View, medium: Medium) { + private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) photo_name.beVisibleIf(displayFilenames || isListViewType) @@ -387,6 +405,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + private fun setupThumbnailSection(view: View, section: ThumbnailSection) { + view.apply { + + } + } + interface MediaOperationsListener { fun refreshItems() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt new file mode 100644 index 000000000..f53c5df10 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailItem.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.gallery.models + +open class ThumbnailItem diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt new file mode 100644 index 000000000..c0703ed5f --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.gallery.models + +import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS + +data class ThumbnailMedium(val name: String, val path: String, val parentPath: String, val modified: Long, val taken: Long, val size: Long, + val type: Int, val isFavorite: Boolean) : ThumbnailItem() { + fun isVideo() = type == TYPE_VIDEOS +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt new file mode 100644 index 000000000..fc501383f --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailSection.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.gallery.models + +data class ThumbnailSection(val title: String) : ThumbnailItem() From 5ca95e7e35fc291929a480738d472c0099b2357c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 10:38:24 +0200 Subject: [PATCH 029/163] handle thumbnail section adding --- .../gallery/adapters/MediaAdapter.kt | 38 ++++++++++++++++--- app/src/main/res/layout/thumbnail_section.xml | 7 ++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/thumbnail_section.xml 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 dc636309e..070e7e4c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -26,6 +26,7 @@ import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailMedium import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.photo_video_item_grid.view.* +import kotlinx.android.synthetic.main.thumbnail_section.view.* import java.util.* import kotlin.collections.ArrayList @@ -71,7 +72,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid + val layoutType = if (viewType == ITEM_SECTION) { + R.layout.thumbnail_section + } else { + if (isListViewType) { + R.layout.photo_video_item_list + } else { + R.layout.photo_video_item_grid + } + } return createViewHolder(layoutType, parent) } @@ -93,6 +102,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, override fun getItemCount() = thumbnailItems.size + override fun getItemViewType(position: Int): Int { + val tmbItem = thumbnailItems[position] + return if (tmbItem is ThumbnailSection) { + ITEM_SECTION + } else { + ITEM_MEDIUM + } + } + override fun prepareActionMode(menu: Menu) { menu.apply { findItem(R.id.cab_rename).isVisible = isOneItemSelected() @@ -135,7 +153,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, if (!activity.isActivityDestroyed()) { val itemView = holder.itemView visibleItemPaths.remove(itemView?.photo_name?.tag) - Glide.with(activity).clear(itemView?.medium_thumbnail!!) + val tmb = itemView?.medium_thumbnail + if (tmb != null) { + Glide.with(activity).clear(tmb) + } } } @@ -367,9 +388,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, mediumGroups[key] = value } - media.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) + thumbnailItems.clear() + for ((key, value) in mediumGroups) { + thumbnailItems.add(ThumbnailSection(key)) + value.forEach { + val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + thumbnailItems.add(thumbnailMedium) + } } } @@ -407,7 +432,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun setupThumbnailSection(view: View, section: ThumbnailSection) { view.apply { - + thumbnail_section.text = section.title + thumbnail_section.setTextColor(textColor) } } diff --git a/app/src/main/res/layout/thumbnail_section.xml b/app/src/main/res/layout/thumbnail_section.xml new file mode 100644 index 000000000..54218ef69 --- /dev/null +++ b/app/src/main/res/layout/thumbnail_section.xml @@ -0,0 +1,7 @@ + + From 2139b19ca8341046eacfef6d40bf2ff57a59714d Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 11:16:45 +0200 Subject: [PATCH 030/163] make sure item group section titles span across the whole line --- .../gallery/activities/MediaActivity.kt | 11 +++++++++++ .../gallery/adapters/MediaAdapter.kt | 2 ++ app/src/main/res/layout/thumbnail_section.xml | 1 + 3 files changed, 14 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index fdb2b876d..5bdcc90ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -325,6 +325,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { setupZoomListener(mZoomListener) media_grid.adapter = this } + setupLayoutManager() } else { (currAdapter as MediaAdapter).updateMedia(media) } @@ -553,6 +554,16 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } layoutManager.spanCount = config.mediaColumnCnt + val adapter = getMediaAdapter() + layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { + override fun getSpanSize(position: Int): Int { + return if (adapter?.isASectionTitle(position) == true) { + layoutManager.spanCount + } else { + 1 + } + } + } } private fun initZoomListener() { 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 070e7e4c5..7b8c4b5b2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -160,6 +160,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + fun isASectionTitle(position: Int) = thumbnailItems.getOrNull(position) is ThumbnailSection + private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 diff --git a/app/src/main/res/layout/thumbnail_section.xml b/app/src/main/res/layout/thumbnail_section.xml index 54218ef69..8278e2058 100644 --- a/app/src/main/res/layout/thumbnail_section.xml +++ b/app/src/main/res/layout/thumbnail_section.xml @@ -4,4 +4,5 @@ android:id="@+id/thumbnail_section" android:layout_width="match_parent" android:layout_height="wrap_content" + android:padding="@dimen/activity_margin" android:textSize="@dimen/bigger_text_size"/> From 2e178ad645704e2681d81094dec2390df8fc12a4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 11:16:56 +0200 Subject: [PATCH 031/163] properly format section titles as appropriate --- .../gallery/adapters/MediaAdapter.kt | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) 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 7b8c4b5b2..2696a3703 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.adapters import android.os.Handler import android.os.Looper +import android.text.format.DateFormat import android.view.Menu import android.view.View import android.view.ViewGroup @@ -18,9 +19,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE -import com.simplemobiletools.gallery.helpers.GROUP_DESCENDING -import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailMedium @@ -392,7 +391,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, thumbnailItems.clear() for ((key, value) in mediumGroups) { - thumbnailItems.add(ThumbnailSection(key)) + thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) value.forEach { val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) thumbnailItems.add(thumbnailMedium) @@ -400,6 +399,36 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } + private fun getFormattedKey(key: String, grouping: Int): String { + return when { + grouping and GROUP_BY_LAST_MODIFIED != 0 || grouping and GROUP_BY_DATE_TAKEN != 0 -> formatDate(key) + grouping and GROUP_BY_FILE_TYPE != 0 -> getFileTypeString(key) + grouping and GROUP_BY_EXTENSION != 0 -> key.toUpperCase() + grouping and GROUP_BY_FOLDER != 0 -> activity.humanizePath(key) + else -> key + } + } + + private fun formatDate(timestamp: String): String { + return if (timestamp.areDigitsOnly()) { + val cal = Calendar.getInstance(Locale.ENGLISH) + cal.timeInMillis = timestamp.toLong() + DateFormat.format("dd MMM yyyy", cal).toString() + } else { + "" + } + } + + private fun getFileTypeString(key: String): String { + val stringId = when (key.toInt()) { + TYPE_IMAGES -> R.string.images + TYPE_VIDEOS -> R.string.videos + TYPE_GIFS -> R.string.gifs + else -> R.string.raw_images + } + return activity.getString(stringId) + } + private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) From 87ebadfdc680c1c841a09f6df585862f3cb28585 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 12:24:43 +0200 Subject: [PATCH 032/163] avoid selecting section titles at thumbnails view --- app/build.gradle | 2 +- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 2 ++ .../gallery/adapters/ManageFoldersAdapter.kt | 2 ++ .../gallery/adapters/ManageHiddenFoldersAdapter.kt | 2 ++ .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 4 +++- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8e3541d06..b4f3b0e09 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.2.9' + implementation 'com.simplemobiletools:commons:4.2.10' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 3eb4fd15d..375fa60f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -104,6 +104,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList, } } - override fun getSelectableItemCount() = media.size + override fun getSelectableItemCount() = thumbnailItems.filter { it is ThumbnailMedium }.size + + override fun getIsItemSelectable(position: Int) = !isASectionTitle(position) override fun onViewRecycled(holder: ViewHolder) { super.onViewRecycled(holder) From 8cf0e9d7d492be907a088cd6ce4683cd5efaa0f8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 13:18:57 +0200 Subject: [PATCH 033/163] clear mediumGroups before refilling it --- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 1 + 1 file changed, 1 insertion(+) 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 10dce565f..ef03e9aa0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -376,6 +376,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, return } + mediumGroups.clear() media.forEach { val key = it.getGroupingKey(currentGrouping) if (!mediumGroups.containsKey(key)) { From 4617be2238f2bba154c4141490ca91578213aae9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 13:19:12 +0200 Subject: [PATCH 034/163] fix clicked medium type casting --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 5bdcc90ed..c2afe97bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -40,6 +40,7 @@ import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailMedium import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException @@ -320,7 +321,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller, mPath) { - itemClicked((it as Medium).path) + itemClicked((it as ThumbnailMedium).path) }.apply { setupZoomListener(mZoomListener) media_grid.adapter = this From e759270019b70cc5981fda337d50cdf3fb3206aa Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 13:46:37 +0200 Subject: [PATCH 035/163] rely on thumbnailItems at getting selected items at mediaadapter --- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 4 +- .../gallery/adapters/MediaAdapter.kt | 54 +++++++++++-------- .../gallery/extensions/Activity.kt | 8 ++- .../gallery/models/ThumbnailMedium.kt | 16 +++++- 5 files changed, 52 insertions(+), 32 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 c2afe97bc..f570be0e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -356,7 +356,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.media?.getOrNull(index)?.getBubbleText(sorting) ?: "" + private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.getItemBubbleText(index, sorting) ?: "" private fun checkLastMediaChanged() { if (isActivityDestroyed()) 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 d6db52d6b..4e0fadde2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -321,7 +321,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_open_with -> openPath(getCurrentPath(), true) R.id.menu_hide -> toggleFileVisibility(true) R.id.menu_unhide -> toggleFileVisibility(false) - R.id.menu_share -> shareMedium(getCurrentMedium()!!) + R.id.menu_share -> shareMediumPath(getCurrentPath()) R.id.menu_delete -> checkDeleteConfirmation() R.id.menu_rename -> renameFile() R.id.menu_edit -> openEditor(getCurrentPath()) @@ -769,7 +769,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } bottom_share.setOnClickListener { - shareMedium(getCurrentMedium()!!) + shareMediumPath(getCurrentPath()) } bottom_delete.setOnClickListener { 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 ef03e9aa0..3273a7d7f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -166,7 +166,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 - selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + getSelectedMedia().forEach { if (it.name.startsWith('.')) { hiddenCnt++ } else { @@ -181,7 +181,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun checkFavoriteBtnVisibility(menu: Menu) { var favoriteCnt = 0 var nonFavoriteCnt = 0 - selectedPositions.mapNotNull { media.getOrNull(it) }.forEach { + getSelectedMedia().forEach { if (it.isFavorite) { favoriteCnt++ } else { @@ -194,16 +194,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } private fun confirmSelection() { - val paths = getSelectedMedia().map { it.path } as ArrayList - listener?.selectedPaths(paths) + listener?.selectedPaths(getSelectedPaths()) } private fun showProperties() { if (selectedPositions.size <= 1) { - PropertiesDialog(activity, media[selectedPositions.first()].path, config.shouldShowHidden) + PropertiesDialog(activity, (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path, config.shouldShowHidden) } else { - val paths = ArrayList() - selectedPositions.forEach { paths.add(media[it].path) } + val paths = getSelectedPaths() PropertiesDialog(activity, paths, config.shouldShowHidden) } } @@ -255,17 +253,19 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun shareMedia() { if (selectedPositions.size == 1 && selectedPositions.first() != -1) { - activity.shareMedium(getSelectedMedia()[0]) + activity.shareMediumPath(getSelectedMedia().first().path) } else if (selectedPositions.size > 1) { - activity.shareMedia(getSelectedMedia()) + activity.shareMediaPaths(getSelectedPaths()) } } private fun copyMoveTo(isCopyOperation: Boolean) { - val paths = ArrayList() - selectedPositions.forEach { paths.add(media[it].path) } + val paths = getSelectedPaths() + + val fileDirItems = paths.map { + FileDirItem(it, it.getFilenameFromPath()) + } as ArrayList - val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { config.tempFolderPath = "" activity.applicationContext.rescanFolderMedia(it) @@ -293,7 +293,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - private fun getCurrentPath() = media[selectedPositions.first()].path + private fun getCurrentPath() = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path private fun deleteFiles() { if (selectedPositions.isEmpty()) { @@ -301,33 +301,39 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } val fileDirItems = ArrayList(selectedPositions.size) - val removeMedia = ArrayList(selectedPositions.size) + val removeMedia = ArrayList(selectedPositions.size) - if (media.size <= selectedPositions.first()) { + if (thumbnailItems.size <= selectedPositions.first()) { finishActMode() return } - val SAFPath = media[selectedPositions.first()].path + val SAFPath = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { - val medium = media[it] - fileDirItems.add(FileDirItem(medium.path, medium.name)) - removeMedia.add(medium) + val thumbnailItem = thumbnailItems[it] + if (thumbnailItem is ThumbnailMedium) { + fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) + removeMedia.add(thumbnailItem) + } } - media.removeAll(removeMedia) + thumbnailItems.removeAll(removeMedia) listener?.tryDeleteFiles(fileDirItems) removeSelectedItems() } } - private fun getSelectedMedia(): List { - val selectedMedia = ArrayList(selectedPositions.size) - selectedPositions.forEach { selectedMedia.add(media[it]) } + private fun getSelectedMedia(): List { + val selectedMedia = ArrayList(selectedPositions.size) + selectedPositions.forEach { + selectedMedia.add(thumbnailItems[it] as ThumbnailMedium) + } return selectedMedia } + private fun getSelectedPaths() = getSelectedMedia().map { it.path } as ArrayList + fun updateMedia(newMedia: ArrayList) { if (newMedia.hashCode() != currentMediaHash || currentGrouping != config.getFolderGrouping(path)) { currentMediaHash = newMedia.hashCode() @@ -432,6 +438,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, return activity.getString(stringId) } + fun getItemBubbleText(position: Int, sorting: Int) = (thumbnailItems[position] as? ThumbnailMedium)?.getBubbleText(sorting) + private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { play_outline.beVisibleIf(medium.isVideo()) 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 e9ae79e4e..48ae4e495 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -15,7 +15,6 @@ 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.models.Medium import java.io.File import java.util.* @@ -27,12 +26,11 @@ fun Activity.sharePaths(paths: ArrayList) { sharePathsIntent(paths, BuildConfig.APPLICATION_ID) } -fun Activity.shareMedium(medium: Medium) { - sharePath(medium.path) +fun Activity.shareMediumPath(path: String) { + sharePath(path) } -fun Activity.shareMedia(media: List) { - val paths = media.map { it.path } as ArrayList +fun Activity.shareMediaPaths(paths: ArrayList) { sharePaths(paths) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt index c0703ed5f..56124f2a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt @@ -1,8 +1,22 @@ package com.simplemobiletools.gallery.models +import com.simplemobiletools.commons.extensions.formatDate +import com.simplemobiletools.commons.extensions.formatSize +import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED +import com.simplemobiletools.commons.helpers.SORT_BY_NAME +import com.simplemobiletools.commons.helpers.SORT_BY_PATH +import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS data class ThumbnailMedium(val name: String, val path: String, val parentPath: String, val modified: Long, val taken: Long, val size: Long, - val type: Int, val isFavorite: Boolean) : ThumbnailItem() { + val type: Int, var isFavorite: Boolean) : ThumbnailItem() { fun isVideo() = type == TYPE_VIDEOS + + fun getBubbleText(sorting: Int) = when { + sorting and SORT_BY_NAME != 0 -> name + sorting and SORT_BY_PATH != 0 -> path + sorting and SORT_BY_SIZE != 0 -> size.formatSize() + sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() + else -> taken.formatDate() + } } From 698f9b0c767d1c38bf27fe95391561874c70d312 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 14:54:28 +0200 Subject: [PATCH 036/163] handle media grouping at the MediaActivity --- .../gallery/activities/MediaActivity.kt | 13 ++- .../gallery/adapters/MediaAdapter.kt | 109 +++--------------- .../gallery/dialogs/PickMediumDialog.kt | 10 +- .../gallery/helpers/MediaFetcher.kt | 74 ++++++++++++ 4 files changed, 107 insertions(+), 99 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 f570be0e8..1cac18206 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -283,8 +283,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { Thread { val filtered = mMedia.filter { it.name.contains(text, true) } as ArrayList filtered.sortBy { !it.name.startsWith(text, true) } + val groupedMedia = MediaFetcher(applicationContext).groupMedia(filtered, mPath) runOnUiThread { - getMediaAdapter()?.updateMedia(filtered) + getMediaAdapter()?.updateMedia(groupedMedia) } }.start() } @@ -315,12 +316,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return } - val media = mMedia.clone() as ArrayList + val groupedMedia = MediaFetcher(applicationContext).groupMedia(mMedia.clone() as ArrayList, mPath) val currAdapter = media_grid.adapter if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, media, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller, mPath) { + MediaAdapter(this, groupedMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { itemClicked((it as ThumbnailMedium).path) }.apply { setupZoomListener(mZoomListener) @@ -328,8 +329,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } setupLayoutManager() } else { - (currAdapter as MediaAdapter).updateMedia(media) + (currAdapter as MediaAdapter).updateMedia(groupedMedia) } + setupScrollDirection() } @@ -359,8 +361,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.getItemBubbleText(index, sorting) ?: "" private fun checkLastMediaChanged() { - if (isActivityDestroyed()) + if (isActivityDestroyed()) { return + } mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.postDelayed({ 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 3273a7d7f..6055e3893 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.adapters import android.os.Handler import android.os.Looper -import android.text.format.DateFormat import android.view.Menu import android.view.View import android.view.ViewGroup @@ -19,19 +18,16 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* -import com.simplemobiletools.gallery.helpers.* -import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailMedium import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import kotlinx.android.synthetic.main.thumbnail_section.view.* -import java.util.* -import kotlin.collections.ArrayList -class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, val path: String, - itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { +class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, + val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : + MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private val INSTANT_LOAD_DURATION = 2000L private val IMAGE_LOAD_DELAY = 100L @@ -41,13 +37,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private val config = activity.config private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST private var visibleItemPaths = ArrayList() - private var thumbnailItems = ArrayList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() - private var currentGrouping = GROUP_BY_NONE private val hasOTGConnected = activity.hasOTGConnected() - private var mediumGroups = LinkedHashMap>() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -56,7 +49,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, init { setupDragListener(true) - groupMedia() enableInstantLoad() } @@ -84,7 +76,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { - val tmbItem = thumbnailItems.getOrNull(position) ?: return + val tmbItem = media.getOrNull(position) ?: return if (tmbItem is ThumbnailMedium) { visibleItemPaths.add(tmbItem.path) } @@ -99,10 +91,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, bindViewHolder(holder, position, view) } - override fun getItemCount() = thumbnailItems.size + override fun getItemCount() = media.size override fun getItemViewType(position: Int): Int { - val tmbItem = thumbnailItems[position] + val tmbItem = media[position] return if (tmbItem is ThumbnailSection) { ITEM_SECTION } else { @@ -145,7 +137,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - override fun getSelectableItemCount() = thumbnailItems.filter { it is ThumbnailMedium }.size + override fun getSelectableItemCount() = media.filter { it is ThumbnailMedium }.size override fun getIsItemSelectable(position: Int) = !isASectionTitle(position) @@ -161,7 +153,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - fun isASectionTitle(position: Int) = thumbnailItems.getOrNull(position) is ThumbnailSection + fun isASectionTitle(position: Int) = media.getOrNull(position) is ThumbnailSection private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 @@ -199,7 +191,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun showProperties() { if (selectedPositions.size <= 1) { - PropertiesDialog(activity, (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path, config.shouldShowHidden) + PropertiesDialog(activity, (media[selectedPositions.first()] as ThumbnailMedium).path, config.shouldShowHidden) } else { val paths = getSelectedPaths() PropertiesDialog(activity, paths, config.shouldShowHidden) @@ -293,7 +285,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - private fun getCurrentPath() = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path + private fun getCurrentPath() = (media[selectedPositions.first()] as ThumbnailMedium).path private fun deleteFiles() { if (selectedPositions.isEmpty()) { @@ -303,22 +295,22 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val fileDirItems = ArrayList(selectedPositions.size) val removeMedia = ArrayList(selectedPositions.size) - if (thumbnailItems.size <= selectedPositions.first()) { + if (media.size <= selectedPositions.first()) { finishActMode() return } - val SAFPath = (thumbnailItems[selectedPositions.first()] as ThumbnailMedium).path + val SAFPath = (media[selectedPositions.first()] as ThumbnailMedium).path activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { - val thumbnailItem = thumbnailItems[it] + val thumbnailItem = media[it] if (thumbnailItem is ThumbnailMedium) { fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) removeMedia.add(thumbnailItem) } } - thumbnailItems.removeAll(removeMedia) + media.removeAll(removeMedia) listener?.tryDeleteFiles(fileDirItems) removeSelectedItems() } @@ -327,19 +319,18 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private fun getSelectedMedia(): List { val selectedMedia = ArrayList(selectedPositions.size) selectedPositions.forEach { - selectedMedia.add(thumbnailItems[it] as ThumbnailMedium) + selectedMedia.add(media[it] as ThumbnailMedium) } return selectedMedia } private fun getSelectedPaths() = getSelectedMedia().map { it.path } as ArrayList - fun updateMedia(newMedia: ArrayList) { - if (newMedia.hashCode() != currentMediaHash || currentGrouping != config.getFolderGrouping(path)) { + fun updateMedia(newMedia: ArrayList) { + if (newMedia.hashCode() != currentMediaHash) { currentMediaHash = newMedia.hashCode() Handler().postDelayed({ media = newMedia - groupMedia() enableInstantLoad() notifyDataSetChanged() finishActMode() @@ -376,69 +367,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, }, INSTANT_LOAD_DURATION) } - private fun groupMedia() { - currentGrouping = config.getFolderGrouping(path) - if (currentGrouping and GROUP_BY_NONE != 0) { - return - } - - mediumGroups.clear() - media.forEach { - val key = it.getGroupingKey(currentGrouping) - if (!mediumGroups.containsKey(key)) { - mediumGroups[key] = ArrayList() - } - mediumGroups[key]!!.add(it) - } - - val sortDescending = currentGrouping and GROUP_DESCENDING != 0 - val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) - mediumGroups.clear() - sorted.forEach { key, value -> - mediumGroups[key] = value - } - - thumbnailItems.clear() - for ((key, value) in mediumGroups) { - thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) - value.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) - } - } - } - - private fun getFormattedKey(key: String, grouping: Int): String { - return when { - grouping and GROUP_BY_LAST_MODIFIED != 0 || grouping and GROUP_BY_DATE_TAKEN != 0 -> formatDate(key) - grouping and GROUP_BY_FILE_TYPE != 0 -> getFileTypeString(key) - grouping and GROUP_BY_EXTENSION != 0 -> key.toUpperCase() - grouping and GROUP_BY_FOLDER != 0 -> activity.humanizePath(key) - else -> key - } - } - - private fun formatDate(timestamp: String): String { - return if (timestamp.areDigitsOnly()) { - val cal = Calendar.getInstance(Locale.ENGLISH) - cal.timeInMillis = timestamp.toLong() - DateFormat.format("dd MMM yyyy", cal).toString() - } else { - "" - } - } - - private fun getFileTypeString(key: String): String { - val stringId = when (key.toInt()) { - TYPE_IMAGES -> R.string.images - TYPE_VIDEOS -> R.string.videos - TYPE_GIFS -> R.string.gifs - else -> R.string.raw_images - } - return activity.getString(stringId) - } - - fun getItemBubbleText(position: Int, sorting: Int) = (thumbnailItems[position] as? ThumbnailMedium)?.getBubbleText(sorting) + fun getItemBubbleText(position: Int, sorting: Int) = (media[position] as? ThumbnailMedium)?.getBubbleText(sorting) private fun setupThumbnailMedium(view: View, medium: ThumbnailMedium) { view.apply { 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 8a2fb0f4b..58d18bcf4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -12,13 +12,15 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedMedia +import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem import kotlinx.android.synthetic.main.dialog_medium_picker.view.* class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val callback: (path: String) -> Unit) { var dialog: AlertDialog - var shownMedia = ArrayList() + var shownMedia = ArrayList() val view = activity.layoutInflater.inflate(R.layout.dialog_medium_picker, null) var isGridViewType = activity.config.viewTypeFiles == VIEW_TYPE_GRID @@ -31,7 +33,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c dialog = AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) - .setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() }) + .setNeutralButton(R.string.other_folder) { dialogInterface, i -> showOtherFolder() } .create().apply { activity.setupDialogStuff(view, this, R.string.select_photo) } @@ -61,8 +63,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c if (media.hashCode() == shownMedia.hashCode()) return - shownMedia = media - val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid, null, path) { + shownMedia = MediaFetcher(activity).groupMedia(media, path) + val adapter = MediaAdapter(activity, shownMedia, null, true, false, view.media_grid, null) { callback((it as Medium).path) dialog.dismiss() } 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 670523e2e..560f83ca9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -4,14 +4,20 @@ import android.content.Context import android.database.Cursor import android.net.Uri import android.provider.MediaStore +import android.text.format.DateFormat import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* +import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getDistinctPath import com.simplemobiletools.gallery.extensions.getOTGFolderChildren import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem +import com.simplemobiletools.gallery.models.ThumbnailMedium +import com.simplemobiletools.gallery.models.ThumbnailSection import java.io.File +import java.util.* class MediaFetcher(val context: Context) { var shouldStop = false @@ -329,4 +335,72 @@ class MediaFetcher(val context: Context) { result }) } + + fun groupMedia(media: ArrayList, path: String): ArrayList { + val thumbnailItems = ArrayList() + val mediumGroups = LinkedHashMap>() + val currentGrouping = context.config.getFolderGrouping(path) + if (currentGrouping and GROUP_BY_NONE != 0) { + media.forEach { + val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + thumbnailItems.add(thumbnailMedium) + } + return thumbnailItems + } + + media.forEach { + val key = it.getGroupingKey(currentGrouping) + if (!mediumGroups.containsKey(key)) { + mediumGroups[key] = ArrayList() + } + mediumGroups[key]!!.add(it) + } + + val sortDescending = currentGrouping and GROUP_DESCENDING != 0 + val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) + mediumGroups.clear() + sorted.forEach { key, value -> + mediumGroups[key] = value + } + + for ((key, value) in mediumGroups) { + thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) + value.forEach { + val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + thumbnailItems.add(thumbnailMedium) + } + } + + return thumbnailItems + } + + private fun getFormattedKey(key: String, grouping: Int): String { + return when { + grouping and GROUP_BY_LAST_MODIFIED != 0 || grouping and GROUP_BY_DATE_TAKEN != 0 -> formatDate(key) + grouping and GROUP_BY_FILE_TYPE != 0 -> getFileTypeString(key) + grouping and GROUP_BY_EXTENSION != 0 -> key.toUpperCase() + grouping and GROUP_BY_FOLDER != 0 -> context.humanizePath(key) + else -> key + } + } + + private fun formatDate(timestamp: String): String { + return if (timestamp.areDigitsOnly()) { + val cal = Calendar.getInstance(Locale.ENGLISH) + cal.timeInMillis = timestamp.toLong() + DateFormat.format("dd MMM yyyy", cal).toString() + } else { + "" + } + } + + private fun getFileTypeString(key: String): String { + val stringId = when (key.toInt()) { + TYPE_IMAGES -> R.string.images + TYPE_VIDEOS -> R.string.videos + TYPE_GIFS -> R.string.gifs + else -> R.string.raw_images + } + return context.getString(stringId) + } } From 2decc73e39903e0671952e7f2f719d47c08a2d77 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 19:30:34 +0200 Subject: [PATCH 037/163] fetch properly grouped and sorted items by ViewPager --- .../gallery/activities/MediaActivity.kt | 10 +++++++++- .../gallery/activities/ViewPagerActivity.kt | 3 ++- 2 files changed, 11 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 1cac18206..6e9ddcddf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -65,6 +65,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mCurrAsyncTask: GetMediaAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null + private var mMedia = ArrayList() private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -74,7 +75,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mStoredPrimaryColor = 0 companion object { - var mMedia = ArrayList() + var mGroupedMedia = ArrayList() // basically mMedia items reordered depending on the grouping } override fun onCreate(savedInstanceState: Bundle?) { @@ -316,7 +317,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return } + mGroupedMedia.clear() val groupedMedia = MediaFetcher(applicationContext).groupMedia(mMedia.clone() as ArrayList, mPath) + groupedMedia.filter { it is ThumbnailMedium }.forEach { + it as ThumbnailMedium + val medium = Medium(0L, it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) + mGroupedMedia.add(medium) + } + val currAdapter = media_grid.adapter if (currAdapter == null) { initZoomListener() 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 4e0fadde2..c0fa82e95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -84,7 +84,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) - mMediaFiles = MediaActivity.mMedia.clone() as ArrayList + mMediaFiles = MediaActivity.mGroupedMedia.clone() as ArrayList + mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) handlePermission(PERMISSION_WRITE_STORAGE) { From 51182c556354a1607b7dcea4971f32d95c253e86 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 19:59:56 +0200 Subject: [PATCH 038/163] remove ThumbnailMedium, make Medium itself implement ThumbnailItem --- .../gallery/activities/MediaActivity.kt | 9 ++-- .../gallery/adapters/MediaAdapter.kt | 44 +++++++++---------- .../gallery/helpers/MediaFetcher.kt | 14 ++---- .../gallery/models/Medium.kt | 2 +- .../gallery/models/ThumbnailMedium.kt | 22 ---------- 5 files changed, 29 insertions(+), 62 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt 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 6e9ddcddf..eb43adbfb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -40,7 +40,6 @@ import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium -import com.simplemobiletools.gallery.models.ThumbnailMedium import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException @@ -319,10 +318,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mGroupedMedia.clear() val groupedMedia = MediaFetcher(applicationContext).groupMedia(mMedia.clone() as ArrayList, mPath) - groupedMedia.filter { it is ThumbnailMedium }.forEach { - it as ThumbnailMedium - val medium = Medium(0L, it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - mGroupedMedia.add(medium) + groupedMedia.filter { it is Medium }.forEach { + mGroupedMedia.add(it as Medium) } val currAdapter = media_grid.adapter @@ -330,7 +327,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller MediaAdapter(this, groupedMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { - itemClicked((it as ThumbnailMedium).path) + itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) media_grid.adapter = this 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 6055e3893..f20d59461 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -19,8 +19,8 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem -import com.simplemobiletools.gallery.models.ThumbnailMedium import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import kotlinx.android.synthetic.main.thumbnail_section.view.* @@ -77,15 +77,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList - if (tmbItem is ThumbnailMedium) { - setupThumbnailMedium(itemView, tmbItem) + if (tmbItem is Medium) { + setupThumbnail(itemView, tmbItem) } else { - setupThumbnailSection(itemView, tmbItem as ThumbnailSection) + setupSection(itemView, tmbItem as ThumbnailSection) } } bindViewHolder(holder, position, view) @@ -137,7 +137,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList(selectedPositions.size) - val removeMedia = ArrayList(selectedPositions.size) + val removeMedia = ArrayList(selectedPositions.size) if (media.size <= selectedPositions.first()) { finishActMode() return } - val SAFPath = (media[selectedPositions.first()] as ThumbnailMedium).path + val SAFPath = (media[selectedPositions.first()] as Medium).path activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { val thumbnailItem = media[it] - if (thumbnailItem is ThumbnailMedium) { + if (thumbnailItem is Medium) { fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) removeMedia.add(thumbnailItem) } @@ -316,10 +316,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList { - val selectedMedia = ArrayList(selectedPositions.size) + private fun getSelectedMedia(): List { + val selectedMedia = ArrayList(selectedPositions.size) selectedPositions.forEach { - selectedMedia.add(media[it] as ThumbnailMedium) + selectedMedia.add(media[it] as Medium) } return selectedMedia } @@ -367,29 +367,29 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, path: String): ArrayList { - val thumbnailItems = ArrayList() val mediumGroups = LinkedHashMap>() val currentGrouping = context.config.getFolderGrouping(path) if (currentGrouping and GROUP_BY_NONE != 0) { - media.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) - } - return thumbnailItems + return media as ArrayList } media.forEach { @@ -363,12 +357,10 @@ class MediaFetcher(val context: Context) { mediumGroups[key] = value } + val thumbnailItems = ArrayList() for ((key, value) in mediumGroups) { thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) - value.forEach { - val thumbnailMedium = ThumbnailMedium(it.name, it.path, it.parentPath, it.modified, it.taken, it.size, it.type, it.isFavorite) - thumbnailItems.add(thumbnailMedium) - } + thumbnailItems.addAll(value) } return thumbnailItems 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 1097f935f..66ce260fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -25,7 +25,7 @@ data class Medium( @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "type") val type: Int, - @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable { + @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable, ThumbnailItem() { companion object { private const val serialVersionUID = -6553149366975455L diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt deleted file mode 100644 index 56124f2a3..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/ThumbnailMedium.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.simplemobiletools.gallery.models - -import com.simplemobiletools.commons.extensions.formatDate -import com.simplemobiletools.commons.extensions.formatSize -import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED -import com.simplemobiletools.commons.helpers.SORT_BY_NAME -import com.simplemobiletools.commons.helpers.SORT_BY_PATH -import com.simplemobiletools.commons.helpers.SORT_BY_SIZE -import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS - -data class ThumbnailMedium(val name: String, val path: String, val parentPath: String, val modified: Long, val taken: Long, val size: Long, - val type: Int, var isFavorite: Boolean) : ThumbnailItem() { - fun isVideo() = type == TYPE_VIDEOS - - fun getBubbleText(sorting: Int) = when { - sorting and SORT_BY_NAME != 0 -> name - sorting and SORT_BY_PATH != 0 -> path - sorting and SORT_BY_SIZE != 0 -> size.formatSize() - sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate() - else -> taken.formatDate() - } -} From 12ed9a66c1cc4a42f6b53c178c8a8922ff143fda Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 20:33:35 +0200 Subject: [PATCH 039/163] group media right after fetching, while still on a background thread --- .../gallery/activities/MainActivity.kt | 5 +++- .../gallery/activities/MediaActivity.kt | 27 +++++++------------ .../gallery/activities/ViewPagerActivity.kt | 9 ++++--- .../gallery/asynctasks/GetMediaAsynctask.kt | 14 +++++----- .../gallery/dialogs/PickMediumDialog.kt | 11 ++++---- .../gallery/extensions/Context.kt | 19 ++++++++----- 6 files changed, 45 insertions(+), 40 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 c6d324019..9a6ab9cb4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -648,7 +648,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { it.forEach { if (!curMedia.contains(it)) { - mediumDao.deleteMediumPath(it.path) + val path = (it as? Medium)?.path + if (path != null) { + mediumDao.deleteMediumPath(path) + } } } } 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 eb43adbfb..8578357b2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -40,6 +40,7 @@ import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException @@ -64,7 +65,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mCurrAsyncTask: GetMediaAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null - private var mMedia = ArrayList() private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -74,7 +74,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mStoredPrimaryColor = 0 companion object { - var mGroupedMedia = ArrayList() // basically mMedia items reordered depending on the grouping + var mMedia = ArrayList() } override fun onCreate(savedInstanceState: Bundle?) { @@ -281,11 +281,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun searchQueryChanged(text: String) { Thread { - val filtered = mMedia.filter { it.name.contains(text, true) } as ArrayList - filtered.sortBy { !it.name.startsWith(text, true) } - val groupedMedia = MediaFetcher(applicationContext).groupMedia(filtered, mPath) + val filtered = mMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList + filtered.sortBy { it is Medium && !it.name.startsWith(text, true) } runOnUiThread { - getMediaAdapter()?.updateMedia(groupedMedia) + getMediaAdapter()?.updateMedia(filtered) } }.start() } @@ -316,17 +315,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return } - mGroupedMedia.clear() - val groupedMedia = MediaFetcher(applicationContext).groupMedia(mMedia.clone() as ArrayList, mPath) - groupedMedia.filter { it is Medium }.forEach { - mGroupedMedia.add(it as Medium) - } - val currAdapter = media_grid.adapter if (currAdapter == null) { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller - MediaAdapter(this, groupedMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { + MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { itemClicked((it as Medium).path) }.apply { setupZoomListener(mZoomListener) @@ -334,7 +327,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } setupLayoutManager() } else { - (currAdapter as MediaAdapter).updateMedia(groupedMedia) + (currAdapter as MediaAdapter).updateMedia(mMedia) } setupScrollDirection() @@ -682,12 +675,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - private fun gotMedia(media: ArrayList, isFromCache: Boolean = false) { - val mediaToInsert = media.clone() as ArrayList + private fun gotMedia(media: ArrayList, isFromCache: Boolean = false) { Thread { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { + val mediaToInsert = (mMedia.clone() as ArrayList).filter { it is Medium }.map { it as Medium } galleryDB.MediumDao().insertAll(mediaToInsert) } }.start() @@ -718,7 +711,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return@deleteFiles } - mMedia.removeAll { filtered.map { it.path }.contains(it.path) } + mMedia.removeAll { filtered.map { it.path }.contains((it as? Medium)?.path) } Thread { val mediumDao = galleryDB.MediumDao() 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 c0fa82e95..015eafa9a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -44,6 +44,7 @@ import com.simplemobiletools.gallery.fragments.VideoFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem import kotlinx.android.synthetic.main.activity_medium.* import kotlinx.android.synthetic.main.bottom_actions.* import java.io.File @@ -84,8 +85,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) - mMediaFiles = MediaActivity.mGroupedMedia.clone() as ArrayList - + (MediaActivity.mMedia.clone() as ArrayList).filter { it is Medium }.mapTo(mMediaFiles) { it as Medium } mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) handlePermission(PERMISSION_WRITE_STORAGE) { @@ -225,7 +225,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View view_pager.onGlobalLayout { if (!isActivityDestroyed()) { if (mMediaFiles.isNotEmpty()) { - gotMedia(mMediaFiles) + gotMedia(mMediaFiles as ArrayList) } } } @@ -884,7 +884,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View }.execute() } - private fun gotMedia(media: ArrayList) { + private fun gotMedia(thumbnailItems: ArrayList) { + val media = thumbnailItems.filter { it is Medium }.map { it as Medium } as ArrayList if (isDirEmpty(media) || media.hashCode() == mPrevHashcode) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 07b9bb630..d99d5f370 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -7,17 +7,18 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getFavoritePaths import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem import java.util.* class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage: Boolean = false, val isPickVideo: Boolean = false, - val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : - AsyncTask>() { + val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : + AsyncTask>() { private val mediaFetcher = MediaFetcher(context) - override fun doInBackground(vararg params: Void): ArrayList { + override fun doInBackground(vararg params: Void): ArrayList { val getProperDateTaken = context.config.getFileSorting(mPath) and SORT_BY_DATE_TAKEN != 0 val favoritePaths = context.getFavoritePaths() - return if (showAll) { + val media = if (showAll) { val foldersToScan = mediaFetcher.getFoldersToScan() val media = ArrayList() foldersToScan.forEach { @@ -25,14 +26,15 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage media.addAll(newMedia) } - MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) + mediaFetcher.sortMedia(media, context.config.getFileSorting("")) media } else { mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } + return mediaFetcher.groupMedia(media, mPath) } - override fun onPostExecute(media: ArrayList) { + override fun onPostExecute(media: ArrayList) { super.onPostExecute(media) callback(media) } 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 58d18bcf4..dbdd77856 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -12,7 +12,6 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedMedia -import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem @@ -39,7 +38,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c } activity.getCachedMedia(path) { - val media = it.filter { !it.isVideo() } as ArrayList + val media = it.filter { it is Medium && !it.isVideo() } as ArrayList if (media.isNotEmpty()) { activity.runOnUiThread { gotMedia(media) @@ -59,11 +58,11 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c } } - private fun gotMedia(media: ArrayList) { + private fun gotMedia(media: ArrayList) { if (media.hashCode() == shownMedia.hashCode()) return - shownMedia = MediaFetcher(activity).groupMedia(media, path) + shownMedia = media val adapter = MediaAdapter(activity, shownMedia, null, true, false, view.media_grid, null) { callback((it as Medium).path) dialog.dismiss() @@ -83,12 +82,12 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c if (scrollHorizontally) { media_horizontal_fastscroller.allowBubbleDisplay = activity.config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid) { - media_horizontal_fastscroller.updateBubbleText(media[it].getBubbleText(sorting)) + media_horizontal_fastscroller.updateBubbleText((media[it] as? Medium)?.getBubbleText(sorting) ?: "") } } else { media_vertical_fastscroller.allowBubbleDisplay = activity.config.showInfoBubble media_vertical_fastscroller.setViews(media_grid) { - media_vertical_fastscroller.updateBubbleText(media[it].getBubbleText(sorting)) + media_vertical_fastscroller.updateBubbleText((media[it] as? Medium)?.getBubbleText(sorting) ?: "") } } } 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 c4049327e..368b97ffe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -26,6 +26,7 @@ import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.interfaces.DirectoryDao import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium +import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.views.MySquareImageView import pl.droidsonroids.gif.GifDrawable import java.io.File @@ -163,11 +164,15 @@ fun Context.rescanFolderMediaSync(path: String) { Thread { val newMedia = it val mediumDao = galleryDB.MediumDao() - mediumDao.insertAll(newMedia) + val media = newMedia.filter { it is Medium } as ArrayList + mediumDao.insertAll(media) cached.forEach { if (!newMedia.contains(it)) { - mediumDao.deleteMediumPath(it.path) + val mediumPath = (it as? Medium)?.path + if (mediumPath != null) { + mediumDao.deleteMediumPath(mediumPath) + } } } }.start() @@ -315,10 +320,11 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: }.start() } -fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { +fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { Thread { + val mediaFetcher = MediaFetcher(this) val mediumDao = galleryDB.MediumDao() - val foldersToScan = if (path.isEmpty()) MediaFetcher(this).getFoldersToScan() else arrayListOf(path) + val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path) var media = ArrayList() if (path == FAVORITES) { media.addAll(mediumDao.getFavorites()) @@ -349,8 +355,9 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag } }) as ArrayList - MediaFetcher(this).sortMedia(media, config.getFileSorting(path)) - callback(media.clone() as ArrayList) + mediaFetcher.sortMedia(media, config.getFileSorting(path)) + val grouped = mediaFetcher.groupMedia(media, path) + callback(grouped.clone() as ArrayList) media.filter { !getDoesFilePathExist(it.path) }.forEach { mediumDao.deleteMediumPath(it.path) From 9520a25f62b87f7c4ca7b25fb7df0b967fdf4d1a Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 20:57:19 +0200 Subject: [PATCH 040/163] do not allow clicking or long pressing thumbnail sections --- .../simplemobiletools/gallery/activities/MediaActivity.kt | 4 +++- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 3 ++- .../simplemobiletools/gallery/dialogs/PickMediumDialog.kt | 6 ++++-- 3 files changed, 9 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 8578357b2..c36cc7191 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -320,7 +320,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid, fastscroller) { - itemClicked((it as Medium).path) + if (it is Medium) { + itemClicked(it.path) + } }.apply { setupZoomListener(mZoomListener) media_grid.adapter = this 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 f20d59461..eddf5d004 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -81,7 +81,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList + val allowLongPress = !allowMultiplePicks && tmbItem is Medium + val view = holder.bindView(tmbItem, allowLongPress) { itemView, adapterPosition -> if (tmbItem is Medium) { setupThumbnail(itemView, tmbItem) } else { 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 dbdd77856..1a45671cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -64,8 +64,10 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c shownMedia = media val adapter = MediaAdapter(activity, shownMedia, null, true, false, view.media_grid, null) { - callback((it as Medium).path) - dialog.dismiss() + if (it is Medium) { + callback(it.path) + dialog.dismiss() + } } val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType From d8104c3ce8ba35bd07a7c212a0e0c20efff003aa Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 21:09:54 +0200 Subject: [PATCH 041/163] update Room to 1.1.1 --- app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b4f3b0e09..e9d3681f5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,9 +55,9 @@ dependencies { implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.2' - kapt "android.arch.persistence.room:compiler:1.1.0" - implementation "android.arch.persistence.room:runtime:1.1.0" - annotationProcessor "android.arch.persistence.room:compiler:1.1.0" + kapt "android.arch.persistence.room:compiler:1.1.1" + implementation "android.arch.persistence.room:runtime:1.1.1" + annotationProcessor "android.arch.persistence.room:compiler:1.1.1" //implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0' implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.0-fork' From 8e1cd62c7cbbd2b83dd9e117d97e23c12e251ea7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 21:14:30 +0200 Subject: [PATCH 042/163] really disallow clicking on thumbnail section titles --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- app/src/main/res/layout/thumbnail_section.xml | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e9d3681f5..4aa3731e4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.2.10' + implementation 'com.simplemobiletools:commons:4.2.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/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 375fa60f3..87daaf994 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -62,7 +62,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + val view = holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition -> setupView(itemView, dir) } bindViewHolder(holder, position, view) 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 eddf5d004..f1ba47f62 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -82,7 +82,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList + val view = holder.bindView(tmbItem, tmbItem is Medium, allowLongPress) { itemView, adapterPosition -> if (tmbItem is Medium) { setupThumbnail(itemView, tmbItem) } else { diff --git a/app/src/main/res/layout/thumbnail_section.xml b/app/src/main/res/layout/thumbnail_section.xml index 8278e2058..65d51f7df 100644 --- a/app/src/main/res/layout/thumbnail_section.xml +++ b/app/src/main/res/layout/thumbnail_section.xml @@ -4,5 +4,6 @@ android:id="@+id/thumbnail_section" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clickable="false" android:padding="@dimen/activity_margin" android:textSize="@dimen/bigger_text_size"/> From cd79467ff629a04bc6b84f8cc5aa3f72544c01cc Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 21:18:39 +0200 Subject: [PATCH 043/163] avoid showing empty fastscroller bubble if the current item is a section --- .../gallery/activities/MediaActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 c36cc7191..66b5278f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -358,7 +358,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - private fun getBubbleTextItem(index: Int, sorting: Int) = getMediaAdapter()?.getItemBubbleText(index, sorting) ?: "" + private fun getBubbleTextItem(index: Int, sorting: Int): String { + var realIndex = index + val mediaAdapter = getMediaAdapter() + if (mediaAdapter?.isASectionTitle(index) == true) { + realIndex++ + } + return mediaAdapter?.getItemBubbleText(realIndex, sorting) ?: "" + } private fun checkLastMediaChanged() { if (isActivityDestroyed()) { From b61e3b7d3d08889df36276935a8ee47139e01800 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 21:37:09 +0200 Subject: [PATCH 044/163] fix thumbnail grouping at Search --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 66b5278f5..ca323870a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -274,6 +274,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { mIsSearchOpen = false media_refresh_layout.isEnabled = config.enablePullToRefresh + searchQueryChanged("") return true } }) @@ -283,8 +284,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { Thread { val filtered = mMedia.filter { it is Medium && it.name.contains(text, true) } as ArrayList filtered.sortBy { it is Medium && !it.name.startsWith(text, true) } + val grouped = MediaFetcher(applicationContext).groupMedia(filtered as ArrayList, mPath) runOnUiThread { - getMediaAdapter()?.updateMedia(filtered) + getMediaAdapter()?.updateMedia(grouped) } }.start() } From dc65539094dccb8b2a37903ae9f4adddf996d301 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 22:38:04 +0200 Subject: [PATCH 045/163] adding a FAQ item about thumbnail grouping --- .../kotlin/com/simplemobiletools/gallery/extensions/Activity.kt | 1 + app/src/main/res/values-ar/strings.xml | 2 ++ app/src/main/res/values-ca/strings.xml | 2 ++ app/src/main/res/values-cs/strings.xml | 2 ++ app/src/main/res/values-da/strings.xml | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-el/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-fi/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-gl/strings.xml | 2 ++ app/src/main/res/values-hr/strings.xml | 2 ++ app/src/main/res/values-hu/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-ko-rKR/strings.xml | 2 ++ app/src/main/res/values-lt/strings.xml | 2 ++ app/src/main/res/values-nb/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values-pl/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-sk/strings.xml | 2 ++ app/src/main/res/values-sv/strings.xml | 2 ++ app/src/main/res/values-tr/strings.xml | 2 ++ app/src/main/res/values-zh-rCN/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 29 files changed, 57 insertions(+) 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 48ae4e495..8ae591cb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -68,6 +68,7 @@ fun SimpleActivity.launchAbout() { FAQItem(R.string.faq_8_title, R.string.faq_8_text), FAQItem(R.string.faq_9_title, R.string.faq_9_text), FAQItem(R.string.faq_10_title, R.string.faq_10_text), + FAQItem(R.string.faq_11_title, R.string.faq_11_text), FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons)) startAboutActivity(R.string.app_name, LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 007b4bff8..5cdd6fabb 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -180,6 +180,8 @@ نعم ، هناك تبديل في الإعدادات يقول \"استبدل صورًا ذات زووم عميق بجودة أفضل منها\" ، يمكنك استخدام ذلك. سيؤدي ذلك إلى تحسين جودة الصور ، ولكن ستظهر بشكل واضح عند محاولة التكبير كثيرًا. هل يمكنني قص الصور باستخدام هذا التطبيق؟ نعم ، يمكنك اقتصاص الصور في المحرر ، عن طريق سحب زوايا الصورة. يمكنك الوصول إلى المحرر إما عن طريق الضغط لفترة طويلة على صورة مصغرة وتحديد تحرير ، أو تحديد تحرير من العرض بملء الشاشة. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index e89acd681..dea3a22f2 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -178,6 +178,8 @@ Sí, hi ha un commutador a la configuració que diu \"Substituïu imatges ampliades i de gran qualitat\", podeu fer-ho. Millora la qualitat de les imatges, però es borraran una vegada que intenteu fer zoom massa. Puc retallar imatges amb aquesta aplicació? Sí, pots retallar imatges a l\'editor, arrossegant les cantonades de la imatge. Pots accedir a l\'editor prement una miniatura d\'imatge i seleccionant Edita o seleccionant Edita des de la visualització de pantalla completa. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index d75d1e2ce..5bf09aab9 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index df8088856..544dd17bf 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c3bee513c..fc8facfd1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -178,6 +178,8 @@ Ja, es gibt einen Schalter in den Einstellungen gekennzeichnet mit \"Stark zoombare Bilder durch Bilder mit hoher Qualität ersetzen\". Dieser wird die Bildqualität verbessern, aber sie werden bei sehr hoher Zoomstufe unscharf. Kann ich mit dieser App Bilder zuschneiden? Ja, du kannst Bilder über das Ziehen der Bildecken im Editor zuschneiden. Du gelangst zum Editor indem du lange auf ein Vorschaubild drückst und Bearbeiten auswählst oder durch Auswählen von Bearbeiten in der Vollbildansicht. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index dc4f69114..8b922c1ce 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -177,6 +177,8 @@ Αυτό θα κάνει ορατούς μόνο τους επιλεγμένους φακέλους, καθώς η εξαίρεση και η συμπερίληψη λειτουργούν αναδρομικά και αν ενας φάκελος ανήκει και στα δύο, θα εμφανιστεί. Οι εικόνες πλήρους οθόνης έχουν κάποια περίεργα σημάδια. Μπορώ κάπως να βελτιώσω την ποιότητα; Ναι. Υπάρχει ένας διακόπτης στις Ρυθμίσεις με το κείμενο \"Αντικατάσταση των φωτογραφιών που απαιτούν ζούμ με άλλες καλύτερης ποιότητας\". Μπορείτε να χρησιμοποιήσετε αυτό. Θα βελτιώσει την ποιότητα των φωτογραφιών, αλλά θα θολώσουν στο μεγάλο ζουμ. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index db762f7b7..be9227426 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -178,6 +178,8 @@ Sí, hay una alternancia en Configuración que dice \"Reemplazar imágenes con zoom profundo con las de mejor calidad\", puedes usar eso. Mejorará la calidad de las imágenes, pero se volverán borrosas una vez que intente ampliar demasiado. ¿Puedo recortar imágenes con esta aplicación? Sí, puede recortar imágenes en el editor arrastrando las esquinas de la imagen. Puede acceder al editor pulsando prolongadamente una imagen en miniatura y seleccionando Editar, o seleccionando Editar en la vista de pantalla completa. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index cec932677..ca2269c62 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 704f7ed5c..038f24828 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -177,6 +177,8 @@ Oui, il existe dans « Paramètres » une option « Remplacer les images zoomables profondes par des images de meilleure qualité », mais les images seront alors floues si vous zoomez trop. Puis-je recadrer des images avec cette application? Oui, vous pouvez recadrer les images dans l\'éditeur en faisant glisser les coins de l\'image. Vous pouvez accéder à l\'éditeur en appuyant longuement sur une vignette d\'image et en sélectionnant Modifier, ou en sélectionnant Modifier en mode plein écran. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index 3e93aac93..d5611b2a6 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -178,6 +178,8 @@ Si, hai unha opción en Axustes que di \"Substituír imaxes con un gran zoom con imaxes de mellor calidade\", pode usar eso. mellorará a calidade das imaxes, mais farase máis borrosaxa si intenta facer moito zoom. 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 403bc5513..e188d3711 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -178,6 +178,8 @@ Da, u "Postavkama" postoji opcija "Zamjena duboko zumiranih slika s kvalitetnijim slikama", ali slike će biti zamućene ako zumirate previše. Mogu li izrezati slike pomoću ove aplikacije? Da, možete obrezati slike u uređivaču povlačenjem uglova. Možete doći do uređivača dugim pritiskom na minijaturu slike i odabirom Uređivanje ili odabirom Uredi iz prikaza preko cijelog zaslona. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 3711293f5..07eb7b9dc 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 53c9dc299..3a28f6b5d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index c5ca12576..6444c9520 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index bb6804892..12a18a9be 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 96011e86e..e47b407de 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -178,6 +178,8 @@ Taip, "Nustatymuose" perjunkite \ "Pakeisti giliuosius, patobulintus vaizdus geresnės kokybės vaizdais \", galite tai naudoti. Tai pagerins vaizdų kokybę, tačiau kai jūs pabandysite per daug padidinti vaizdą, jie bus neryškūs. Ar galiu apkarpyti vaizdus naudojant šią programėlę? Taip, redaguodami vaizdus, galite juos apkarpyti, vilkdami vaizdo kampus. Galite patekti į redaktorių ilgai paspaudę vaizdo miniatiūrą ir pasirinkę "Redaguoti" arba iš viso ekrano rodinio pasirinkę "Redaguoti". + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 5ea56bfbd..0131bdd3b 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 8e12577dd..252005e38 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index e6232ee27..7aea01fd1 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -176,6 +176,8 @@    U ustawieniach aplikacji włącz opcję \'Zamieniaj powiększalne obrazy na te o lepszej jakości\'. Poprawi ona jakość zdjęć, jednak przy bardzo dużych powiększeniach mogą się stać one zbyt rozmazane. Czy mogę w tej aplikacji przycinać obrazy? Tak, możesz to zrobić w edytorze, przeciągając krawędzie obrazu. Edytor otworzysz przytrzymując miniaturę obrazu i wybierając opcję \'Edytuj\', bądź wybierając tą samą opcję w menu pełnoekranowym. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 52c6f82c4..1d44b3c2c 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 67cf01651..4a296084f 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 342195f80..959ab53d7 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -178,6 +178,8 @@ Да, в настройках есть переключатель \"Заменять масштабируемые изображения высококачественными\", использовуйте его. Это улучшит качество изображений, но они будут размыты, если вы попытаетесь сильно увеличить масштаб отображения. Можно ли обрезать изображения с помощью данного приложения? Да, вы можете обрезать изображения в редакторе, перетаскивая за углы. К редактированию можно перейти, выбрав соответсвующий пункт в меню, открывающемуся длительным нажатием на миниатюру или изображение в полноэкранном режиме. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 9d8fb036f..ff6757200 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -178,6 +178,8 @@ Áno, v nastaveniach je prepínač s textom \"Nahradiť hlboko priblížiteľné obrázky s obrázkami s lepšou kvalitou\", môžete ho skúsiť. Spôsobí to vyššiu kvalitu obrázkov, po priblížení sa ale budú rozmazávať oveľa skôr. Dá sa s touto aplikáciou orezať obrázky? Áno, orezanie je možné v editore, potiahnutím rohov obrázkov. Do editoru sa môžete dostať buď dlhým podržaním náhľadu obrázku a zvolením menu položky Upraviť, alebo zvolením Upraviť pri celoobrazovkovom režime. + Viem nejakým spôsobom zoskupiť náhľady súborov? + Áno, použitím funkcie \"Zoskupiť podľa\" na menu obrazovky s náhľadmi. Zoskupenie je možné na základe rozličných kritérií vrátane Dátumu vytvorenia. Ak použijete funkciu \"Zobraziť obsah všetkých priečinkov\", viete ich zoskupiť aj podľa priečinkov. diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 989736b9d..254b91f01 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 63c4966fc..e6b31504d 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 655f35f8e..573b2d631 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -176,6 +176,8 @@ 在设置中有一个“用质量更好的图像替换可深度缩放的图像”开关,打开它后就可以提高图像的显示质量,但是一旦尝试放大太多次,它们就又会变得模糊不清。 可以裁剪图片吗? 当然,通过长按图片缩略图并选择编辑,或在全屏视图中选择编辑来打开编辑器。你可以通过拖动图片边角来剪裁图像。 + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e9ddc409a..6e93b84db 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -178,6 +178,8 @@ 可啊,[設定]內有個開關叫做「可深度縮放的圖片用品質更佳的來取代」,你能用用看。這會提高圖片的品質,不過一旦你放大太多就會模糊掉。 我可以用這程式裁減圖片嗎? 是的,你能夠在編輯器內拉動圖片角落來裁剪圖片。要進入編輯器,你可以長按圖片縮圖然後選擇[編輯],或是在全螢幕檢視下選擇[編輯]。 + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 199e012db..663722392 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -178,6 +178,8 @@ 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. + Can I somehow group media file thumbnails? + Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. From e5da025335be5ca832cebb6c30237d561b1f2675 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 22 Jun 2018 23:39:02 +0200 Subject: [PATCH 046/163] remove an unused activity_splash layout file --- app/src/main/res/layout/activity_splash.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 app/src/main/res/layout/activity_splash.xml diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml deleted file mode 100644 index 9a0069a92..000000000 --- a/app/src/main/res/layout/activity_splash.xml +++ /dev/null @@ -1,6 +0,0 @@ - - From f6231bf517e43c0b5f210ff21dd94c7b113cdd89 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 23 Jun 2018 09:41:26 +0200 Subject: [PATCH 047/163] properly measure recyclerview content height when content changes --- app/build.gradle | 2 +- .../gallery/activities/MediaActivity.kt | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 4aa3731e4..c6bdcaf90 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.2.11' + implementation 'com.simplemobiletools:commons:4.2.13' 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 ca323870a..b23f895e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -41,6 +41,7 @@ import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem +import com.simplemobiletools.gallery.models.ThumbnailSection import kotlinx.android.synthetic.main.activity_media.* import java.io.File import java.io.IOException @@ -60,6 +61,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mIsSearchOpen = false private var mLatestMediaId = 0L private var mLatestMediaDateId = 0L + private var mSectionTitleHeight = 0 + private var mThumbnailHeight = 0 private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetMediaAsynctask? = null @@ -287,6 +290,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val grouped = MediaFetcher(applicationContext).groupMedia(filtered as ArrayList, mPath) runOnUiThread { getMediaAdapter()?.updateMedia(grouped) + measureRecyclerViewContent(grouped) } }.start() } @@ -334,6 +338,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { (currAdapter as MediaAdapter).updateMedia(mMedia) } + measureRecyclerViewContent(mMedia) setupScrollDirection() } @@ -579,6 +584,33 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun measureRecyclerViewContent(media: ArrayList) { + val layoutManager = media_grid.layoutManager as MyGridLayoutManager + media_grid.onGlobalLayout { + val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 + mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 + mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height ?: 0 + + var fullHeight = 0 + var curSectionItems = 0 + media.forEach { + if (it is ThumbnailSection) { + fullHeight += mSectionTitleHeight + if (curSectionItems != 0) { + val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) + fullHeight += rows * mThumbnailHeight + } + curSectionItems = 0 + } else { + curSectionItems++ + } + } + + fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight + media_vertical_fastscroller.setContentHeight(fullHeight) + } + } + private fun initZoomListener() { if (config.viewTypeFiles == VIEW_TYPE_GRID) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager From b9263cf09069c6bf5602839670ef493899056d2b Mon Sep 17 00:00:00 2001 From: unbranched Date: Sun, 24 Jun 2018 15:34:40 +0200 Subject: [PATCH 048/163] Italian update --- app/src/main/res/values-it/strings.xml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3a28f6b5d..d5d09cc84 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -10,7 +10,7 @@ Sblocca cartella Fissa in alto Mostra tutti i contenuti - Tutti i media + Tutte le cartelle Visualizza a cartelle Altra cartella Mostra sulla mappa @@ -30,7 +30,7 @@ Immagini Video GIF - RAW images + Immagini RAW Nessun file trovato per il filtro selezionato. Cambia filtro @@ -111,16 +111,16 @@ Cambia modalità visualizzazione Griglia Elenco - Group direct subfolders + Raggruppa sottocartelle dirette - Group by - Do not group files - Folder - Last modified - Date taken - File type - Extension + Raggruppa per + Non raggruppare i file + Cartella + Ultima modifica + Data creazione + Tipo di file + Estensione Riproduci i video automaticamente @@ -148,7 +148,7 @@ Sostituisci le immagini ingrandibili a fondo con altre di migliore qualità Nascondi i dettagli estesi quando la barra di stato è nascosta Fai un controllo ulteriore per evitare di mostrare file non validi - Show some action buttons at the bottom of the screen + Mostra alcuni pulsanti azione in fondo allo schermo Miniature @@ -178,8 +178,8 @@ 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. - Can I somehow group media file thumbnails? - Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. + Posso raggruppare in qualche modo le miniature dei file? + Certo, usa il menu \"Raggruppa per\" mentre visualizzi le miniature. Puoi raggruppare i file con diversi criteri, incluso la data di creazione. Se utilizzi la funzione \"Mostra tutti i contenuti\" puoi anche raggrupparli per cartelle. From d69351fa99f21bb309d804e20a9ce8dec94c34bc Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 15:46:14 +0200 Subject: [PATCH 049/163] avoid doing any action on Search Collapsed during device rotation --- .../gallery/activities/MediaActivity.kt | 9 ++++++--- 1 file changed, 6 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 b23f895e8..6d51be4fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -274,10 +274,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return true } + // this triggers on device rotation too, avoid doing anything override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { - mIsSearchOpen = false - media_refresh_layout.isEnabled = config.enablePullToRefresh - searchQueryChanged("") + if (mIsSearchOpen) { + mIsSearchOpen = false + media_refresh_layout.isEnabled = config.enablePullToRefresh + searchQueryChanged("") + } return true } }) From 92fc3ec90c61b22e810e4de6c520b1d8c46e3ae8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 18:07:01 +0200 Subject: [PATCH 050/163] recreate the MediaAdapter in some extra cases --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/MediaActivity.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index c6bdcaf90..3692780c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.2.13' + implementation 'com.simplemobiletools:commons:4.3.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' 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 6d51be4fb..a24de85c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -403,6 +403,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun showSortingDialog() { ChangeSortingDialog(this, false, !config.showAll, mPath) { mLoadedInitialPhotos = false + media_grid.adapter = null getMedia() } } @@ -411,6 +412,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { FilterMediaDialog(this) { mLoadedInitialPhotos = false media_refresh_layout.isRefreshing = true + media_grid.adapter = null getMedia() } } @@ -443,6 +445,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun showGroupByDialog() { ChangeGroupingDialog(this, mShowAll, mPath) { mLoadedInitialPhotos = false + media_grid.adapter = null getMedia() } } @@ -651,6 +654,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { config.mediaColumnCnt = ++(media_grid.layoutManager as MyGridLayoutManager).spanCount invalidateOptionsMenu() media_grid.adapter?.notifyDataSetChanged() + measureRecyclerViewContent(mMedia) } private fun reduceColumnCount() { @@ -659,6 +663,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { config.mediaColumnCnt = --(media_grid.layoutManager as MyGridLayoutManager).spanCount invalidateOptionsMenu() media_grid.adapter?.notifyDataSetChanged() + measureRecyclerViewContent(mMedia) } private fun isSetWallpaperIntent() = intent.getBooleanExtra(SET_WALLPAPER_INTENT, false) From 8e4aa5b438b7592ec99a89ff533d9da62ca410ae Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 18:11:30 +0200 Subject: [PATCH 051/163] do not remeasure recyclerview size at column count change, we set it manually --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 4 ---- 1 file changed, 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 a24de85c4..d28e528a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -649,8 +649,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun increaseColumnCount() { - media_vertical_fastscroller.measureRecyclerViewOnRedraw() - media_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.mediaColumnCnt = ++(media_grid.layoutManager as MyGridLayoutManager).spanCount invalidateOptionsMenu() media_grid.adapter?.notifyDataSetChanged() @@ -658,8 +656,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun reduceColumnCount() { - media_vertical_fastscroller.measureRecyclerViewOnRedraw() - media_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.mediaColumnCnt = --(media_grid.layoutManager as MyGridLayoutManager).spanCount invalidateOptionsMenu() media_grid.adapter?.notifyDataSetChanged() From 185e4dcb6cf45e2b36fe0ad94b3072156ea3116a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 18:31:31 +0200 Subject: [PATCH 052/163] recalculate fastscroller position at measuring content --- .../gallery/activities/MediaActivity.kt | 9 ++++++--- 1 file changed, 6 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 d28e528a3..61721dbca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -614,6 +614,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight media_vertical_fastscroller.setContentHeight(fullHeight) + media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) } } @@ -650,13 +651,15 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun increaseColumnCount() { config.mediaColumnCnt = ++(media_grid.layoutManager as MyGridLayoutManager).spanCount - invalidateOptionsMenu() - media_grid.adapter?.notifyDataSetChanged() - measureRecyclerViewContent(mMedia) + columnCountChanged() } private fun reduceColumnCount() { config.mediaColumnCnt = --(media_grid.layoutManager as MyGridLayoutManager).spanCount + columnCountChanged() + } + + private fun columnCountChanged() { invalidateOptionsMenu() media_grid.adapter?.notifyDataSetChanged() measureRecyclerViewContent(mMedia) From 2d8ab6647df489faae124bff83f18c681b8fe6d4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 18:59:07 +0200 Subject: [PATCH 053/163] recreate directories grid at changing sorting and filtering --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 9a6ab9cb4..400bbf1f2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -322,6 +322,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun showSortingDialog() { ChangeSortingDialog(this, true, false) { + directories_grid.adapter = null if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) { getDirectories() } else { @@ -334,6 +335,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { FilterMediaDialog(this) { mLoadedInitialPhotos = false directories_refresh_layout.isRefreshing = true + directories_grid.adapter = null getDirectories() } } From 73e5333eefde717381519e498ffa805fe43d6991 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 19:24:22 +0200 Subject: [PATCH 054/163] recreate whole thumbnails view on toggling horizontal scroll --- .../gallery/activities/MainActivity.kt | 6 +- .../gallery/activities/MediaActivity.kt | 68 ++++++++++++------- .../gallery/adapters/DirectoryAdapter.kt | 5 -- .../gallery/adapters/MediaAdapter.kt | 6 -- 4 files changed, 46 insertions(+), 39 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 400bbf1f2..edfec247a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -138,8 +138,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } if (mStoredScrollHorizontally != config.scrollHorizontally) { - getRecyclerAdapter()?.updateScrollHorizontally(config.viewTypeFolders != VIEW_TYPE_LIST && config.scrollHorizontally) - setupScrollDirection() + mLoadedInitialPhotos = false + directories_grid.adapter = null + getDirectories() } if (mStoredTextColor != config.textColor) { @@ -382,6 +383,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun toggleTemporarilyShowHidden(show: Boolean) { mLoadedInitialPhotos = false config.temporarilyShowHidden = show + directories_grid.adapter = null getDirectories() invalidateOptionsMenu() } 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 61721dbca..e37ca9f78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -61,8 +61,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mIsSearchOpen = false private var mLatestMediaId = 0L private var mLatestMediaDateId = 0L - private var mSectionTitleHeight = 0 - private var mThumbnailHeight = 0 private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetMediaAsynctask? = null @@ -126,8 +124,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } if (mStoredScrollHorizontally != config.scrollHorizontally) { - getMediaAdapter()?.updateScrollHorizontally(config.viewTypeFiles != VIEW_TYPE_LIST || !config.scrollHorizontally) - setupScrollDirection() + mLoadedInitialPhotos = false + media_grid.adapter = null + getMedia() } if (mStoredTextColor != config.textColor) { @@ -591,33 +590,50 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun measureRecyclerViewContent(media: ArrayList) { - val layoutManager = media_grid.layoutManager as MyGridLayoutManager media_grid.onGlobalLayout { - val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 - mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 - mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height ?: 0 - - var fullHeight = 0 - var curSectionItems = 0 - media.forEach { - if (it is ThumbnailSection) { - fullHeight += mSectionTitleHeight - if (curSectionItems != 0) { - val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) - fullHeight += rows * mThumbnailHeight - } - curSectionItems = 0 - } else { - curSectionItems++ - } + if (config.scrollHorizontally) { + calculateContentWidth(media) + } else { + calculateContentHeight(media) } - - fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight - media_vertical_fastscroller.setContentHeight(fullHeight) - media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) } } + private fun calculateContentWidth(media: ArrayList) { + val layoutManager = media_grid.layoutManager as MyGridLayoutManager + val mThumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * mThumbnailWidth + media_horizontal_fastscroller.setContentWidth(fullWidth) + media_horizontal_fastscroller.setScrollTo(media_grid.computeHorizontalScrollOffset()) + } + + private fun calculateContentHeight(media: ArrayList) { + val layoutManager = media_grid.layoutManager as MyGridLayoutManager + val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally + val mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 + val mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height + ?: 0 + + var fullHeight = 0 + var curSectionItems = 0 + media.forEach { + if (it is ThumbnailSection) { + fullHeight += mSectionTitleHeight + if (curSectionItems != 0) { + val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) + fullHeight += rows * mThumbnailHeight + } + curSectionItems = 0 + } else { + curSectionItems++ + } + } + + fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight + media_vertical_fastscroller.setContentHeight(fullHeight) + media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) + } + private fun initZoomListener() { if (config.viewTypeFiles == VIEW_TYPE_GRID) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager 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 87daaf994..1c77d7af1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -442,11 +442,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Sun, 24 Jun 2018 19:44:55 +0200 Subject: [PATCH 055/163] do not add group sections at horizontal scrolling for now --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/MediaActivity.kt | 6 ++++-- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3692780c0..49da96ccb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.0' + implementation 'com.simplemobiletools:commons:4.3.1' 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 e37ca9f78..05a309f7e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -192,6 +192,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val isFolderHidden = File(mPath).containsNoMedia() menu.apply { + findItem(R.id.group).isVisible = !config.scrollHorizontally + findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES @@ -604,7 +606,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val mThumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * mThumbnailWidth media_horizontal_fastscroller.setContentWidth(fullWidth) - media_horizontal_fastscroller.setScrollTo(media_grid.computeHorizontalScrollOffset()) + media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset()) } private fun calculateContentHeight(media: ArrayList) { @@ -631,7 +633,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight media_vertical_fastscroller.setContentHeight(fullHeight) - media_vertical_fastscroller.setScrollTo(media_grid.computeVerticalScrollOffset()) + media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset()) } private fun initZoomListener() { 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 c3042d0b1..fc29815ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -342,6 +342,12 @@ class MediaFetcher(val context: Context) { return media as ArrayList } + val thumbnailItems = ArrayList() + if (context.config.scrollHorizontally) { + media.mapTo(thumbnailItems) { it } + return thumbnailItems + } + media.forEach { val key = it.getGroupingKey(currentGrouping) if (!mediumGroups.containsKey(key)) { @@ -357,7 +363,6 @@ class MediaFetcher(val context: Context) { mediumGroups[key] = value } - val thumbnailItems = ArrayList() for ((key, value) in mediumGroups) { thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping))) thumbnailItems.addAll(value) From 66962c3ec995942788c229f10dc27cc6fc2471ed Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jun 2018 20:43:19 +0200 Subject: [PATCH 056/163] fix some recycler glitches at the directories view --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 43 +++++++++++++++---- .../gallery/activities/MediaActivity.kt | 15 +++---- .../gallery/adapters/DirectoryAdapter.kt | 2 - 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 49da96ccb..9df4e778b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.1' + implementation 'com.simplemobiletools:commons:4.3.2' 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 edfec247a..8ccc7d9fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -425,6 +425,32 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { layoutManager.spanCount = config.dirColumnCnt } + private fun measureRecyclerViewContent(directories: ArrayList) { + directories_grid.onGlobalLayout { + if (config.scrollHorizontally) { + calculateContentWidth(directories) + } else { + calculateContentHeight(directories) + } + } + } + + private fun calculateContentWidth(directories: ArrayList) { + val layoutManager = directories_grid.layoutManager as MyGridLayoutManager + val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth + directories_horizontal_fastscroller.setContentWidth(fullWidth) + directories_horizontal_fastscroller.setScrollToX(directories_grid.computeHorizontalScrollOffset()) + } + + private fun calculateContentHeight(directories: ArrayList) { + val layoutManager = directories_grid.layoutManager as MyGridLayoutManager + val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0 + val fullHeight = ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight + directories_vertical_fastscroller.setContentHeight(fullHeight) + directories_vertical_fastscroller.setScrollToY(directories_grid.computeVerticalScrollOffset()) + } + private fun initZoomListener() { if (config.viewTypeFolders == VIEW_TYPE_GRID) { val layoutManager = directories_grid.layoutManager as MyGridLayoutManager @@ -466,19 +492,19 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun increaseColumnCount() { - directories_vertical_fastscroller.measureRecyclerViewOnRedraw() - directories_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.dirColumnCnt = ++(directories_grid.layoutManager as MyGridLayoutManager).spanCount - invalidateOptionsMenu() - directories_grid.adapter?.notifyDataSetChanged() + columnCountChanged() } private fun reduceColumnCount() { - directories_vertical_fastscroller.measureRecyclerViewOnRedraw() - directories_horizontal_fastscroller.measureRecyclerViewOnRedraw() config.dirColumnCnt = --(directories_grid.layoutManager as MyGridLayoutManager).spanCount + columnCountChanged() + } + + private fun columnCountChanged() { invalidateOptionsMenu() directories_grid.adapter?.notifyDataSetChanged() + measureRecyclerViewContent(getRecyclerAdapter()!!.dirs) } private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent)) @@ -698,7 +724,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { runOnUiThread { directories_refresh_layout.isRefreshing = false - directories_vertical_fastscroller.measureRecyclerView() checkPlaceholderVisibility(dirs) } checkInvalidDirectories(dirs, directoryDao) @@ -763,12 +788,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { (currAdapter as DirectoryAdapter).updateDirs(directories) } + getRecyclerAdapter()?.dirs?.apply { + measureRecyclerViewContent(this) + } setupScrollDirection() } private fun setupScrollDirection() { val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID - directories_vertical_fastscroller.isHorizontal = false directories_vertical_fastscroller.beGoneIf(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 05a309f7e..c15bb52f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -355,7 +355,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) val sorting = config.getFileSorting(mPath) - if (allowHorizontalScroll) { media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { @@ -603,8 +602,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun calculateContentWidth(media: ArrayList) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager - val mThumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 - val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * mThumbnailWidth + val thumbnailWidth = layoutManager.getChildAt(0)?.width ?: 0 + val fullWidth = ((media.size - 1) / layoutManager.spanCount + 1) * thumbnailWidth media_horizontal_fastscroller.setContentWidth(fullWidth) media_horizontal_fastscroller.setScrollToX(media_grid.computeHorizontalScrollOffset()) } @@ -612,18 +611,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun calculateContentHeight(media: ArrayList) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally - val mSectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 - val mThumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height + val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 + val thumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height ?: 0 var fullHeight = 0 var curSectionItems = 0 media.forEach { if (it is ThumbnailSection) { - fullHeight += mSectionTitleHeight + fullHeight += sectionTitleHeight if (curSectionItems != 0) { val rows = ((curSectionItems - 1) / layoutManager.spanCount + 1) - fullHeight += rows * mThumbnailHeight + fullHeight += rows * thumbnailHeight } curSectionItems = 0 } else { @@ -631,7 +630,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * mThumbnailHeight + fullHeight += ((curSectionItems - 1) / layoutManager.spanCount + 1) * thumbnailHeight media_vertical_fastscroller.setContentHeight(fullHeight) media_vertical_fastscroller.setScrollToY(media_grid.computeVerticalScrollOffset()) } 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 1c77d7af1..a44740940 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -255,7 +255,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Sun, 24 Jun 2018 22:07:36 +0200 Subject: [PATCH 057/163] give Properties a higher priority at Menu items than Rename --- app/src/main/res/menu/menu_viewpager.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/menu/menu_viewpager.xml b/app/src/main/res/menu/menu_viewpager.xml index c26c45eb8..ce071ed9c 100644 --- a/app/src/main/res/menu/menu_viewpager.xml +++ b/app/src/main/res/menu/menu_viewpager.xml @@ -81,16 +81,16 @@ android:icon="@drawable/ic_edit" android:title="@string/edit" app:showAsAction="ifRoom"/> - + Date: Mon, 25 Jun 2018 00:11:35 +0200 Subject: [PATCH 058/163] make db queries involving paths case insensitive --- .../simplemobiletools/gallery/interfaces/DirectoryDao.kt | 6 +++--- .../com/simplemobiletools/gallery/interfaces/MediumDao.kt | 8 ++++---- 2 files changed, 7 insertions(+), 7 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 c61717d95..ad1b5afab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -17,12 +17,12 @@ interface DirectoryDao { @Insert(onConflict = REPLACE) fun insertAll(directories: List) - @Query("DELETE FROM directories WHERE path = :path") + @Query("DELETE FROM directories WHERE path = :path COLLATE NOCASE") 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") + @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 COLLATE NOCASE") fun updateDirectory(path: String, thumbnail: String, mediaCnt: Int, lastModified: Long, dateTaken: Long, size: Long, mediaTypes: Int) - @Query("UPDATE directories SET thumbnail = :thumbnail, filename = :name, path = :newPath WHERE path = :oldPath") + @Query("UPDATE directories SET thumbnail = :thumbnail, filename = :name, path = :newPath WHERE path = :oldPath COLLATE NOCASE") fun updateDirectoryAfterRename(thumbnail: String, name: String, newPath: String, oldPath: String) } 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 13c0278e1..a5dd5e221 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.gallery.models.Medium @Dao interface MediumDao { - @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path") + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path COLLATE NOCASE") fun getMediaFromPath(path: String): List @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE is_favorite = 1") @@ -23,12 +23,12 @@ interface MediumDao { @Insert(onConflict = REPLACE) fun insertAll(media: List) - @Query("DELETE FROM media WHERE full_path = :path") + @Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE") fun deleteMediumPath(path: String) - @Query("UPDATE OR REPLACE 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 COLLATE NOCASE") fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) - @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path") + @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE") fun updateFavorite(path: String, isFavorite: Boolean) } From 3a7e93f0951787e4b354328efa4b67cf818efae3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jun 2018 14:43:39 +0200 Subject: [PATCH 059/163] do not allow clicking bottom actions if faded away --- .../gallery/activities/PhotoVideoActivity.kt | 4 ++-- .../gallery/activities/ViewPagerActivity.kt | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 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 912f7541b..3d49e28c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -182,13 +182,13 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList bottom_delete.beGone() bottom_edit.setOnClickListener { - if (mUri != null) { + if (mUri != null && bottom_actions.alpha == 1f) { openEditor(mUri!!.toString()) } } bottom_share.setOnClickListener { - if (mUri != null) { + if (mUri != null && bottom_actions.alpha == 1f) { sharePath(mUri!!.toString()) } } 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 015eafa9a..71fae94f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -762,19 +762,27 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun initBottomActionButtons() { bottom_favorite.setOnClickListener { - toggleFavorite() + if (bottom_actions.alpha == 1f) { + toggleFavorite() + } } bottom_edit.setOnClickListener { - openEditor(getCurrentPath()) + if (bottom_actions.alpha == 1f) { + openEditor(getCurrentPath()) + } } bottom_share.setOnClickListener { - shareMediumPath(getCurrentPath()) + if (bottom_actions.alpha == 1f) { + shareMediumPath(getCurrentPath()) + } } bottom_delete.setOnClickListener { - checkDeleteConfirmation() + if (bottom_actions.alpha == 1f) { + checkDeleteConfirmation() + } } } From efc4e241ca5c331a3c47f8652c6111a8c3b08e53 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jun 2018 16:14:51 +0200 Subject: [PATCH 060/163] add recycle bin to pinned folders by default --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 5 +++++ .../kotlin/com/simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../com/simplemobiletools/gallery/helpers/Constants.kt | 2 ++ 3 files changed, 11 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 8ccc7d9fc..5f9bf1867 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -114,6 +114,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.addPinnedFolders(hashSetOf(FAVORITES)) config.wereFavoritesPinned = true } + + if (!config.wasRecycleBinPinned) { + config.addPinnedFolders(hashSetOf(RECYCLE_BIN)) + config.wasRecycleBinPinned = true + } } override fun onStart() { 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 40b22e446..2af6c7bd7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -349,6 +349,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(WERE_FAVORITES_PINNED, false) set(wereFavoritesPinned) = prefs.edit().putBoolean(WERE_FAVORITES_PINNED, wereFavoritesPinned).apply() + var wasRecycleBinPinned: Boolean + get() = prefs.getBoolean(WAS_RECYCLE_BIN_PINNED, false) + set(wasRecycleBinPinned) = prefs.edit().putBoolean(WAS_RECYCLE_BIN_PINNED, wasRecycleBinPinned).apply() + var groupBy: Int get() = prefs.getInt(GROUP_BY, GROUP_BY_NONE) set(groupBy) = prefs.edit().putInt(GROUP_BY, groupBy).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 3e8c478b1..97773caca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -51,6 +51,7 @@ const val WAS_OTG_HANDLED = "was_otg_handled" const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" const val BOTTOM_ACTIONS = "bottom_actions" const val WERE_FAVORITES_PINNED = "were_favorites_pinned" +const val WAS_RECYCLE_BIN_PINNED = "was_recycle_bin_pinned" const val GROUP_BY = "group_by" // slideshow @@ -67,6 +68,7 @@ const val SLIDESHOW_SCROLL_DURATION = 500L const val NOMEDIA = ".nomedia" const val FAVORITES = "favorites" +const val RECYCLE_BIN = "recycle_bin" const val SHOW_FAVORITES = "show_favorites" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 300000L From d8a33f81d7a9655285bf7c60ae80144b0e47af13 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jun 2018 22:37:49 +0200 Subject: [PATCH 061/163] add a settings toggle for toggling recycle bin usage --- .../gallery/activities/SettingsActivity.kt | 11 ++++- .../gallery/helpers/Config.kt | 4 ++ .../gallery/helpers/Constants.kt | 1 + app/src/main/res/layout/activity_settings.xml | 41 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 197d2071a..2fdf38049 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -70,12 +70,13 @@ class SettingsActivity : SimpleActivity() { setupSkipDeleteConfirmation() updateTextColors(settings_holder) setupSectionColors() + setupUseRecycleBin() } private fun setupSectionColors() { val adjustedPrimaryColor = getAdjustedPrimaryColor() arrayListOf(visibility_label, videos_label, thumbnails_label, scrolling_label, fullscreen_media_label, security_label, - file_operations_label, extended_details_label).forEach { + file_operations_label, extended_details_label, recycle_bin_label).forEach { it.setTextColor(adjustedPrimaryColor) } } @@ -409,4 +410,12 @@ class SettingsActivity : SimpleActivity() { ROTATE_BY_DEVICE_ROTATION -> R.string.screen_rotation_device_rotation else -> R.string.screen_rotation_aspect_ratio }) + + private fun setupUseRecycleBin() { + settings_use_recycle_bin.isChecked = config.useRecycleBin + settings_use_recycle_bin_holder.setOnClickListener { + settings_use_recycle_bin.toggle() + config.useRecycleBin = settings_use_recycle_bin.isChecked + } + } } 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 2af6c7bd7..2a1fd92f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -356,4 +356,8 @@ class Config(context: Context) : BaseConfig(context) { var groupBy: Int get() = prefs.getInt(GROUP_BY, GROUP_BY_NONE) set(groupBy) = prefs.edit().putInt(GROUP_BY, groupBy).apply() + + var useRecycleBin: Boolean + get() = prefs.getBoolean(USE_RECYCLE_BIN, true) + set(useRecycleBin) = prefs.edit().putBoolean(USE_RECYCLE_BIN, useRecycleBin).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 97773caca..68a5df3de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -52,6 +52,7 @@ const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" const val BOTTOM_ACTIONS = "bottom_actions" const val WERE_FAVORITES_PINNED = "were_favorites_pinned" const val WAS_RECYCLE_BIN_PINNED = "was_recycle_bin_pinned" +const val USE_RECYCLE_BIN = "use_recycle_bin" const val GROUP_BY = "group_by" // slideshow diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 94cc6ea57..7717c996d 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -941,5 +941,46 @@ android:text="@string/skip_delete_confirmation"/> + + + + + + + + + + From 97829e98405b9fdc24a6648568ea40be3e73a9ea Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jun 2018 23:25:18 +0200 Subject: [PATCH 062/163] update commons to 4.3.3 --- app/build.gradle | 2 +- app/src/main/res/layout/activity_settings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9df4e778b..59c12030e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.2' + implementation 'com.simplemobiletools:commons:4.3.3' 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/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 7717c996d..0b40ee5e1 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -979,7 +979,7 @@ android:clickable="false" android:paddingLeft="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin" - android:text="@string/move_items_to_trash_bin"/> + android:text="@string/move_items_to_recycle_bin"/> From 3bedb2282cb8e4f76d9d642bfa9299908b2faaf5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jun 2018 23:54:32 +0200 Subject: [PATCH 063/163] update commons to 4.3.4 --- app/build.gradle | 2 +- .../gallery/dialogs/DeleteWithRememberDialog.kt | 2 +- app/src/main/res/layout/activity_settings.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 59c12030e..08eda2400 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.3' + implementation 'com.simplemobiletools:commons:4.3.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' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt index 1948339c3..f07705e35 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt @@ -13,7 +13,7 @@ class DeleteWithRememberDialog(val activity: Activity, val message: String, val init { view.delete_remember_title.text = message val builder = AlertDialog.Builder(activity) - .setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() }) + .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.no, null) dialog = builder.create().apply { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 0b40ee5e1..883731009 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -979,7 +979,7 @@ android:clickable="false" android:paddingLeft="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin" - android:text="@string/move_items_to_recycle_bin"/> + android:text="@string/move_items_into_recycle_bin"/> From 3468a9860bc9c844dce44f3aeff7fe99342b23ac Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 09:28:24 +0200 Subject: [PATCH 064/163] update the delete confirmation Dialog if we are using the recycle bin --- .../simplemobiletools/gallery/activities/ViewPagerActivity.kt | 3 ++- .../com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 3 ++- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 3 ++- 3 files changed, 6 insertions(+), 3 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 71fae94f5..07c0e0be4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -829,7 +829,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - DeleteWithRememberDialog(this, getString(R.string.proceed_with_deletion)) { + val message = if (config.useRecycleBin) R.string.are_you_sure_recycle_bin else R.string.are_you_sure_delete + DeleteWithRememberDialog(this, getString(message)) { config.tempSkipDeleteConfirmation = it deleteConfirmed() } 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 a44740940..95ba983bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -327,7 +327,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Wed, 27 Jun 2018 09:51:33 +0200 Subject: [PATCH 065/163] add a new field to media, the timestamp of their move to recycle bin --- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/databases/GalleryDatabase.kt | 2 +- .../simplemobiletools/gallery/helpers/MediaFetcher.kt | 4 ++-- .../simplemobiletools/gallery/interfaces/MediumDao.kt | 9 ++++++--- .../com/simplemobiletools/gallery/models/Medium.kt | 5 +++-- .../gallery/receivers/RefreshMediaReceiver.kt | 2 +- 6 files changed, 14 insertions(+), 10 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 3d49e28c9..b3c139420 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -95,7 +95,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList else -> TYPE_RAWS } - mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false) + mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false, 0) supportActionBar?.title = mMedium!!.name bundle.putSerializable(MEDIUM, mMedium) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt index 56896a30b..8f8df8e23 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/databases/GalleryDatabase.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.interfaces.MediumDao import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium -@Database(entities = [(Directory::class), (Medium::class)], version = 3) +@Database(entities = [(Directory::class), (Medium::class)], version = 4) abstract class GalleryDatabase : RoomDatabase() { abstract fun DirectoryDao(): DirectoryDao 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 fc29815ae..349cb9aee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -224,7 +224,7 @@ class MediaFetcher(val context: Context) { val path = file.absolutePath val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite) + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0) media.add(medium) } return media @@ -281,7 +281,7 @@ class MediaFetcher(val context: Context) { val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH)) val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite) + val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite, 0) media.add(medium) } 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 a5dd5e221..955513380 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -8,15 +8,18 @@ import com.simplemobiletools.gallery.models.Medium @Dao interface MediumDao { - @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path COLLATE NOCASE") + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND parent_path = :path COLLATE NOCASE") fun getMediaFromPath(path: String): List - @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE is_favorite = 1") + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND is_favorite = 1") fun getFavorites(): List - @Query("SELECT full_path FROM media WHERE is_favorite = 1") + @Query("SELECT full_path FROM media WHERE deleted_ts = 0 AND is_favorite = 1") fun getFavoritePaths(): List + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite, deleted_ts FROM media WHERE deleted_ts != 0") + fun getDeletedMedia(): 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 66ce260fe..a942039cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -25,10 +25,11 @@ data class Medium( @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "type") val type: Int, - @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable, ThumbnailItem() { + @ColumnInfo(name = "is_favorite") var isFavorite: Boolean, + @ColumnInfo(name = "deleted_ts") var deletedTS: Int) : Serializable, ThumbnailItem() { companion object { - private const val serialVersionUID = -6553149366975455L + private const val serialVersionUID = -6553149366975655L } fun isGif() = type == TYPE_GIFS 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 7e6de9293..8ec3929c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -19,7 +19,7 @@ class RefreshMediaReceiver : BroadcastReceiver() { Thread { val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(), - File(path).length(), getFileType(path), false) + File(path).length(), getFileType(path), false, 0) context.galleryDB.MediumDao().insert(medium) }.start() } From 87fde0f813a90c5609fa141145eeed2bd223c95e Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 10:40:22 +0200 Subject: [PATCH 066/163] lets just move the deleted file into the recycle bin when appropriate --- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 26 +++++++++++++---- .../gallery/extensions/Activity.kt | 29 +++++++++++++++---- .../gallery/helpers/MediaFetcher.kt | 4 +-- .../gallery/interfaces/MediumDao.kt | 3 ++ .../gallery/models/Medium.kt | 2 +- .../gallery/receivers/RefreshMediaReceiver.kt | 2 +- 9 files changed, 54 insertions(+), 18 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 5f9bf1867..580599a23 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -275,7 +275,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (newFolder.exists() && newFolder.isDirectory) { if (newFolder.list()?.isEmpty() == true) { toast(String.format(getString(R.string.deleting_folder), config.tempFolderPath), Toast.LENGTH_LONG) - tryDeleteFileDirItem(newFolder.toFileDirItem(applicationContext), true) + tryDeleteFileDirItem(newFolder.toFileDirItem(applicationContext), true, 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 c15bb52f0..e3ba78a58 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -490,7 +490,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) { - tryDeleteFileDirItem(fileDirItem, true) + tryDeleteFileDirItem(fileDirItem, true, true) } } 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 b3c139420..764f3ff82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -95,7 +95,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList else -> TYPE_RAWS } - mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false, 0) + mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, false, 0L) 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 07c0e0be4..d7a194288 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -589,7 +589,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (getDoesFilePathExist(newPath)) { - tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath())) + tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath()), false, true) } copyFile(tmpPath, newPath) @@ -618,7 +618,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } catch (e: Exception) { showErrorToast(e) } finally { - tryDeleteFileDirItem(tmpFileDirItem) + tryDeleteFileDirItem(tmpFileDirItem, false, true) } } @@ -837,9 +837,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun deleteConfirmed() { - val path = getCurrentMedia()[mPos].path - tryDeleteFileDirItem(FileDirItem(path, path.getFilenameFromPath())) { - refreshViewPager() + val path = getCurrentMedia().getOrNull(mPos)?.path ?: return + if (config.useRecycleBin) { + Thread { + movePathInRecycleBin(path) { + if (it) { + galleryDB.MediumDao().updateDeleted(path, System.currentTimeMillis()) + refreshViewPager() + } else { + toast(R.string.unknown_error_occurred) + } + } + }.start() + } else { + val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) + tryDeleteFileDirItem(fileDirItem, false, true) { + refreshViewPager() + } } } @@ -926,7 +940,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) { - tryDeleteFileDirItem(fileDirItem, true) + tryDeleteFileDirItem(fileDirItem, true, true) } scanPathRecursively(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 8ae591cb2..c138baa31 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -133,7 +133,7 @@ fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = nul return } - tryDeleteFileDirItem(file.toFileDirItem(applicationContext)) { + tryDeleteFileDirItem(file.toFileDirItem(applicationContext), false, false) { callback?.invoke() } } @@ -168,12 +168,31 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, } } -fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) { +fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean, + callback: ((wasSuccess: Boolean) -> Unit)? = null) { deleteFile(fileDirItem, allowDeleteFolder) { callback?.invoke(it) - Thread { - galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) - }.start() + if (deleteFromDatabase) { + Thread { + galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) + }.start() + } + } +} + +fun BaseSimpleActivity.movePathInRecycleBin(path: String, callback: (success: Boolean) -> Unit) { + val file = File(path) + val internalFile = File(filesDir, path) + return try { + file.copyRecursively(internalFile, true) + val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) + tryDeleteFileDirItem(fileDirItem, getIsPathDirectory(path), false) { + Thread { + callback(it) + }.start() + } + } catch (ignored: Exception) { + callback(false) } } 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 349cb9aee..3e495cb7c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -224,7 +224,7 @@ class MediaFetcher(val context: Context) { val path = file.absolutePath val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0) + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0L) media.add(medium) } return media @@ -281,7 +281,7 @@ class MediaFetcher(val context: Context) { val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH)) val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite, 0) + val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, isFavorite, 0L) media.add(medium) } 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 955513380..31ea1835e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -34,4 +34,7 @@ interface MediumDao { @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE") fun updateFavorite(path: String, isFavorite: Boolean) + + @Query("UPDATE media SET deleted_ts = :deletedTS WHERE full_path = :path COLLATE NOCASE") + fun updateDeleted(path: String, deletedTS: Long) } 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 a942039cf..1a7313d52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -26,7 +26,7 @@ data class Medium( @ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "type") val type: Int, @ColumnInfo(name = "is_favorite") var isFavorite: Boolean, - @ColumnInfo(name = "deleted_ts") var deletedTS: Int) : Serializable, ThumbnailItem() { + @ColumnInfo(name = "deleted_ts") var deletedTS: Long) : Serializable, ThumbnailItem() { companion object { private const val serialVersionUID = -6553149366975655L 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 8ec3929c5..25dc4aa5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/RefreshMediaReceiver.kt @@ -19,7 +19,7 @@ class RefreshMediaReceiver : BroadcastReceiver() { Thread { val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(), - File(path).length(), getFileType(path), false, 0) + File(path).length(), getFileType(path), false, 0L) context.galleryDB.MediumDao().insert(medium) }.start() } From 721890ce678b145dde82ffc94ae7ffd366481402 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 11:15:58 +0200 Subject: [PATCH 067/163] properly handle moving multiple items in the recycle bin too --- .../gallery/activities/MediaActivity.kt | 19 ++++++++++- .../gallery/activities/ViewPagerActivity.kt | 15 ++++----- .../gallery/extensions/Activity.kt | 33 +++++++++++-------- 3 files changed, 44 insertions(+), 23 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 e3ba78a58..1a8234c7d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -772,6 +772,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun tryDeleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList + if (config.useRecycleBin) { + movePathsInRecycleBin(filtered.map { it.path } as ArrayList) { + if (it) { + deleteFilteredFiles(filtered) + } else { + toast(R.string.unknown_error_occurred) + } + } + } else { + deleteFilteredFiles(filtered) + } + } + + private fun deleteFilteredFiles(filtered: ArrayList) { deleteFiles(filtered) { if (!it) { toast(R.string.unknown_error_occurred) @@ -782,8 +796,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { Thread { val mediumDao = galleryDB.MediumDao() + val useRecycleBin = config.useRecycleBin filtered.forEach { - mediumDao.deleteMediumPath(it.path) + if (!useRecycleBin) { + 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 d7a194288..6ac4f0744 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -838,19 +838,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { val path = getCurrentMedia().getOrNull(mPos)?.path ?: return + val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) if (config.useRecycleBin) { - Thread { - movePathInRecycleBin(path) { - if (it) { - galleryDB.MediumDao().updateDeleted(path, System.currentTimeMillis()) + movePathInRecycleBin(path) { + if (it) { + tryDeleteFileDirItem(fileDirItem, false, false) { refreshViewPager() - } else { - toast(R.string.unknown_error_occurred) } + } else { + toast(R.string.unknown_error_occurred) } - }.start() + } } else { - val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) tryDeleteFileDirItem(fileDirItem, false, true) { refreshViewPager() } 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 c138baa31..736a67fe4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -181,18 +181,23 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet } } -fun BaseSimpleActivity.movePathInRecycleBin(path: String, callback: (success: Boolean) -> Unit) { - val file = File(path) - val internalFile = File(filesDir, path) - return try { - file.copyRecursively(internalFile, true) - val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) - tryDeleteFileDirItem(fileDirItem, getIsPathDirectory(path), false) { - Thread { - callback(it) - }.start() - } - } catch (ignored: Exception) { - callback(false) - } +fun BaseSimpleActivity.movePathInRecycleBin(path: String, callback: ((wasSuccess: Boolean) -> Unit)?) { + movePathsInRecycleBin(arrayListOf(path), callback) +} + +fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList, callback: ((wasSuccess: Boolean) -> Unit)?) { + Thread { + var pathsCnt = paths.size + paths.forEach { + val file = File(it) + val internalFile = File(filesDir, it) + try { + file.copyRecursively(internalFile, true) + galleryDB.MediumDao().updateDeleted(it, System.currentTimeMillis()) + pathsCnt-- + } catch (ignored: Exception) { + } + } + callback?.invoke(pathsCnt == 0) + }.start() } From c75f564a35d626452b1e8ef110282b4d073bf689 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 12:05:36 +0200 Subject: [PATCH 068/163] show a Recycle Bin folder on the main screen if not empty --- .../gallery/activities/MainActivity.kt | 17 +++++++++++++---- .../gallery/activities/MediaActivity.kt | 12 +++++++----- .../gallery/activities/ViewPagerActivity.kt | 10 +++++++--- .../gallery/adapters/DirectoryAdapter.kt | 4 ++-- .../gallery/extensions/Context.kt | 15 ++++++++++++++- .../gallery/helpers/Constants.kt | 1 + .../gallery/helpers/MediaFetcher.kt | 13 +++++-------- .../gallery/models/Directory.kt | 3 +++ 8 files changed, 52 insertions(+), 23 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 580599a23..c4bc687b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -679,7 +679,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { // update directories and media files in the local db, delete invalid items updateDBDirectory(directory) - mediumDao.insertAll(curMedia) + if (!directory.isRecycleBin()) { + mediumDao.insertAll(curMedia) + } getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { it.forEach { if (!curMedia.contains(it)) { @@ -696,6 +698,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val foldersToScan = mediaFetcher.getFoldersToScan() foldersToScan.add(FAVORITES) + foldersToScan.add(RECYCLE_BIN) dirs.forEach { foldersToScan.remove(it.path) } @@ -720,7 +723,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { dirs.add(newDir) showSortedDirs(dirs) directoryDao.insert(newDir) - mediumDao.insertAll(newMedia) + if (folder != RECYCLE_BIN) { + mediumDao.insertAll(newMedia) + } } mIsGettingDirs = false @@ -764,7 +769,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val mediaTypes = curMedia.getDirMediaTypes() - val dirName = if (path == FAVORITES) getString(R.string.favorites) else checkAppendingHidden(path, hiddenString, includedFolders) + val dirName = when (path) { + FAVORITES -> getString(R.string.favorites) + RECYCLE_BIN -> getString(R.string.recycle_bin) + else -> checkAppendingHidden(path, hiddenString, includedFolders) + } val firstItem = curMedia.first() val lastItem = curMedia.last() @@ -822,7 +831,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun checkInvalidDirectories(dirs: ArrayList, directoryDao: DirectoryDao) { val invalidDirs = ArrayList() - dirs.filter { !it.areFavorites() }.forEach { + dirs.filter { !it.areFavorites() && !it.isRecycleBin() }.forEach { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) } else if (it.path != 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 1a8234c7d..934b7263b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -194,9 +194,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { menu.apply { findItem(R.id.group).isVisible = !config.scrollHorizontally - findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES - findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES - findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES + findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN + findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN + findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN findItem(R.id.folder_view).isVisible = mShowAll findItem(R.id.open_camera).isVisible = mShowAll @@ -304,6 +304,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { if (it) { val dirName = when { mPath == FAVORITES -> getString(R.string.favorites) + mPath == RECYCLE_BIN -> getString(R.string.recycle_bin) mPath == OTG_PATH -> getString(R.string.otg) mPath.startsWith(OTG_PATH) -> mPath.trimEnd('/').substringAfterLast('/') else -> getHumanizedFilename(mPath) @@ -525,7 +526,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun isDirEmpty(): Boolean { return if (mMedia.size <= 0 && config.filterMedia > 0) { - if (mPath != FAVORITES) { + if (mPath != FAVORITES && mPath != RECYCLE_BIN) { deleteDirectoryIfEmpty() deleteDBDirectory() } @@ -736,6 +737,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { putExtra(PATH, path) putExtra(SHOW_ALL, mShowAll) putExtra(SHOW_FAVORITES, mPath == FAVORITES) + putExtra(SHOW_RECYCLE_BIN, mPath == RECYCLE_BIN) startActivity(this) } } @@ -747,7 +749,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - val mediaToInsert = (mMedia.clone() as ArrayList).filter { it is Medium }.map { it as Medium } + val mediaToInsert = (mMedia.clone() as ArrayList).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium } galleryDB.MediumDao().insertAll(mediaToInsert) } }.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 6ac4f0744..b00879def 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -60,7 +60,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mPos = -1 private var mShowAll = false private var mIsSlideshowActive = false - private var mIsShowingFavorites = false private var mRotationDegrees = 0 private var mPrevHashcode = 0 @@ -86,7 +85,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) (MediaActivity.mMedia.clone() as ArrayList).filter { it is Medium }.mapTo(mMediaFiles) { it as Medium } - mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { @@ -216,7 +214,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View showSystemUI() - mDirectory = if (mIsShowingFavorites) FAVORITES else mPath.getParentPath() + val isShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false) + val isShowingRecycleBin = intent.getBooleanExtra(SHOW_RECYCLE_BIN, false) + mDirectory = when { + isShowingFavorites -> FAVORITES + isShowingRecycleBin -> RECYCLE_BIN + else -> mPath.getParentPath() + } if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { mDirectory += "/" } 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 95ba983bd..ba83dcd3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -181,7 +181,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !it.areFavorites() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { + dirsToCheck.filter { !it.areFavorites() && !it.isRecycleBin() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { directoryDao.deleteDirPath(it.path) } } @@ -387,3 +392,11 @@ fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFile fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)?.map { it.name }?.toList() fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList + +fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { + val media = mediumDao.getDeletedMedia() as ArrayList + media.forEach { + it.path = File(filesDir, it.path).toString() + } + return media +} 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 68a5df3de..5f099c5a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -71,6 +71,7 @@ const val NOMEDIA = ".nomedia" const val FAVORITES = "favorites" const val RECYCLE_BIN = "recycle_bin" const val SHOW_FAVORITES = "show_favorites" +const val SHOW_RECYCLE_BIN = "show_recycle_bin" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 300000L const val CLICK_MAX_DURATION = 150 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 3e495cb7c..5a64f8f67 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -8,10 +8,7 @@ import android.text.format.DateFormat import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.getDistinctPath -import com.simplemobiletools.gallery.extensions.getOTGFolderChildren -import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailSection @@ -165,10 +162,10 @@ class MediaFetcher(val context: Context) { favoritePaths: ArrayList): ArrayList { val media = ArrayList() - val files = if (folder == FAVORITES) { - favoritePaths.map { File(it) }.toTypedArray() - } else { - File(folder).listFiles() ?: return media + val files = when (folder) { + FAVORITES -> favoritePaths.map { File(it) }.toTypedArray() + RECYCLE_BIN -> context.getUpdatedDeletedMedia(context.galleryDB.MediumDao()).map { File(it.path) }.toTypedArray() + else -> File(folder).listFiles() ?: return media } val doExtraCheck = context.config.doExtraCheck 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 85835f165..3c748c50e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.FAVORITES +import com.simplemobiletools.gallery.helpers.RECYCLE_BIN import java.io.Serializable @Entity(tableName = "directories", indices = [Index(value = "path", unique = true)]) @@ -39,4 +40,6 @@ data class Directory( } fun areFavorites() = path == FAVORITES + + fun isRecycleBin() = path == RECYCLE_BIN } From b7b49f579e43212346e9f6293e5aaff64fbec1be Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 12:11:15 +0200 Subject: [PATCH 069/163] do not allow renaming Favorites or Recycle bin --- .../com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ba83dcd3b..4c6f204ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -71,8 +71,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Wed, 27 Jun 2018 12:30:55 +0200 Subject: [PATCH 070/163] fetch proper deletedTS at items in the recycle bin --- .../simplemobiletools/gallery/helpers/MediaFetcher.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 5a64f8f67..15e61bd10 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -162,9 +162,15 @@ class MediaFetcher(val context: Context) { favoritePaths: ArrayList): ArrayList { val media = ArrayList() + val deletedMedia = if (folder == RECYCLE_BIN) { + context.getUpdatedDeletedMedia(context.galleryDB.MediumDao()) + } else { + ArrayList() + } + val files = when (folder) { FAVORITES -> favoritePaths.map { File(it) }.toTypedArray() - RECYCLE_BIN -> context.getUpdatedDeletedMedia(context.galleryDB.MediumDao()).map { File(it.path) }.toTypedArray() + RECYCLE_BIN -> deletedMedia.map { File(it.path) }.toTypedArray() else -> File(folder).listFiles() ?: return media } @@ -221,7 +227,8 @@ class MediaFetcher(val context: Context) { val path = file.absolutePath val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0L) + val deletedTS = if (folder == RECYCLE_BIN) deletedMedia.firstOrNull { it.path == path }?.deletedTS ?: 0L else 0L + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, deletedTS) media.add(medium) } return media From f852b69f6e7e8848fe81daf03e899c85d4e182be Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 14:45:50 +0200 Subject: [PATCH 071/163] allow permanent delete to items already in the recycle bin --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 4 ++-- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 3 ++- .../com/simplemobiletools/gallery/extensions/Activity.kt | 7 +++++-- .../kotlin/com/simplemobiletools/gallery/models/Medium.kt | 2 ++ 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08eda2400..137c3a2c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.4' + implementation 'com.simplemobiletools:commons:4.3.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/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 934b7263b..ae24492c6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -774,7 +774,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun tryDeleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList - if (config.useRecycleBin) { + if (config.useRecycleBin && !filtered.first().path.startsWith(filesDir.toString())) { movePathsInRecycleBin(filtered.map { it.path } as ArrayList) { if (it) { deleteFilteredFiles(filtered) 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 b00879def..a7640970b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -833,7 +833,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - val message = if (config.useRecycleBin) R.string.are_you_sure_recycle_bin else R.string.are_you_sure_delete + val message = if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) R.string.are_you_sure_recycle_bin else R.string.are_you_sure_delete DeleteWithRememberDialog(this, getString(message)) { config.tempSkipDeleteConfirmation = it deleteConfirmed() @@ -843,7 +843,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { val path = getCurrentMedia().getOrNull(mPos)?.path ?: return val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) - if (config.useRecycleBin) { + if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { movePathInRecycleBin(path) { if (it) { tryDeleteFileDirItem(fileDirItem, false, false) { 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 c6e2decf5..438713baf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -279,7 +279,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean, callback: ((wasSuccess: Boolean) -> Unit)? = null) { deleteFile(fileDirItem, allowDeleteFolder) { - callback?.invoke(it) - if (deleteFromDatabase) { Thread { galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) + runOnUiThread { + callback?.invoke(it) + } }.start() + } else { + callback?.invoke(it) } } } 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 1a7313d52..bc9eff1db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -59,6 +59,8 @@ data class Medium( } } + fun getIsInRecycleBin() = deletedTS != 0L + private fun getDayStartTS(ts: Long): String { val calendar = Calendar.getInstance(Locale.ENGLISH).apply { timeInMillis = ts From 59cb293d987e52f094c22f1cbaa4719ea62ed42c Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 15:20:22 +0200 Subject: [PATCH 072/163] add handling for moving whole folders in the recycle bin --- .../gallery/activities/MainActivity.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index c4bc687b5..46211993b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -395,6 +395,26 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun deleteFolders(folders: ArrayList) { val fileDirItems = folders.map { FileDirItem(it.absolutePath, it.name, true) } as ArrayList + if (config.useRecycleBin) { + val pathsToDelete = ArrayList() + fileDirItems.filter { it.isDirectory }.forEach { + val files = File(it.path).listFiles() + files?.filter { it.absolutePath.isImageVideoGif() }?.mapTo(pathsToDelete) { it.absolutePath } + } + + movePathsInRecycleBin(pathsToDelete) { + if (it) { + deleteFilteredFolders(fileDirItems, folders) + } else { + toast(R.string.unknown_error_occurred) + } + } + } else { + deleteFilteredFolders(fileDirItems, folders) + } + } + + private fun deleteFilteredFolders(fileDirItems: ArrayList, folders: ArrayList) { deleteFolders(fileDirItems) { runOnUiThread { refreshItems() From ed8fa63ce8b03d32d6f147926cfcd6e040bc72b1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 15:20:45 +0200 Subject: [PATCH 073/163] make sure we clean up invalid recycle bin db entries --- .../com/simplemobiletools/gallery/extensions/Context.kt | 7 ++++++- 1 file changed, 6 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 7b8195b7d..086102b1e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -364,8 +364,13 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag val grouped = mediaFetcher.groupMedia(media, path) callback(grouped.clone() as ArrayList) + val recycleBinPath = filesDir.toString() media.filter { !getDoesFilePathExist(it.path) }.forEach { - mediumDao.deleteMediumPath(it.path) + if (it.path.startsWith(recycleBinPath)) { + mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath)) + } else { + mediumDao.deleteMediumPath(it.path) + } } }.start() } From e0f8d311bad6a2496070db455461b74073b38d06 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 15:39:38 +0200 Subject: [PATCH 074/163] fix some data consistency issues when fetching recycle bin items --- .../gallery/helpers/MediaFetcher.kt | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 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 15e61bd10..41fa4903e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -211,25 +211,30 @@ class MediaFetcher(val context: Context) { if (size <= 0L || (doExtraCheck && !file.exists())) continue - val lastModified = file.lastModified() - var dateTaken = lastModified - - if (getProperDateTaken) { - dateTaken = dateTakens.remove(filename) ?: lastModified - } - - val type = when { - isImage -> TYPE_IMAGES - isVideo -> TYPE_VIDEOS - isGif -> TYPE_GIFS - else -> TYPE_RAWS - } - val path = file.absolutePath - val isFavorite = favoritePaths.contains(path) - val deletedTS = if (folder == RECYCLE_BIN) deletedMedia.firstOrNull { it.path == path }?.deletedTS ?: 0L else 0L - val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, deletedTS) - media.add(medium) + if (folder == RECYCLE_BIN) { + deletedMedia.firstOrNull { it.path == path }?.apply { + media.add(this) + } + } else { + val lastModified = file.lastModified() + var dateTaken = lastModified + + if (getProperDateTaken) { + dateTaken = dateTakens.remove(filename) ?: lastModified + } + + val type = when { + isImage -> TYPE_IMAGES + isVideo -> TYPE_VIDEOS + isGif -> TYPE_GIFS + else -> TYPE_RAWS + } + + val isFavorite = favoritePaths.contains(path) + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite, 0L) + media.add(medium) + } } return media } From f54616bf3f5328eee2e9545b5a896aa712654bc8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 16:09:26 +0200 Subject: [PATCH 075/163] do not allow showing the Properties of Favorites and Recycle bin --- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 4c6f204ed..78089c37c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -148,11 +148,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Date: Wed, 27 Jun 2018 16:34:46 +0200 Subject: [PATCH 076/163] make sure we hide the Recycle Bin folder if empty --- .../gallery/activities/MainActivity.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 46211993b..a3ef6ea65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -864,9 +864,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } if (getFavoritePaths().isEmpty()) { - val dirsFolder = dirs.firstOrNull { it.areFavorites() } - if (dirsFolder != null) { - invalidDirs.add(dirsFolder) + val favoritesFolder = dirs.firstOrNull { it.areFavorites() } + if (favoritesFolder != null) { + invalidDirs.add(favoritesFolder) + } + } + + if (config.useRecycleBin) { + val binFolder = dirs.firstOrNull { it.path == RECYCLE_BIN } + if (binFolder != null && galleryDB.MediumDao().getDeletedMedia().isEmpty()) { + invalidDirs.add(binFolder) } } From 8397ebac6607edde125a1a4b35f4682dc9eea414 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 16:56:22 +0200 Subject: [PATCH 077/163] add some helper menu buttons for emptying and disabling recycle bin --- .../gallery/activities/MediaActivity.kt | 17 +++++++++++++++++ .../gallery/extensions/Activity.kt | 18 ++++++++++++++++++ .../gallery/interfaces/DirectoryDao.kt | 4 ++++ .../gallery/interfaces/MediumDao.kt | 3 +++ app/src/main/res/menu/menu_media.xml | 8 ++++++++ 5 files changed, 50 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index ae24492c6..57739f38c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -198,6 +198,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN + findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN + findItem(R.id.empty_disable_recycle_bin).isVisible = mPath == RECYCLE_BIN + findItem(R.id.folder_view).isVisible = mShowAll findItem(R.id.open_camera).isVisible = mShowAll findItem(R.id.about).isVisible = mShowAll @@ -219,6 +222,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { when (item.itemId) { R.id.sort -> showSortingDialog() R.id.filter -> showFilterMediaDialog() + R.id.empty_recycle_bin -> emptyRecycleBin() + R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin() R.id.toggle_filename -> toggleFilenameVisibility() R.id.open_camera -> launchCamera() R.id.folder_view -> switchToFolderView() @@ -418,6 +423,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun emptyRecycleBin() { + emptyTheRecycleBin { + finish() + } + } + + private fun emptyAndDisableRecycleBin() { + emptyAndDisableTheRecycleBin { + finish() + } + } + private fun toggleFilenameVisibility() { config.displayFileNames = !config.displayFileNames getMediaAdapter()?.updateDisplayFilenames(config.displayFileNames) 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 89c2cb333..41a33621f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -204,3 +204,21 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList, callback: callback?.invoke(pathsCnt == 0) }.start() } + +fun BaseSimpleActivity.emptyTheRecycleBin(callback: () -> Unit) { + Thread { + filesDir.deleteRecursively() + galleryDB.MediumDao().clearRecycleBin() + galleryDB.DirectoryDao().deleteRecycleBin() + callback() + }.start() +} + +fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) { + Thread { + emptyTheRecycleBin { + config.useRecycleBin = false + callback() + } + }.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 ad1b5afab..6ca318f4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -4,6 +4,7 @@ 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.helpers.RECYCLE_BIN import com.simplemobiletools.gallery.models.Directory @Dao @@ -25,4 +26,7 @@ interface DirectoryDao { @Query("UPDATE directories SET thumbnail = :thumbnail, filename = :name, path = :newPath WHERE path = :oldPath COLLATE NOCASE") fun updateDirectoryAfterRename(thumbnail: String, name: String, newPath: String, oldPath: String) + + @Query("DELETE FROM directories WHERE path = \'$RECYCLE_BIN\' COLLATE NOCASE") + fun deleteRecycleBin() } 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 31ea1835e..68e4c3642 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -37,4 +37,7 @@ interface MediumDao { @Query("UPDATE media SET deleted_ts = :deletedTS WHERE full_path = :path COLLATE NOCASE") fun updateDeleted(path: String, deletedTS: Long) + + @Query("DELETE FROM media WHERE deleted_ts != 0") + fun clearRecycleBin() } diff --git a/app/src/main/res/menu/menu_media.xml b/app/src/main/res/menu/menu_media.xml index f59adabec..ea3f38fd9 100644 --- a/app/src/main/res/menu/menu_media.xml +++ b/app/src/main/res/menu/menu_media.xml @@ -22,6 +22,14 @@ android:icon="@drawable/ic_filter" android:title="@string/filter_media" app:showAsAction="ifRoom"/> + + Date: Wed, 27 Jun 2018 18:36:43 +0200 Subject: [PATCH 078/163] PL translation updates [2018.06.27] --- app/src/main/res/values-pl/strings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 7aea01fd1..88de4b69c 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -7,7 +7,7 @@ (ukryty) (wykluczony) Przypnij folder - Wypakuj folder + Odepnij folder    Przypnij na górze Pokaż wszystko Wszystkie foldery @@ -173,11 +173,11 @@    Co jeśli chcę widzieć tylko.wybrane foldery?    Przejdź do sekcji z wykluczonymi folderami w ustawieniach aplikacji, dodaj tam folder główny (\"/\"), a następnie dodaj pożądane foldery w sekcji z dołączonymi folderami.    Zdjęcia w widoku pełnoekranowym mają dziwne artefakty. Jak mogę to naprawić? -    U ustawieniach aplikacji włącz opcję \'Zamieniaj powiększalne obrazy na te o lepszej jakości\'. Poprawi ona jakość zdjęć, jednak przy bardzo dużych powiększeniach mogą się stać one zbyt rozmazane. + W ustawieniach aplikacji włącz opcję \'Zamieniaj powiększalne obrazy na te o lepszej jakości\'. Poprawi ona jakość zdjęć, jednak przy bardzo dużych powiększeniach mogą się stać one zbyt rozmazane. Czy mogę w tej aplikacji przycinać obrazy? Tak, możesz to zrobić w edytorze, przeciągając krawędzie obrazu. Edytor otworzysz przytrzymując miniaturę obrazu i wybierając opcję \'Edytuj\', bądź wybierając tą samą opcję w menu pełnoekranowym. - Can I somehow group media file thumbnails? - Sure, just use the \"Group by\" menu item while at the thumbnails view. You can group files by multiple criteria, including Date Taken. If you use the \"Show all folders content\" function you can group them by folders too. + Czy mogę jakoś grupować miniatury plików? + Tak. Użyj opcji \'Grupuj według\', gdy jesteś w widoku miniatur. Grupować je możesz według wielu kryteriów, włącznie z datą ich utworzenia. Ponadto, jeśli użyjesz opcji \'Pokazuj całą zawartość folderów\', możesz je także grupować według folderów. From 15440cab4230df994fd521661d57ea841eeedd49 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 18:40:18 +0200 Subject: [PATCH 079/163] allow emptying the recycle bin with some menu buttons --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 6 ++++-- .../gallery/adapters/DirectoryAdapter.kt | 17 +++++++++++++++++ app/src/main/res/menu/cab_directories.xml | 8 ++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 137c3a2c4..2ffaa0bb4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.5' + implementation 'com.simplemobiletools:commons:4.3.6' 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 a3ef6ea65..721393926 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -218,8 +218,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { menuInflater.inflate(R.menu.menu_main_intent, menu) } else { menuInflater.inflate(R.menu.menu_main, menu) - menu.findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT - menu.findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1 + menu.apply { + findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT + findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1 + } } menu.findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden menu.findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden 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 78089c37c..12283589b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -76,6 +76,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList pinFolders(true) R.id.cab_unpin -> pinFolders(false) R.id.cab_hide -> toggleFoldersVisibility(true) + R.id.cab_empty_recycle_bin -> emptyRecycleBin() + R.id.cab_empty_disable_recycle_bin -> emptyAndDisableRecycleBin() R.id.cab_unhide -> toggleFoldersVisibility(false) R.id.cab_exclude -> tryExcludeFolder() R.id.cab_copy_to -> copyMoveTo(true) @@ -208,6 +213,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList