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)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun restoreAll(apps: List<AppInfo>)
|
suspend fun restoreAll(apps: List<AppInfo>)
|
||||||
|
|
||||||
|
|
||||||
@Query("DELETE FROM app")
|
@Query("DELETE FROM app")
|
||||||
suspend fun clearAll()
|
suspend fun clearAll()
|
||||||
|
|
||||||
|
@Query("DELETE FROM sqlite_sequence WHERE name = 'app'")
|
||||||
|
suspend fun resetAutoIncrement()
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
suspend fun update(app: AppInfo)
|
suspend fun update(app: AppInfo)
|
||||||
|
|
||||||
|
|||||||
@@ -389,6 +389,8 @@ class AppHelper @Inject constructor() {
|
|||||||
val type = object : TypeToken<List<AppInfo>>() {}.type
|
val type = object : TypeToken<List<AppInfo>>() {}.type
|
||||||
val appInfoList: List<AppInfo> = gson.fromJson(jsonString, type)
|
val appInfoList: List<AppInfo> = gson.fromJson(jsonString, type)
|
||||||
|
|
||||||
|
// Clear all apps first
|
||||||
|
resetDatabase(dao)
|
||||||
// Reinsert data into the database
|
// Reinsert data into the database
|
||||||
dao.restoreAll(appInfoList)
|
dao.restoreAll(appInfoList)
|
||||||
} ?: throw Exception("Failed to open input stream from URI")
|
} ?: 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 {
|
fun getActionType(actionType: Constants.Swipe): NavOptions {
|
||||||
return when (actionType) {
|
return when (actionType) {
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class SettingsAdvancedFragment : Fragment(),
|
|||||||
private fun clearData() {
|
private fun clearData() {
|
||||||
preferenceHelper.clearAll(context)
|
preferenceHelper.clearAll(context)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
appDAO.clearAll()
|
appHelper.resetDatabase(appDAO)
|
||||||
}
|
}
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
AppReloader.restartApp(context)
|
AppReloader.restartApp(context)
|
||||||
|
|||||||
Reference in New Issue
Block a user