Exemplo n.º 1
0
 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
   try {
     Log.d("syncPrefs", "onChanged");
     if (activity.isFinishing()) {
       // Setting the summary now would crash it with
       // IllegalStateException since we are not attached to a view
     } else {
       if (KEY_SYNC_ENABLE.equals(key)) {
         toggleSync(prefs);
       } else if (KEY_BACKGROUND_SYNC.equals(key)) {
         setSyncInterval(activity, prefs);
       } else if (KEY_ACCOUNT.equals(key)) {
         Log.d("syncPrefs", "account");
         prefAccount.setTitle(prefs.getString(KEY_ACCOUNT, ""));
       } else if (KEY_SD_ENABLE.equals(key)) {
         // Restart the sync service
         OrgSyncService.stop(getActivity());
       } else if (KEY_SD_DIR.equals(key)) {
         setSdDirSummary(prefs);
       } else if (KEY_DROPBOX_ENABLE.equals(key)) {
         // TODO
         if (mDropboxHelper == null) {
           mDropboxHelper = new DropboxSyncHelper(getActivity());
         }
         if (prefs.getBoolean(key, false)) {
           // authorize the user
           mDropboxHelper.linkAccount();
           //                        DropboxSynchronizer.linkAccount(this,
           //                                DROPBOX_LINK_CODE);
         } else {
           mDropboxHelper.unlinkAccount();
           //                        DropboxSynchronizer.unlink(getActivity());
         }
         // Restart sync service
         OrgSyncService.stop(getActivity());
       } else if (KEY_DROPBOX_DIR.equals(key)) {
         setDropboxDirSummary(prefs);
       }
     }
   } catch (IllegalStateException e) {
     // This is just in case the "isFinishing" wouldn't be enough
     // The isFinishing will try to prevent us from doing something
     // stupid
     // This catch prevents the app from crashing if we do something
     // stupid
   }
 }
Exemplo n.º 2
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   OrgSyncService.stop(this);
   try {
     if (mBillingHelper != null) mBillingHelper.dispose();
   } catch (Exception e) {
     // We are destroying, ignore all errors at this point
   }
   mBillingHelper = null;
 }
Exemplo n.º 3
0
 @Override
 public void onPause() {
   super.onPause();
   // deactivate monitor
   if (syncStatusReceiver != null) {
     syncStatusReceiver.stopMonitoring();
   }
   // deactivate any progress bar
   if (pullToRefreshAttacher != null) {
     pullToRefreshAttacher.setRefreshComplete();
   }
   // Pause sync monitors
   OrgSyncService.pause(this);
 }
Exemplo n.º 4
0
  private void handleSyncRequest() {
    boolean syncing = false;
    // GTasks
    if (SyncHelper.isGTasksConfigured(ActivityMain.this)) {
      syncing = true;
      SyncHelper.requestSyncIf(ActivityMain.this, SyncHelper.MANUAL);
    }

    // Others
    if (OrgSyncService.areAnyEnabled(this)) {
      syncing = true;
      OrgSyncService.start(this);
    }

    if (syncing) {
      // In case of connectivity problems, stop the progress bar
      new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
          try {
            Thread.sleep(30000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          return null;
        }

        @Override
        protected void onPostExecute(Void result) {
          // Notify PullToRefreshAttacher that the refresh has finished
          pullToRefreshAttacher.setRefreshComplete();
        }
      }.execute();
    }
  }
Exemplo n.º 5
0
  @Override
  public void onResume() {
    if (shouldRestart) {
      restartAndRefresh();
    }
    super.onResume();
    // activate monitor
    if (syncStatusReceiver != null) {
      syncStatusReceiver.startMonitoring(this);
    }

    // Sync if appropriate
    if (SyncHelper.enoughTimeSinceLastSync(this)) {
      SyncHelper.requestSyncIf(this, SyncHelper.ONAPPSTART);
      OrgSyncService.start(this);
    }

    // Check any upgrades
    checkPremium();
  }