浏览代码

cancel specific backup job
disable daily backup on remove

tobiasKaminsky 8 年之前
父节点
当前提交
02411467b8

+ 16 - 2
src/main/java/com/owncloud/android/ui/activity/ContactsPreferenceActivity.java

@@ -106,8 +106,8 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
                 .schedule();
     }
 
-    public static void cancelContactBackupJob(Context context) {
-        Log_OC.d(TAG, "disabling contacts backup job");
+    public static void cancelAllContactBackupJobs(Context context) {
+        Log_OC.d(TAG, "disabling all contacts backup job");
 
         JobManager jobManager = JobManager.create(context);
         Set<JobRequest> jobs = jobManager.getAllJobRequestsForTag(ContactsBackupJob.TAG);
@@ -117,6 +117,20 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
         }
     }
 
+    public static void cancelContactBackupJobForAccount(Context context, Account account) {
+        Log_OC.d(TAG, "disabling contacts backup job for account: " + account.name);
+
+        JobManager jobManager = JobManager.create(context);
+        Set<JobRequest> jobs = jobManager.getAllJobRequestsForTag(ContactsBackupJob.TAG);
+
+        for (JobRequest jobRequest : jobs) {
+            PersistableBundleCompat extras = jobRequest.getExtras();
+            if (extras.getString(ContactsBackupJob.ACCOUNT, "").equalsIgnoreCase(account.name)) {
+                jobManager.cancel(jobRequest.getJobId());
+            }
+        }
+    }
+
 
     @Override
     public void showFiles(boolean onDeviceOnly) {

+ 2 - 1
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -1197,7 +1197,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
 
                     Account account = AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this);
 
-                    if (account != null && getStorageManager().getCapability(account.name) != null &&
+                    if (account != null && getStorageManager() != null &&
+                            getStorageManager().getCapability(account.name) != null &&
                             getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
 
                         int count = sharedPreferences.getInt(EXTERNAL_LINKS_COUNT, -1);

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/FileActivity.java

@@ -250,7 +250,7 @@ public abstract class FileActivity extends DrawerActivity
         if (sharedPreferences.getBoolean(ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP, false)) {
             ContactsPreferenceActivity.startContactBackupJob(getAccount());
         } else {
-            ContactsPreferenceActivity.cancelContactBackupJob(getBaseContext());
+            ContactsPreferenceActivity.cancelAllContactBackupJobs(getBaseContext());
         }
     }
 

+ 17 - 4
src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -31,6 +31,7 @@ import android.app.DialogFragment;
 import android.app.FragmentManager;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
@@ -50,6 +51,7 @@ import android.widget.TextView;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AuthenticatorActivity;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.lib.common.UserInfo;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -337,11 +339,22 @@ public class UserInfoActivity extends FileActivity {
                             new DialogInterface.OnClickListener() {
                                 @Override
                                 public void onClick(DialogInterface dialogInterface, int i) {
-                                    Bundle bundle = new Bundle();
-                                    bundle.putParcelable(KEY_ACCOUNT, Parcels.wrap(account));
-                                    Intent intent = new Intent();
-                                    intent.putExtras(bundle);
+                                    // remove contact backup job
+                                    ContactsPreferenceActivity.cancelContactBackupJobForAccount(getActivity(), account);
+
+                                    // disable daily backup
+                                    SharedPreferences sharedPreferences = PreferenceManager
+                                            .getDefaultSharedPreferences(getActivity());
+                                    SharedPreferences.Editor editor = sharedPreferences.edit();
+                                    editor.putBoolean(ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP,
+                                            false);
+                                    editor.apply();
+
                                     if (getActivity() != null && !removeDirectly) {
+                                        Bundle bundle = new Bundle();
+                                        bundle.putParcelable(KEY_ACCOUNT, Parcels.wrap(account));
+                                        Intent intent = new Intent();
+                                        intent.putExtras(bundle);
                                         getActivity().setResult(KEY_DELETE_CODE, intent);
                                         getActivity().finish();
                                     } else {

+ 1 - 1
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java

@@ -267,7 +267,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
         if (bool) {
         ContactsPreferenceActivity.startContactBackupJob(contactsPreferenceActivity.getAccount());
         } else {
-            ContactsPreferenceActivity.cancelContactBackupJob(contactsPreferenceActivity);
+            ContactsPreferenceActivity.cancelAllContactBackupJobs(contactsPreferenceActivity);
         }
 
         SharedPreferences.Editor editor = sharedPreferences.edit();