Skip to content

Commit ac4456d

Browse files
Feature: Added the ability for restore to also run a clear list before restoring.
1 parent 724219f commit ac4456d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

app/src/main/java/com/github/droidworksstudio/launcher/data/dao/AppInfoDAO.kt

+4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ interface AppInfoDAO {
2222
@Insert(onConflict = OnConflictStrategy.REPLACE)
2323
suspend fun restoreAll(apps: List<AppInfo>)
2424

25+
2526
@Query("DELETE FROM app")
2627
suspend fun clearAll()
2728

29+
@Query("DELETE FROM sqlite_sequence WHERE name = 'app'")
30+
suspend fun resetAutoIncrement()
31+
2832
@Update
2933
suspend fun update(app: AppInfo)
3034

app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt

+7
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ class AppHelper @Inject constructor() {
389389
val type = object : TypeToken<List<AppInfo>>() {}.type
390390
val appInfoList: List<AppInfo> = gson.fromJson(jsonString, type)
391391

392+
// Clear all apps first
393+
resetDatabase(dao)
392394
// Reinsert data into the database
393395
dao.restoreAll(appInfoList)
394396
} ?: throw Exception("Failed to open input stream from URI")
@@ -398,6 +400,11 @@ class AppHelper @Inject constructor() {
398400
}
399401
}
400402

403+
suspend fun resetDatabase(dao: AppInfoDAO) {
404+
dao.clearAll() // Clears all rows in the table
405+
dao.resetAutoIncrement() // Resets the ID counter
406+
}
407+
401408

402409
fun getActionType(actionType: Constants.Swipe): NavOptions {
403410
return when (actionType) {

app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsAdvancedFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class SettingsAdvancedFragment : Fragment(),
170170
private fun clearData() {
171171
preferenceHelper.clearAll(context)
172172
lifecycleScope.launch {
173-
appDAO.clearAll()
173+
appHelper.resetDatabase(appDAO)
174174
}
175175
Handler(Looper.getMainLooper()).postDelayed({
176176
AppReloader.restartApp(context)

0 commit comments

Comments
 (0)