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 8137f0ba5..c56c0ebae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -29,7 +29,6 @@ import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* @@ -63,7 +62,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mTempShowHiddenHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null - private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -91,7 +89,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { removeTempFolder() directories_refresh_layout.setOnRefreshListener { getDirectories() } mDirs = ArrayList() - mGalleryDB = GalleryDataBase.getInstance(applicationContext) storeStateVariables() checkWhatsNewDialog() @@ -557,7 +554,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (!isFromCache) { Thread { //checkFolderContentChange(newDirs) - mGalleryDB!!.DirectoryDao().insertAll(newDirs) + galleryDB.DirectoryDao().insertAll(newDirs) }.start() } 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 507644f84..547cf7d37 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -33,7 +33,6 @@ 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.databases.GalleryDataBase import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.FilterMediaDialog @@ -63,7 +62,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mCurrAsyncTask: GetMediaAsynctask? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null - private var mGalleryDB: GalleryDataBase? = null private var mStoredAnimateGifs = true private var mStoredCropThumbnails = true @@ -96,7 +94,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } storeStateVariables() - mGalleryDB = GalleryDataBase.getInstance(applicationContext) if (mShowAll) { supportActionBar?.setDisplayHomeAsUpEnabled(false) @@ -629,7 +626,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mLatestMediaId = getLatestMediaId() mLatestMediaDateId = getLatestMediaByDateId() if (!isFromCache) { - mGalleryDB!!.MediumDao().insertAll(media) + galleryDB.MediumDao().insertAll(media) } }.start() 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 66a7fbde5..33c0cf0d5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.databases.GalleryDataBase import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT @@ -65,6 +66,8 @@ fun Context.launchSettings() { val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.galleryDB: GalleryDataBase get() = GalleryDataBase.getInstance(applicationContext) + fun Context.movePinnedDirectoriesToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() val pinnedFolders = config.pinnedFolders