Android Open Source - PicSync Cloud Syncer






From Project

Back to project page PicSync.

License

The source code is released under:

Apache License

If you think the Android project PicSync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.darrenmowat.gdcu.service.helpers;
/*  w  w  w  .  j  a va2  s .com*/
import java.io.IOException;
import java.util.ArrayList;

import org.json.JSONException;

import android.content.Context;

import com.darrenmowat.gdcu.GDCU;
import com.darrenmowat.gdcu.data.Database;
import com.darrenmowat.gdcu.data.Preferences;
import com.darrenmowat.gdcu.drive.DriveApi;
import com.flurry.android.FlurryAgent;
import com.google.api.services.drive.model.File;

/*
 * This class keeps our database in sync with 
 * all the files that have been uploaded to Cloud
 */
public class CloudSyncer {

  private Database database;
  private DriveApi drive;

  public CloudSyncer(Context context, String userToken) {
    database = new Database(context);
    String uploadsDirName = Preferences.getUploadsFolderName(context);
    drive = new DriveApi(userToken, uploadsDirName);
  }

  public void sync() throws IOException, JSONException {
    database.connect();
    long lastSync = database.getLastSyncedTime();
    ArrayList<File> files = new ArrayList<File>();
    if (lastSync == 0) {
      // We've never synced with Drive
      files = drive.retrieveAllUploadedFiles();
    } else {
      // Sync changes since our last sync
      files = drive.retrieveAllUploadedFilesSince(lastSync);
    }
    // Add all the files to the database
    // SQLite will deal with conflicts
    for (File file : files) {
      database.addToUploaded(file.getTitle(), file.getMd5Checksum(), file.getId(), file
          .getCreatedDate().getValue(), file.getMimeType());
    }
    // What if something changed whilst we were downloading this
    long timestamp = System.currentTimeMillis() - 60000;
    database.setLastSyncedTime(timestamp);
    database.disconnect();
    if (!GDCU.DEVEL_BUILD) {
      FlurryAgent.logEvent("Synced with GDrive");
    }
  }
}




Java Source Code List

com.darrenmowat.gdcu.GDCU.java
com.darrenmowat.gdcu.Keys.java
com.darrenmowat.gdcu.activity.AuthActivity.java
com.darrenmowat.gdcu.activity.RenameFolderActivity.java
com.darrenmowat.gdcu.activity.SettingsActivity.java
com.darrenmowat.gdcu.activity.WebviewActivity.java
com.darrenmowat.gdcu.data.Database.java
com.darrenmowat.gdcu.data.Preferences.java
com.darrenmowat.gdcu.drive.DriveApi.java
com.darrenmowat.gdcu.otto.DataBus.java
com.darrenmowat.gdcu.otto.UploadStatusEventProducer.java
com.darrenmowat.gdcu.otto.UploadStatusEvent.java
com.darrenmowat.gdcu.security.PackageSecurityException.java
com.darrenmowat.gdcu.security.PackageSecurity.java
com.darrenmowat.gdcu.service.GalleryAlarmListener.java
com.darrenmowat.gdcu.service.GalleryObserver.java
com.darrenmowat.gdcu.service.MediaService.java
com.darrenmowat.gdcu.service.MediaThread.java
com.darrenmowat.gdcu.service.Notifier.java
com.darrenmowat.gdcu.service.ServiceUtils.java
com.darrenmowat.gdcu.service.UploadService.java
com.darrenmowat.gdcu.service.UploadThread.java
com.darrenmowat.gdcu.service.helpers.CloudSyncer.java
com.darrenmowat.gdcu.service.helpers.Media.java
com.darrenmowat.gdcu.service.helpers.ServiceIntents.java
com.darrenmowat.gdcu.service.helpers.ThreadCallbacks.java
com.darrenmowat.gdcu.tasks.GetTokenTask.java
com.darrenmowat.gdcu.tasks.RenameFolderTask.java
com.darrenmowat.gdcu.ui.ProgressDialogFragment.java
com.darrenmowat.gdcu.utils.HexConversions.java
com.darrenmowat.gdcu.utils.MD5Utils.java
com.darrenmowat.gdcu.utils.Preconditions.java