Feature: Added the ability for restore to also run a clear list before restoring.
This commit is contained in:
@@ -22,9 +22,13 @@ interface AppInfoDAO {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun restoreAll(apps: List<AppInfo>)
|
||||
|
||||
|
||||
@Query("DELETE FROM app")
|
||||
suspend fun clearAll()
|
||||
|
||||
@Query("DELETE FROM sqlite_sequence WHERE name = 'app'")
|
||||
suspend fun resetAutoIncrement()
|
||||
|
||||
@Update
|
||||
suspend fun update(app: AppInfo)
|
||||
|
||||
|
||||
@@ -389,6 +389,8 @@ class AppHelper @Inject constructor() {
|
||||
val type = object : TypeToken<List<AppInfo>>() {}.type
|
||||
val appInfoList: List<AppInfo> = gson.fromJson(jsonString, type)
|
||||
|
||||
// Clear all apps first
|
||||
resetDatabase(dao)
|
||||
// Reinsert data into the database
|
||||
dao.restoreAll(appInfoList)
|
||||
} ?: throw Exception("Failed to open input stream from URI")
|
||||
@@ -398,6 +400,11 @@ class AppHelper @Inject constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun resetDatabase(dao: AppInfoDAO) {
|
||||
dao.clearAll() // Clears all rows in the table
|
||||
dao.resetAutoIncrement() // Resets the ID counter
|
||||
}
|
||||
|
||||
|
||||
fun getActionType(actionType: Constants.Swipe): NavOptions {
|
||||
return when (actionType) {
|
||||
|
||||
@@ -170,7 +170,7 @@ class SettingsAdvancedFragment : Fragment(),
|
||||
private fun clearData() {
|
||||
preferenceHelper.clearAll(context)
|
||||
lifecycleScope.launch {
|
||||
appDAO.clearAll()
|
||||
appHelper.resetDatabase(appDAO)
|
||||
}
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
AppReloader.restartApp(context)
|
||||
|
||||
Reference in New Issue
Block a user