diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 61a3e64fb..fbe985495 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -573,14 +573,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache) directories_grid.beVisibleIf(directories_empty_text_label.isGone()) - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID - directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) - directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) - checkLastMediaChanged() mDirs = dirs runOnUiThread { + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) + directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) setupAdapter() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 547cf7d37..6bfaecad5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -454,9 +454,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } mIsGettingMedia = true - val media = getCachedMedia(mPath) - if (media.isNotEmpty() && !mLoadedInitialPhotos) { - gotMedia(media, true) + if (!mLoadedInitialPhotos) { + getCachedMedia(mPath) { + if (it.isEmpty()) { + media_refresh_layout.isRefreshing = true + } else { + gotMedia(it, true) + } + } } else { media_refresh_layout.isRefreshing = true } @@ -631,20 +636,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { }.start() mIsGettingMedia = false - media_refresh_layout.isRefreshing = false - - media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache) - media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache) - media_grid.beVisibleIf(media_empty_text_label.isGone()) - - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID - media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) - media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) checkLastMediaChanged() - mMedia = media + runOnUiThread { + media_refresh_layout.isRefreshing = false + media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache) + media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache) + media_grid.beVisibleIf(media_empty_text_label.isGone()) + + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) + media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) + setupAdapter() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index fd5abf97b..88845a539 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -33,12 +33,14 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() }) .create().apply { - activity.setupDialogStuff(view, this, R.string.select_photo) - } + activity.setupDialogStuff(view, this, R.string.select_photo) + } - val media = activity.getCachedMedia(path).filter { !it.isVideo() } as ArrayList - if (media.isNotEmpty()) { - gotMedia(media) + activity.getCachedMedia(path) { + val media = it.filter { !it.isVideo() } as ArrayList + if (media.isNotEmpty()) { + gotMedia(media) + } } GetMediaAsynctask(activity, path, false, true, false) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index bdcb171c2..172fc25e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -11,8 +11,6 @@ import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -256,7 +254,10 @@ fun Activity.getCachedDirectories(callback: (ArrayList) -> Unit) { }.start() } -fun Activity.getCachedMedia(path: String): ArrayList { - val token = object : TypeToken>() {}.type - return Gson().fromJson>(config.loadFolderMedia(path), token) ?: ArrayList(1) +fun Activity.getCachedMedia(path: String, callback: (ArrayList) -> Unit) { + Thread { + val mediumDao = galleryDB.MediumDao() + val media = mediumDao.getMediaFromPath(path) as ArrayList + callback(media) + }.start() }