move the gallery database fetcher in a context extension

This commit is contained in:
tibbi 2018-04-20 11:52:26 +02:00
parent 73000aa611
commit b0afe92afb
3 changed files with 5 additions and 8 deletions

View file

@ -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()
}

View file

@ -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()

View file

@ -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<Directory>): ArrayList<Directory> {
val foundFolders = ArrayList<Directory>()
val pinnedFolders = config.pinnedFolders