diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index a5b9d346a..ed1ddee6b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -1122,7 +1122,10 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { dirs.removeAll(invalidDirs) setupAdapter(dirs) invalidDirs.forEach { - mDirectoryDao.deleteDirPath(it.path) + try { + mDirectoryDao.deleteDirPath(it.path) + } catch (ignored: Exception) { + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index bd5b65f44..9a4235f70 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.content.res.Configuration import android.database.Cursor -import android.database.sqlite.SQLiteException import android.graphics.Point import android.graphics.drawable.PictureDrawable import android.media.AudioManager @@ -477,7 +476,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Thread { val directories = try { directoryDao.getAll() as ArrayList - } catch (e: SQLiteException) { + } catch (e: Exception) { ArrayList() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 8ed09a992..e93d46050 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -243,11 +243,13 @@ class PhotoFragment : ViewPagerFragment() { // avoid GIFs being skewed, played in wrong aspect ratio if (mMedium.isGIF()) { mView.onGlobalLayout { - measureScreen() - Handler().postDelayed({ - mView.gif_view_frame.controller.resetState() - loadGif() - }, 50) + if (activity != null) { + measureScreen() + Handler().postDelayed({ + mView.gif_view_frame.controller.resetState() + loadGif() + }, 50) + } } } else { hideZoomableView() @@ -286,7 +288,7 @@ class PhotoFragment : ViewPagerFragment() { private fun measureScreen() { val metrics = DisplayMetrics() - activity!!.windowManager.defaultDisplay.getRealMetrics(metrics) + activity?.windowManager?.defaultDisplay?.getRealMetrics(metrics) mScreenWidth = metrics.widthPixels mScreenHeight = metrics.heightPixels }