Class DynamicBackupFragment

java.lang.Object
androidx.fragment.app.Fragment
com.pranavpandey.android.dynamic.support.fragment.DynamicFragment
com.pranavpandey.android.dynamic.backup.fragment.DynamicBackupFragment
All Implemented Interfaces:
ComponentCallbacks, DialogInterface.OnDismissListener, SharedPreferences.OnSharedPreferenceChangeListener, View.OnCreateContextMenuListener, ActivityResultCaller, MenuProvider, HasDefaultViewModelProviderFactory, LifecycleOwner, ViewModelStoreOwner, SavedStateRegistryOwner, DynamicBackup, DynamicLifecycle, DynamicSearchListener, DynamicTransitionListener, DynamicProductFlavor

public abstract class DynamicBackupFragment extends DynamicFragment implements DynamicBackup, DialogInterface.OnDismissListener
A DynamicFragment to provide backup and restore functionality.

Extend it and implement the required methods accordingly.

  • Field Details

    • REQUEST_PERMISSION_BACKUP

      protected static final int REQUEST_PERMISSION_BACKUP
      Constant to request the storage permission to create backup.
      See Also:
    • REQUEST_PERMISSION_RESTORE

      protected static final int REQUEST_PERMISSION_RESTORE
      Constant to request the storage permission to restore backup.
      See Also:
    • REQUEST_BACKUP_LOCATION

      protected static final int REQUEST_BACKUP_LOCATION
      Constant to request the backup file location.
      See Also:
    • REQUEST_IMPORT_BACKUP

      protected static final int REQUEST_IMPORT_BACKUP
      Constant to request the backup import from file.
      See Also:
    • mBackup

      protected File mBackup
      Backup file used by this fragment.
    • mBackupDialog

      protected DynamicBackupDialog mBackupDialog
      Dialog fragment to show the backup options.
    • mProgressDialog

      protected DynamicDialogFragment mProgressDialog
      Dialog fragment to show the progress.
  • Constructor Details

    • DynamicBackupFragment

      public DynamicBackupFragment()
  • Method Details

    • isStoragePermissionGranted

      public boolean isStoragePermissionGranted()
      Checks whether the storage permission is granted.

      Currently, it will always return true as it is not required for API 19 and above.

      Returns:
      true if storage permission is granted.
    • requestStoragePermission

      public boolean requestStoragePermission(int requestCode)
      Request the storage permission.
      Parameters:
      requestCode - The request code for the result.
      Returns:
      true if the storage permission has been granted.
    • getBackupImportMime

      @NonNull public String getBackupImportMime()
      Description copied from interface: DynamicBackup
      Returns the mime type to import the backup file.
      Specified by:
      getBackupImportMime in interface DynamicBackup
      Returns:
      The mime type to import the backup file.
    • showBackupDialog

      public void showBackupDialog(int type)
      Description copied from interface: DynamicBackup
      This method will be called to show the backup dialog.
      Specified by:
      showBackupDialog in interface DynamicBackup
      Parameters:
      type - The dialog type to be set.
    • getBackupLocation

      public int getBackupLocation()
      Description copied from interface: DynamicBackup
      This method will be called to get the selected backup location.
      Specified by:
      getBackupLocation in interface DynamicBackup
      Returns:
      The selected backup location.
    • setBackupLocation

      public void setBackupLocation(int location)
      Description copied from interface: DynamicBackup
      This method will be called to save the selected backup location.
      Specified by:
      setBackupLocation in interface DynamicBackup
      Parameters:
      location - The backup location to be set.
    • onCreateBackup

      public void onCreateBackup(@NonNull String backup, int location)
      Description copied from interface: DynamicBackup
      This method will be called on creating the backup.
      Specified by:
      onCreateBackup in interface DynamicBackup
      Parameters:
      backup - The requested backup name.
      location - The requested backup location.
    • onSetProgress

      public void onSetProgress(@Nullable BackupConfig backupConfig, boolean visible)
      Description copied from interface: DynamicBackup
      This method will be called to set the backup progress.
      Specified by:
      onSetProgress in interface DynamicBackup
      Parameters:
      backupConfig - The backup configurations.
      visible - true to make the progress visible.
    • onBackupCreated

      public void onBackupCreated(@Nullable File backup, int location)
      Description copied from interface: DynamicBackup
      This method will be called when a backup is created.
      Specified by:
      onBackupCreated in interface DynamicBackup
      Parameters:
      backup - The created backup file.
      location - The requested backup location.
    • onBackupSaved

      public void onBackupSaved(@Nullable File backup, int location)
      Description copied from interface: DynamicBackup
      This method will be called when a backup is saved.
      Specified by:
      onBackupSaved in interface DynamicBackup
      Parameters:
      backup - The saved backup file.
      location - The requested backup location.
    • onBackupSaved

      public void onBackupSaved(@Nullable Uri backup, int location)
      Description copied from interface: DynamicBackup
      This method will be called when a backup is saved.
      Specified by:
      onBackupSaved in interface DynamicBackup
      Parameters:
      backup - The saved backup file URI.
      location - The requested backup location.
    • onRenameBackup

      public void onRenameBackup(@NonNull File backup, @NonNull String newName)
      Description copied from interface: DynamicBackup
      This method will be called on renaming the backup.
      Specified by:
      onRenameBackup in interface DynamicBackup
      Parameters:
      backup - The backup file to be renamed.
      newName - The new name for the backup file.
    • onBackupRenamed

      public void onBackupRenamed(@Nullable File backup, @Nullable String newName, boolean renamed)
      Description copied from interface: DynamicBackup
      This method will be called after renaming the backup.
      Specified by:
      onBackupRenamed in interface DynamicBackup
      Parameters:
      backup - The renamed backup file to.
      newName - The new name of the backup file.
      renamed - true if the backup is renamed successfully.
    • onDeleteBackup

      public void onDeleteBackup(@Nullable File backup, boolean delete)
      Description copied from interface: DynamicBackup
      This method will be called on deleting the backup.
      Specified by:
      onDeleteBackup in interface DynamicBackup
      Parameters:
      backup - The backup file to be deleted.
      delete - true to delete the backup.
    • onBackupDeleted

      public void onBackupDeleted(@Nullable String backup)
      Description copied from interface: DynamicBackup
      This method will be called after deleting a backup.
      Specified by:
      onBackupDeleted in interface DynamicBackup
      Parameters:
      backup - The deleted backup name.
    • onDeleteAllBackups

      public void onDeleteAllBackups()
      Description copied from interface: DynamicBackup
      This method will be called on deleting all the backups stored in the app storage.
      Specified by:
      onDeleteAllBackups in interface DynamicBackup
    • onDeleteAllBackups

      public void onDeleteAllBackups(boolean delete)
      Description copied from interface: DynamicBackup
      This method will be called on deleting all the backups stored in the app storage.
      Specified by:
      onDeleteAllBackups in interface DynamicBackup
      Parameters:
      delete - true to delete all the backups.
    • onAllBackupsDeleted

      public void onAllBackupsDeleted(boolean deleted)
      Description copied from interface: DynamicBackup
      This method will be called after deleting all the backups stored in the app storage.
      Specified by:
      onAllBackupsDeleted in interface DynamicBackup
      Parameters:
      deleted - true if the operation has been completed successfully.
    • onRestoreBackup

      public void onRestoreBackup(@NonNull File backup)
      Description copied from interface: DynamicBackup
      This method will be called on restoring a backup.
      Specified by:
      onRestoreBackup in interface DynamicBackup
      Parameters:
      backup - The backup file to be restored.
    • onRestoreBackup

      public void onRestoreBackup(@NonNull File backup, boolean delete)
      Description copied from interface: DynamicBackup
      This method will be called on restoring a backup.
      Specified by:
      onRestoreBackup in interface DynamicBackup
      Parameters:
      backup - The backup file to be restored.
      delete - true to delete the backup file after performing the restore operation.
    • onImportBackup

      public void onImportBackup()
      Description copied from interface: DynamicBackup
      This method will be called on requesting the backup from device storage.
      Specified by:
      onImportBackup in interface DynamicBackup
    • onImportBackup

      public void onImportBackup(@Nullable Uri uri)
      Description copied from interface: DynamicBackup
      This method will be called on importing the backup from device storage.
      Specified by:
      onImportBackup in interface DynamicBackup
      Parameters:
      uri - The backup file URI to be imported.
    • onRefresh

      public void onRefresh()
      Description copied from interface: DynamicBackup
      This method will be called on refreshing the backup state.
      Specified by:
      onRefresh in interface DynamicBackup
    • onBackupError

      public void onBackupError(@Nullable File file, int location)
      Description copied from interface: DynamicBackup
      This method will be called if there is any error while doing the backup operations.
      Specified by:
      onBackupError in interface DynamicBackup
      Parameters:
      file - The erroneous backup file.
      location - The requested backup location.
    • onRestoreError

      public void onRestoreError(@Nullable File file)
      Description copied from interface: DynamicBackup
      This method will be called if there is any error while doing the restore operations.
      Specified by:
      onRestoreError in interface DynamicBackup
      Parameters:
      file - The erroneous restore file.
    • saveBackup

      protected void saveBackup(int requestCode, @Nullable Uri file)
      Save backup according to the supplied parameters.
      Parameters:
      requestCode - The request code to be used.
      file - The file URI to be used.
    • onActivityResult

      public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
      Overrides:
      onActivityResult in class Fragment
    • onDismiss

      public void onDismiss(DialogInterface dialogInterface)
      Specified by:
      onDismiss in interface DialogInterface.OnDismissListener