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.
-
Nested Class Summary
Nested classes/interfaces inherited from class androidx.fragment.app.Fragment
Fragment.InstantiationException, Fragment.SavedState
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected File
Backup file used by this fragment.protected DynamicBackupDialog
Dialog fragment to show the backup options.protected DynamicDialogFragment
Dialog fragment to show the progress.protected static final int
Constant to request the backup file location.protected static final int
Constant to request the backup import from file.protected static final int
Constant to request the storage permission to create backup.protected static final int
Constant to request the storage permission to restore backup.Fields inherited from class androidx.fragment.app.Fragment
mPreviousWho
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the mime type to import the backup file.int
This method will be called to get the selected backup location.boolean
Checks whether the storage permission is granted.void
onActivityResult
(int requestCode, int resultCode, Intent data) void
onAllBackupsDeleted
(boolean deleted) This method will be called after deleting all the backups stored in the app storage.void
onBackupCreated
(File backup, int location) This method will be called when a backup is created.void
onBackupDeleted
(String backup) This method will be called after deleting a backup.void
onBackupError
(File file, int location) This method will be called if there is any error while doing the backup operations.void
onBackupRenamed
(File backup, String newName, boolean renamed) This method will be called after renaming the backup.void
onBackupSaved
(Uri backup, int location) This method will be called when a backup is saved.void
onBackupSaved
(File backup, int location) This method will be called when a backup is saved.void
onCreateBackup
(String backup, int location) This method will be called on creating the backup.void
This method will be called on deleting all the backups stored in the app storage.void
onDeleteAllBackups
(boolean delete) This method will be called on deleting all the backups stored in the app storage.void
onDeleteBackup
(File backup, boolean delete) This method will be called on deleting the backup.void
onDismiss
(DialogInterface dialogInterface) void
This method will be called on requesting the backup from device storage.void
onImportBackup
(Uri uri) This method will be called on importing the backup from device storage.void
This method will be called on refreshing the backup state.void
onRenameBackup
(File backup, String newName) This method will be called on renaming the backup.void
onRestoreBackup
(File backup) This method will be called on restoring a backup.void
onRestoreBackup
(File backup, boolean delete) This method will be called on restoring a backup.void
onRestoreError
(File file) This method will be called if there is any error while doing the restore operations.void
onSetProgress
(BackupConfig backupConfig, boolean visible) This method will be called to set the backup progress.boolean
requestStoragePermission
(int requestCode) Request the storage permission.protected void
saveBackup
(int requestCode, Uri file) Save backup according to the supplied parameters.void
setBackupLocation
(int location) This method will be called to save the selected backup location.void
showBackupDialog
(int type) This method will be called to show the backup dialog.Methods inherited from class com.pranavpandey.android.dynamic.support.fragment.DynamicFragment
finishActivity, getBooleanFromArguments, getCheckedMenuItemId, getDynamicActivity, getDynamicEnterTransition, getDynamicExitTransition, getDynamicReenterTransition, getDynamicReturnTransition, getHostMenu, getIntFromArguments, getNavigationViewId, getParcelableFromArguments, getPostponeTransitionView, getProductFlavor, getSavedInstanceState, getStringFromArguments, getStringFromArguments, getSubtitle, getSystemActivity, getTextWatcher, getTitle, invalidateHostMenu, isAppCompatActivity, isEnableMenu, isForceMenuIcons, isHasMenuProvider, isOnSharedPreferenceChangeListener, isSearchViewExpanded, isSearchViewListenerListener, isSupportActionBar, onAddActivityHeader, onAddMenuProvider, onAdjustEnterReturnTransition, onAdjustExitReenterTransition, onApplyTransitions, onCreate, onCreateMenu, onDestroy, onDynamicPause, onDynamicResume, onFindView, onMenuClosed, onMenuItemSelected, onPause, onPrepareMenu, onRemoveProvider, onResume, onSaveInstanceState, onSearchViewCollapsed, onSearchViewExpanded, onSharedPreferenceChanged, onStart, onStartActivityException, onViewCreated, postponeEnterTransition, setHasOptionsMenu, setHostMenuItemVisible, setMenuVisibility, setResult, setResult, setResult, setResult, startActivity, startActivity, startActivityForResult, startActivityForResult, startMotionActivity, startMotionActivityForResult, startPostponedEnterTransition
Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onStop, onViewStateRestored, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startIntentSenderForResult, toString, unregisterForContextMenu
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.pranavpandey.android.dynamic.backup.DynamicBackup
getBackupDir, getBackupExtension, getBackupMime, getBackupTask, getRestoreTask, isBackupExist, onRestoreComplete, onShareBackup, onVerifyBackup, onVerifyBackup
-
Field Details
-
REQUEST_PERMISSION_BACKUP
protected static final int REQUEST_PERMISSION_BACKUPConstant to request the storage permission to create backup.- See Also:
-
REQUEST_PERMISSION_RESTORE
protected static final int REQUEST_PERMISSION_RESTOREConstant to request the storage permission to restore backup.- See Also:
-
REQUEST_BACKUP_LOCATION
protected static final int REQUEST_BACKUP_LOCATIONConstant to request the backup file location.- See Also:
-
REQUEST_IMPORT_BACKUP
protected static final int REQUEST_IMPORT_BACKUPConstant to request the backup import from file.- See Also:
-
mBackup
Backup file used by this fragment. -
mBackupDialog
Dialog fragment to show the backup options. -
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
Description copied from interface:DynamicBackup
Returns the mime type to import the backup file.- Specified by:
getBackupImportMime
in interfaceDynamicBackup
- 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 interfaceDynamicBackup
- 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 interfaceDynamicBackup
- 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 interfaceDynamicBackup
- Parameters:
location
- The backup location to be set.
-
onCreateBackup
Description copied from interface:DynamicBackup
This method will be called on creating the backup.- Specified by:
onCreateBackup
in interfaceDynamicBackup
- Parameters:
backup
- The requested backup name.location
- The requested backup location.
-
onBackupCreated
Description copied from interface:DynamicBackup
This method will be called when a backup is created.- Specified by:
onBackupCreated
in interfaceDynamicBackup
- Parameters:
backup
- The created backup file.location
- The requested backup location.
-
onBackupSaved
Description copied from interface:DynamicBackup
This method will be called when a backup is saved.- Specified by:
onBackupSaved
in interfaceDynamicBackup
- Parameters:
backup
- The saved backup file.location
- The requested backup location.
-
onBackupSaved
Description copied from interface:DynamicBackup
This method will be called when a backup is saved.- Specified by:
onBackupSaved
in interfaceDynamicBackup
- Parameters:
backup
- The saved backup file URI.location
- The requested backup location.
-
onRenameBackup
Description copied from interface:DynamicBackup
This method will be called on renaming the backup.- Specified by:
onRenameBackup
in interfaceDynamicBackup
- Parameters:
backup
- The backup file to be renamed.newName
- The new name for the backup file.
-
onBackupRenamed
Description copied from interface:DynamicBackup
This method will be called after renaming the backup.- Specified by:
onBackupRenamed
in interfaceDynamicBackup
- Parameters:
backup
- The renamed backup file to.newName
- The new name of the backup file.renamed
-true
if the backup is renamed successfully.
-
onDeleteBackup
Description copied from interface:DynamicBackup
This method will be called on deleting the backup.- Specified by:
onDeleteBackup
in interfaceDynamicBackup
- Parameters:
backup
- The backup file to be deleted.delete
-true
to delete the backup.
-
onBackupDeleted
Description copied from interface:DynamicBackup
This method will be called after deleting a backup.- Specified by:
onBackupDeleted
in interfaceDynamicBackup
- 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 interfaceDynamicBackup
-
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 interfaceDynamicBackup
- 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 interfaceDynamicBackup
- Parameters:
deleted
-true
if the operation has been completed successfully.
-
onRestoreBackup
Description copied from interface:DynamicBackup
This method will be called on restoring a backup.- Specified by:
onRestoreBackup
in interfaceDynamicBackup
- Parameters:
backup
- The backup file to be restored.
-
onRestoreBackup
Description copied from interface:DynamicBackup
This method will be called on restoring a backup.- Specified by:
onRestoreBackup
in interfaceDynamicBackup
- 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 interfaceDynamicBackup
-
onImportBackup
Description copied from interface:DynamicBackup
This method will be called on importing the backup from device storage.- Specified by:
onImportBackup
in interfaceDynamicBackup
- 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 interfaceDynamicBackup
-
onBackupError
Description copied from interface:DynamicBackup
This method will be called if there is any error while doing the backup operations.- Specified by:
onBackupError
in interfaceDynamicBackup
- Parameters:
file
- The erroneous backup file.location
- The requested backup location.
-
onRestoreError
Description copied from interface:DynamicBackup
This method will be called if there is any error while doing the restore operations.- Specified by:
onRestoreError
in interfaceDynamicBackup
- Parameters:
file
- The erroneous restore file.
-
saveBackup
Save backup according to the supplied parameters.- Parameters:
requestCode
- The request code to be used.file
- The file URI to be used.
-
onActivityResult
- Overrides:
onActivityResult
in classFragment
-
onDismiss
- Specified by:
onDismiss
in interfaceDialogInterface.OnDismissListener
-