mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
migrate favorites in the new table on app upgrade
This commit is contained in:
parent
9d2239d1c1
commit
409be79489
3 changed files with 37 additions and 0 deletions
|
@ -2,9 +2,41 @@ package com.simplemobiletools.gallery.pro.activities
|
|||
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.commons.activities.BaseSplashActivity
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.gallery.pro.extensions.config
|
||||
import com.simplemobiletools.gallery.pro.extensions.favoritesDB
|
||||
import com.simplemobiletools.gallery.pro.extensions.getFavoriteFromPath
|
||||
import com.simplemobiletools.gallery.pro.extensions.mediaDB
|
||||
import com.simplemobiletools.gallery.pro.models.Favorite
|
||||
|
||||
class SplashActivity : BaseSplashActivity() {
|
||||
override fun initActivity() {
|
||||
|
||||
// check if previously selected favorite items have been properly migrated into the new Favorites table
|
||||
if (config.wereFavoritesMigrated) {
|
||||
launchActivity()
|
||||
} else {
|
||||
if (config.appRunCount == 0) {
|
||||
config.wereFavoritesMigrated = true
|
||||
} else {
|
||||
ensureBackgroundThread {
|
||||
val favorites = ArrayList<Favorite>()
|
||||
val favoritePaths = mediaDB.getFavorites().map { it.path }.toMutableList() as ArrayList<String>
|
||||
favoritePaths.forEach {
|
||||
favorites.add(getFavoriteFromPath(it))
|
||||
}
|
||||
favoritesDB.insertAll(favorites)
|
||||
config.wereFavoritesMigrated = true
|
||||
|
||||
runOnUiThread {
|
||||
launchActivity()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchActivity() {
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -494,4 +494,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var editorBrushSize: Float
|
||||
get() = prefs.getFloat(EDITOR_BRUSH_SIZE, 0.05f)
|
||||
set(editorBrushSize) = prefs.edit().putFloat(EDITOR_BRUSH_SIZE, editorBrushSize).apply()
|
||||
|
||||
var wereFavoritesMigrated: Boolean
|
||||
get() = prefs.getBoolean(WERE_FAVORITES_MIGRATED, false)
|
||||
set(wereFavoritesMigrated) = prefs.edit().putBoolean(WERE_FAVORITES_MIGRATED, wereFavoritesMigrated).apply()
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ const val SHOW_THUMBNAIL_FILE_TYPES = "show_thumbnail_file_types"
|
|||
const val EDITOR_BRUSH_COLOR = "editor_brush_color"
|
||||
const val EDITOR_BRUSH_HARDNESS = "editor_brush_hardness"
|
||||
const val EDITOR_BRUSH_SIZE = "editor_brush_size"
|
||||
const val WERE_FAVORITES_MIGRATED = "were_favorites_migrated"
|
||||
|
||||
// slideshow
|
||||
const val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||
|
|
Loading…
Reference in a new issue