Class DynamicBackupUtils
java.lang.Object
com.pranavpandey.android.dynamic.backup.util.DynamicBackupUtils
Helper class to perform backup operations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
backupDatabase
(Context context, File destination, SQLiteOpenHelper database) Try to backup the supplied database.static boolean
backupDatabase
(Context context, File destination, SupportSQLiteOpenHelper database) Try to backup the supplied database.static boolean
backupInfo
(Context context, File destination) Try to create the backup info at the supplied destination.static boolean
backupSharedPreferences
(Context context, File destination, String preferences) Try to backup the supplied shared preferences.static String
getBackupCreated
(Context context, String backupName) Returns the formatted string with the backup created info.static String
getBackupDeleted
(Context context, String backupName) Returns the formatted string with the backup deleted info.static String
getBackupDir
(Context context) Returns the default backup directory for the app.static String
getBackupDirString
(Context context, String path) Returns the formatted backup directory according to the supplied path.static String
getBackupModified
(Context context, String backupName) Returns the formatted string with the backup modified info.static String
Returns the backup name according to the time in milliseconds.static String[]
getBackupOptions
(Context context) Returns available the backup options.static int[]
getBackupOptionsIcons
(Context context) Returns the icons for the backup options.static String
getBackupRenamed
(Context context, String backupName) Returns the formatted string with the backup renamed info.static String
getBackupRestored
(Context context, String backupName) Returns the formatted string with the backup restored info.static String
getBackupSaved
(Context context, String backupName) Returns the formatted string with the backup saved info.static String
getLastBackup
(Context context, String dir) Returns the info about the last backup in the supplied directory.static String
getLastModified
(Context context, File backup) Returns the last modified info for the supplied backup.static String
getNoBackupHint
(Context context) Returns the hint to notify if no backups are available to restore.static String
getNoBackupHintImport
(Context context) Returns the hint to notify if no backups are available to restore along with the import info.static boolean
restoreDatabase
(Context context, File file) Try to restore the supplied database file.static boolean
restoreFiles
(Context context, File dir) Try to restore the shared preferences and database inside the supplied directory.static boolean
restoreSharedPreferences
(Context context, File file) Try to restore the supplied shared preferences file.static File[]
sortBackups
(File[] backups) Sort backups in ascending order according to the last modified date.
-
Field Details
-
EXTENSION_XML
XML file extension.- See Also:
-
EXTENSION_DB
Database file extension.- See Also:
-
DIR_BACKUP
Default directory for the app backup.- See Also:
-
-
Constructor Details
-
DynamicBackupUtils
public DynamicBackupUtils()
-
-
Method Details
-
getBackupDir
Returns the default backup directory for the app.- Parameters:
context
- The context to be used.- Returns:
- The default backup directory for the app.
- See Also:
-
getBackupDirString
Returns the formatted backup directory according to the supplied path.- Parameters:
context
- The context to be used.path
- The path to be used.- Returns:
- The formatted backup directory according to the supplied path.
-
getBackupName
Returns the backup name according to the time in milliseconds.- Returns:
- The backup name according to the time in milliseconds.
-
getLastBackup
Returns the info about the last backup in the supplied directory.- Parameters:
context
- The context to be used.dir
- The backup location to be used.- Returns:
- The info about the last backup in the supplied directory.
-
sortBackups
Sort backups in ascending order according to the last modified date.- Parameters:
backups
- The backups to be sorted.- Returns:
- The sorted backups in ascending order according to the last modified date.
-
getLastModified
Returns the last modified info for the supplied backup.- Parameters:
context
- The context to be used.backup
- The backup file to be used.- Returns:
- The last modified info for the supplied backup.
-
getBackupCreated
@Nullable public static String getBackupCreated(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup created info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup created info.
-
getBackupModified
@Nullable public static String getBackupModified(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup modified info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup modified info.
-
getBackupSaved
@Nullable public static String getBackupSaved(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup saved info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup saved info.
-
getBackupRenamed
@Nullable public static String getBackupRenamed(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup renamed info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup renamed info.
-
getBackupDeleted
@Nullable public static String getBackupDeleted(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup deleted info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup deleted info.
-
getBackupRestored
@Nullable public static String getBackupRestored(@Nullable Context context, @Nullable String backupName) Returns the formatted string with the backup restored info.- Parameters:
context
- The context to be used.backupName
- The backup name to be used.- Returns:
- The formatted string with the backup restored info.
-
getNoBackupHint
Returns the hint to notify if no backups are available to restore.- Parameters:
context
- The context to be used.- Returns:
- The hint to notify if no backups are available to restore.
-
getNoBackupHintImport
Returns the hint to notify if no backups are available to restore along with the import info.- Parameters:
context
- The context to be used.- Returns:
- The hint to notify if no backups are available to restore along with the import info.
-
getBackupOptions
Returns available the backup options.- Parameters:
context
- The context to be used.- Returns:
- The available backup options.
-
getBackupOptionsIcons
Returns the icons for the backup options.- Parameters:
context
- The context to be used.- Returns:
- The icons for the backup options.
-
backupInfo
Try to create the backup info at the supplied destination.- Parameters:
context
- The context to be used.destination
- The destination to be used.- Returns:
true
if the backup info is created successfully.
-
backupDatabase
public static boolean backupDatabase(@Nullable Context context, @Nullable File destination, @Nullable SQLiteOpenHelper database) Try to backup the supplied database.- Parameters:
context
- The context to be used.destination
- The destination to be used.database
- The database to be used.- Returns:
true
if the backup is created successfully.
-
backupDatabase
public static boolean backupDatabase(@Nullable Context context, @Nullable File destination, @Nullable SupportSQLiteOpenHelper database) Try to backup the supplied database.- Parameters:
context
- The context to be used.destination
- The destination to be used.database
- The database to be used.- Returns:
true
if the backup is created successfully.
-
restoreDatabase
Try to restore the supplied database file.- Parameters:
context
- The context to be used.file
- The file to be restored.- Returns:
true
if the file is restored successfully.
-
restoreFiles
Try to restore the shared preferences and database inside the supplied directory.- Parameters:
context
- The context to be used.dir
- The directory to be restored.- Returns:
true
if the directory is restored successfully.- See Also:
-