public class BackupHelper
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
BACKUP_FILNAME
Name of file in the zipfile
|
private android.content.Context |
mContext
Global Application Context
|
private static BackupHelper |
sInstance |
private java.lang.String |
TAG
Class Indentifier
|
| Modifier | Constructor and Description |
|---|---|
private |
BackupHelper(android.content.Context context) |
| Modifier and Type | Method and Description |
|---|---|
void |
createBackupAsync()
Create a backup on Drive
|
private byte[] |
createZipContents(byte[] data)
Create the contents of a Zip file as a byte array
|
private byte[] |
createZipContentsFromDB()
Create the contents of a Zip file from the database
|
void |
deleteBackupAsync(Backup backup)
Delete a backup
|
private void |
deleteLastBackup()
Try to delete the last backup
|
(package private) void |
extractFromZipFile(java.io.BufferedInputStream bis,
BackupContents contents)
Extract the data from a ZipFile into a BackupContents
|
void |
getBackupsAsync()
Get the list of backups from Drive
|
private java.lang.String |
getZipFilename()
Get name of backup file
|
static BackupHelper |
INST(android.content.Context context)
Lazily create our instance
|
private void |
replaceDB(BackupContents contents)
Replace the contents of the database
|
void |
restoreBackupAsync(Backup backup)
Restore the contents of a backup to the database
|
private void |
saveContentsToDB(BackupContents contents)
Replace the database with the restored data
|
private BackupContents |
saveMergedContentsToDB(BackupContents contents)
Replace the database with a merge of the given data
|
private void |
showMessage(java.lang.String msg,
java.lang.Exception ex)
Log exception and show message
|
void |
syncContentsAsync(Backup backup)
Synchronize the contents of a backup and the database
|
private static BackupHelper sInstance
private final android.content.Context mContext
private final java.lang.String TAG
private final java.lang.String BACKUP_FILNAME
public static BackupHelper INST(@NonNull android.content.Context context)
context - any old contextpublic void getBackupsAsync()
public void createBackupAsync()
public void restoreBackupAsync(Backup backup)
backup - File to restorepublic void syncContentsAsync(Backup backup)
backup - File to sync withpublic void deleteBackupAsync(@NonNull
Backup backup)
backup - File to deleteprivate void saveContentsToDB(@Nullable
BackupContents contents)
throws java.io.IOException,
android.database.SQLException
contents - database data to restorejava.io.IOException - if no contentsandroid.database.SQLException - if database update failedprivate BackupContents saveMergedContentsToDB(@Nullable BackupContents contents) throws java.io.IOException, android.database.SQLException
contents - data to merge with dbjava.io.IOException - if no contentsandroid.database.SQLException - if database update failedprivate byte[] createZipContentsFromDB()
throws java.io.IOException
java.io.IOException - on processing dataprivate byte[] createZipContents(@NonNull
byte[] data)
throws java.io.IOException
data - contents of zip filejava.io.IOException - if no contentsvoid extractFromZipFile(@NonNull
java.io.BufferedInputStream bis,
@NonNull
BackupContents contents)
bis - stream of datacontents - will contain the contentsprivate void deleteLastBackup()
private void replaceDB(@NonNull
BackupContents contents)
throws android.database.SQLException
contents - new contentsandroid.database.SQLException - - if database update failed@NonNull private java.lang.String getZipFilename()
private void showMessage(@NonNull
java.lang.String msg,
@NonNull
java.lang.Exception ex)
msg - messageex - exception