Skip to content

Commit

Permalink
Feature: Added the ability for restore to also run a clear list befor…
Browse files Browse the repository at this point in the history
…e restoring.
  • Loading branch information
CreativeCodeCat committed Dec 2, 2024
1 parent 724219f commit ac4456d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ac4456d

Please sign in to comment.