Browse Source

Reset state of check boxes if update of privileges fails

David A. Velasco 9 years ago
parent
commit
bba66e773d

+ 3 - 2
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -74,6 +74,7 @@ import com.owncloud.android.operations.GetSharesForFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.operations.SynchronizeFolderOperation;
 import com.owncloud.android.operations.UnshareOperation;
+import com.owncloud.android.operations.UpdateSharePermissionsOperation;
 import com.owncloud.android.operations.UpdateShareViaLinkOperation;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
@@ -104,7 +105,6 @@ public class FileActivity extends AppCompatActivity
 
     private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
     private static final String DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD";
-    private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
     private static final String KEY_ACTION_BAR_TITLE = "ACTION_BAR_TITLE";
 
     protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200;
@@ -753,7 +753,8 @@ public class FileActivity extends AppCompatActivity
                 operation instanceof CreateShareWithShareeOperation ||
                 operation instanceof UnshareOperation ||
                 operation instanceof SynchronizeFolderOperation ||
-                operation instanceof UpdateShareViaLinkOperation
+                operation instanceof UpdateShareViaLinkOperation ||
+                operation instanceof UpdateSharePermissionsOperation
                 ) {
             if (result.isSuccess()) {
                 updateFileFromDB();

+ 6 - 0
src/com/owncloud/android/ui/activity/ShareActivity.java

@@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.CreateShareViaLinkOperation;
 import com.owncloud.android.operations.GetSharesForFileOperation;
 import com.owncloud.android.operations.UnshareOperation;
+import com.owncloud.android.operations.UpdateSharePermissionsOperation;
 import com.owncloud.android.providers.UsersAndGroupsSearchProvider;
 
 import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -201,6 +202,10 @@ public class ShareActivity extends FileActivity
         if (operation instanceof UnshareOperation && result.isSuccess() && getEditShareFragment() != null) {
             getSupportFragmentManager().popBackStack();
         }
+
+        if (operation instanceof UpdateSharePermissionsOperation && getEditShareFragment() != null) {
+            getEditShareFragment().onUpdateSharePermissionsFinished(result);
+        }
     }
 
 
@@ -222,6 +227,7 @@ public class ShareActivity extends FileActivity
                 searchShareesFragment.isAdded()) {  // only if added to the view hierarchy!!
             searchShareesFragment.refreshUsersOrGroupsListFromDB();
         }
+
     }
 
     /**

+ 37 - 6
src/com/owncloud/android/ui/fragment/EditShareFragment.java

@@ -33,6 +33,7 @@ import android.widget.TextView;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder;
@@ -142,13 +143,19 @@ public class EditShareFragment extends Fragment {
      * @param editShareView     Root view in the fragment.
      */
     private void initPrivileges(View editShareView) {
-        mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
+        boolean setListener = false;
+        if (mOnPrivilegeChangeListener == null) {
+            mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
+            setListener = true;
+        }
         int sharePermissions = mShare.getPermissions();
         CheckBox checkBox;
 
         checkBox = (CheckBox) editShareView.findViewById(R.id.canShareCheckBox);
         checkBox.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);
-        checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+        if (setListener) {
+            checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+        }
 
         checkBox = (CheckBox) editShareView.findViewById(R.id.canEditCheckBox);
         int anyUpdatePermission =
@@ -158,7 +165,9 @@ public class EditShareFragment extends Fragment {
                 ;
         boolean canEdit = (sharePermissions & anyUpdatePermission) > 0;
         checkBox.setChecked(canEdit);
-        checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+        if (setListener) {
+            checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+        }
 
         if (mFile.isFolder()) {
             checkBox = (CheckBox) editShareView.findViewById(R.id.canEditCreateCheckBox);
@@ -166,26 +175,48 @@ public class EditShareFragment extends Fragment {
                 checkBox.setVisibility(View.VISIBLE);
                 checkBox.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0);
             }
-            checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            if (setListener) {
+                checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            }
 
             checkBox = (CheckBox) editShareView.findViewById(R.id.canEditChangeCheckBox);
             if (canEdit) {
                 checkBox.setVisibility(View.VISIBLE);
                 checkBox.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0);
             }
-            checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            if (setListener) {
+                checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            }
 
             checkBox = (CheckBox) editShareView.findViewById(R.id.canEditDeleteCheckBox);
             if (canEdit) {
                 checkBox.setVisibility(View.VISIBLE);
                 checkBox.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0);
             }
-            checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            if (setListener) {
+                checkBox.setOnCheckedChangeListener(mOnPrivilegeChangeListener);
+            }
 
         }   // else, trust in visibility GONE in R.layout.edit_share_layout
 
     }
 
+    /**
+     * Called when an operation to update share permissions finished.
+     * s
+     * @param result        Result of the update operation
+     */
+    public void onUpdateSharePermissionsFinished(RemoteOperationResult result) {
+        if (result.isSuccess()) {
+            getFragmentManager().popBackStack();
+
+        } else {
+            if (getView() != null) {
+                initPrivileges(getView());
+            }
+        }
+    }
+
 
     /**
      * Listener for user actions that enable or disable a privilege