Class DynamicBackupUtils

java.lang.Object
com.pranavpandey.android.dynamic.backup.util.DynamicBackupUtils

public class DynamicBackupUtils extends Object
Helper class to perform backup operations.
  • Field Details

  • Constructor Details

    • DynamicBackupUtils

      public DynamicBackupUtils()
  • Method Details

    • getBackupDir

      @Nullable public static String getBackupDir(@Nullable Context context)
      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

      @Nullable public static String getBackupDirString(@Nullable Context context, @Nullable String path)
      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

      @NonNull public static String getBackupName()
      Returns the backup name according to the time in milliseconds.
      Returns:
      The backup name according to the time in milliseconds.
    • getLastBackup

      @Nullable public static String getLastBackup(@Nullable Context context, @Nullable String dir)
      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

      @Nullable public static File[] sortBackups(@Nullable File[] backups)
      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

      @Nullable public static String getLastModified(@Nullable Context context, @Nullable File backup)
      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

      @Nullable public static String getNoBackupHint(@Nullable Context context)
      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

      @Nullable public static String getNoBackupHintImport(@Nullable Context context)
      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

      @Nullable public static String[] getBackupOptions(@Nullable Context context)
      Returns available the backup options.
      Parameters:
      context - The context to be used.
      Returns:
      The available backup options.
    • getBackupOptionsIcons

      @Nullable public static int[] getBackupOptionsIcons(@Nullable Context context)
      Returns the icons for the backup options.
      Parameters:
      context - The context to be used.
      Returns:
      The icons for the backup options.
    • backupInfo

      public static boolean backupInfo(@Nullable Context context, @Nullable File destination)
      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.
    • backupSharedPreferences

      public static boolean backupSharedPreferences(@Nullable Context context, @Nullable File destination, @Nullable String preferences)
      Try to backup the supplied shared preferences.
      Parameters:
      context - The context to be used.
      destination - The destination to be used.
      preferences - The shared preferences to be used.
      Returns:
      true if the backup is created successfully.
    • restoreSharedPreferences

      public static boolean restoreSharedPreferences(@Nullable Context context, @Nullable File file)
      Try to restore the supplied shared preferences file.
      Parameters:
      context - The context to be used.
      file - The file to be restored.
      Returns:
      true if the shared preferences are restored 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

      public static boolean restoreDatabase(@Nullable Context context, @Nullable File file)
      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

      public static boolean restoreFiles(@Nullable Context context, @Nullable File dir)
      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: