photos auto backup design - Logan676/seadroid GitHub Wiki

function description

  • User choose Backup Photos from slide menu bar to turn on the backup function.
  • Popup a window to let user choose an account.
  • Show library list under the selected account and let user choose a library.
  • When user choose a library, popup a message to tell user that uploading task starts.
  • User can navigate to UploadTaskFragment to see photos uploading status.

limit conditions

  • have internet access
  • only via wifi
  • cache backup data, detect duplicate

technical design

  • Create a photos auto backup manager to backup local photos to the cloud.
  • When user turns on the auto backup button, load all photos from sdcard in order to add them to auto backup manager.
  • Monitor local photos, broadcast event when local photos change. For example, when user takes new photos by camera, monitor the change, broadcast the event and auto backup the newly added photos immediately.
  • When backup photos underneath, always popup to show user state messages.

code perspective

  • add a new package com.seafile.seadroid2.sync to manage backup functions
  • add a new class PhotosLoader which implements LoaderManager to asynchronously load local photos from sdcard
  • add a new class PhotosObserver which extends FileObserver to monitor file access and modification

Warning: If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object.
Note: FileObserver API is actually not recursively monitor all files and subdirectories inside the monitored directory

  • add a new service AutoBackupService which extends IntentService to provide auto backup service when application starts if user turn on the auto backup photos button.

Warning: If you want to notify the user about an event that happened in the background while your app was not visible, use a Notification. Never start an Activity in response to an incoming broadcast Intent.

  • add a new class AutoBackupManager to create and send a auto backup request to the AutoBackupService and use PhotosBackupReceiver which extends BroadcastReceiver to receive status broadcast sent by AutoBackupService
  • AutoBackupManager works as a controller, it connect PhotosObserver, PhotosLoader and PhotosBackupReceiver together. It is also responsible to add photos to upload queue and interact with UploadingTaskFragment. And if user turn off the auto upload button, it is its duty to stop the background service. Also it writes & reads data to SharedPreference and database, interact with UI thread or more.
  • cache cloud repo info selected by user to local sdcard (user SharedPreference)
  • cache upload photos data in local db to detect duplicate upload (use SQLite 3 databse)

other modules used

  • SeafilePathChooserActivity.java
  • UploadTasksFragment.java
  • BrowserActivity.addUploadTask()
  • FileLoader.java
  • Utils.getImageFoldersList()
⚠️ **GitHub.com Fallback** ⚠️