From f0db2aa43cbfa4d0523e8571042807427c2be2f6 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Thu, 4 Apr 2024 11:38:57 +0200 Subject: [PATCH] Improve documentation --- .../settings/BackupRestoreSettingsFragment.java | 4 +++- .../newpipe/settings/export/ImportExportManager.kt | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java index 20af8c150..97df1549b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java @@ -187,6 +187,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { throw new IOException("Could not create databases dir"); } + // replace the current database if (!manager.extractDb(file)) { Toast.makeText(requireContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG) @@ -265,7 +266,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { } /** - * Save import path and restart system. + * Save import path and restart app. * * @param importDataUri The import path to save */ @@ -290,6 +291,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { private void showErrorSnackbar(final Throwable e, final String request) { ErrorUtil.showSnackbar(this, new ErrorInfo(e, UserAction.DATABASE_IMPORT_EXPORT, request)); } + private void createErrorNotification(final Throwable e, final String request) { ErrorUtil.createNotification( requireContext(), diff --git a/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt b/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt index 843806b80..9a0d842a4 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt @@ -67,11 +67,17 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) { return fileLocator.dbDir.exists() || fileLocator.dbDir.mkdir() } + /** + * Extracts the database from the given file to the app's database directory. + * The current app's database will be overwritten. + * @param file the .zip file to extract the database from + * @return true if the database was successfully extracted, false otherwise + */ fun extractDb(file: StoredFileHelper): Boolean { val success = ZipHelper.extractFileFromZip( - file, - BackupFileLocator.FILE_NAME_DB, - fileLocator.db.path, + file, + BackupFileLocator.FILE_NAME_DB, + fileLocator.db.path, ) if (success) {