Skip to content

Commit

Permalink
Resert timestamps when disabling the feature + code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
davigonz committed Jan 10, 2018
1 parent 6278701 commit 8ff4438
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
52 changes: 48 additions & 4 deletions src/com/owncloud/android/files/services/CameraUploadsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CameraUploadsHandler {
private CameraUploadsConfiguration mCameraUploadsConfig; // Camera uploads configuration, set by the user
private Context mContext;

public CameraUploadsHandler(CameraUploadsConfiguration cameraUploadsConfiguration, Context context) {
public CameraUploadsHandler(Context context, CameraUploadsConfiguration cameraUploadsConfiguration) {
mCameraUploadsConfig = cameraUploadsConfiguration;
mContext = context;
}
Expand All @@ -55,9 +55,7 @@ public CameraUploadsHandler(CameraUploadsConfiguration cameraUploadsConfiguratio
*/
public void scheduleCameraUploadsSyncJob() {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
(mCameraUploadsConfig.isEnabledForPictures() || mCameraUploadsConfig.
isEnabledForVideos())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

// Initialize synchronization timestamps for pictures/videos, if needed
initializeCameraUploadSync();
Expand Down Expand Up @@ -153,6 +151,7 @@ private void initializeCameraUploadSync() {
return;
}


if (ocCameraUploadSync.getPicturesLastSync() == 0 && mCameraUploadsConfig.isEnabledForPictures()) {

// Pictures synchronization timestamp not initialized yet, initialize it
Expand All @@ -168,4 +167,49 @@ private void initializeCameraUploadSync() {
mCameraUploadsSyncStorageManager.updateCameraUploadSync(ocCameraUploadSync);
}
}

public void resetPicturesLastSync(){

// DB connection
CameraUploadsSyncStorageManager mCameraUploadsSyncStorageManager = new
CameraUploadsSyncStorageManager(mContext.getContentResolver());

OCCameraUploadSync ocCameraUploadSync = mCameraUploadsSyncStorageManager.
getCameraUploadSync(null, null, null);

if (ocCameraUploadSync == null) {

return;

} else {

ocCameraUploadSync.setPicturesLastSync(0);

mCameraUploadsSyncStorageManager.updateCameraUploadSync(ocCameraUploadSync);
}
}

public void resetVideosLastSync(){
// DB connection
CameraUploadsSyncStorageManager mCameraUploadsSyncStorageManager = new
CameraUploadsSyncStorageManager(mContext.getContentResolver());

OCCameraUploadSync ocCameraUploadSync = mCameraUploadsSyncStorageManager.
getCameraUploadSync(null, null, null);

if (ocCameraUploadSync == null) {

return;

} else {

ocCameraUploadSync.setVideosLastSync(0);

mCameraUploadsSyncStorageManager.updateCameraUploadSync(ocCameraUploadSync);
}
}

public void setCameraUploadsConfig(CameraUploadsConfiguration mCameraUploadsConfig) {
this.mCameraUploadsConfig = mCameraUploadsConfig;
}
}
17 changes: 15 additions & 2 deletions src/com/owncloud/android/ui/activity/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class Preferences extends PreferenceActivity {
private Preference mPrefCameraUploadsSourcePath;
private Preference mPrefCameraUploadsBehaviour;

private CameraUploadsHandler mCameraUploadsHandler;

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -405,6 +407,11 @@ public boolean onPreferenceClick(Preference preference) {
loadCameraUploadsPicturePath();
loadCameraUploadsVideoPath();
loadCameraUploadsSourcePath();

CameraUploadsConfiguration configuration = com.owncloud.android.db.PreferenceManager.
getCameraUploadsConfiguration(this);

mCameraUploadsHandler = new CameraUploadsHandler(this, configuration);
}

/**
Expand Down Expand Up @@ -433,9 +440,11 @@ public void onClick(DialogInterface dialog, int which) {
((CheckBoxPreference) mPrefCameraPictureUploads).setChecked(true);
mPrefCameraUploadsCategory.addPreference(mPrefCameraPictureUploadsWiFi);
mPrefCameraUploadsCategory.addPreference(mPrefCameraPictureUploadsPath);

} else if (which == DialogInterface.BUTTON_POSITIVE) {
mPrefCameraUploadsCategory.removePreference(mPrefCameraPictureUploadsWiFi);
mPrefCameraUploadsCategory.removePreference(mPrefCameraPictureUploadsPath);
mCameraUploadsHandler.resetPicturesLastSync();
}
dismissConfirmationDialog(builder);
}
Expand Down Expand Up @@ -475,6 +484,7 @@ public void onClick(DialogInterface dialog, int which) {
} else if (which == DialogInterface.BUTTON_POSITIVE) {
mPrefCameraUploadsCategory.removePreference(mPrefCameraVideoUploadsWiFi);
mPrefCameraUploadsCategory.removePreference(mPrefCameraVideoUploadsPath);
mCameraUploadsHandler.resetVideosLastSync();
}
dismissConfirmationDialog(builder);
}
Expand Down Expand Up @@ -657,9 +667,12 @@ protected void onStop() {
CameraUploadsConfiguration configuration = com.owncloud.android.db.PreferenceManager.
getCameraUploadsConfiguration(this);

CameraUploadsHandler cameraUploadsHandler = new CameraUploadsHandler(configuration, this);
if (configuration.isEnabledForPictures() || configuration.isEnabledForVideos()) {

cameraUploadsHandler.scheduleCameraUploadsSyncJob();
mCameraUploadsHandler.setCameraUploadsConfig(configuration);

mCameraUploadsHandler.scheduleCameraUploadsSyncJob();
}

super.onStop();
getDelegate().onStop();
Expand Down

0 comments on commit 8ff4438

Please sign in to comment.