Feature: Added the ability for restore to also run a clear list before restoring.

This commit is contained in:
HeCodes2Much
2024-12-02 13:20:17 +00:00
parent 724219fdb7
commit ac4456dac4
3 changed files with 12 additions and 1 deletions

View File

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

View File

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

View File

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