Browse Source

Added buttons to unshare (working) and finish (not working) in EditShareFragment layout

David A. Velasco 9 years ago
parent
commit
d826451e2d

+ 29 - 0
res/layout/edit_share_layout.xml

@@ -42,4 +42,33 @@
         android:visibility="gone"
         />
 
+    <!-- ImageView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/unshareButton"
+        android:src="@drawable/ic_cancel"
+        android:layout_gravity="center_horizontal"
+        /-->
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/unshareButton"
+        style="@style/ownCloud.Button"
+        android:drawableRight="@drawable/ic_cancel"
+        android:drawableEnd="@drawable/ic_cancel"
+        android:text="@string/edit_share_unshare"
+        android:layout_gravity="center_horizontal"
+        />
+
+    <android.support.v7.widget.AppCompatButton
+        android:id="@+id/doneButton"
+        style="@style/ownCloud.Button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
+        android:text="@string/edit_share_done"
+        android:contentDescription="@string/edit_share_done"
+        />
+
 </LinearLayout>

+ 2 - 0
res/values/strings.xml

@@ -399,6 +399,8 @@
     <string name="share_privilege_can_edit_create">create</string>
     <string name="share_privilege_can_edit_change">change</string>
     <string name="share_privilege_can_edit_delete">delete</string>
+    <string name="edit_share_unshare">Stop sharing</string>
+    <string name="edit_share_done">done</string>
 
     <string name="action_switch_grid_view">Switch to grid view</string>
     <string name="action_switch_list_view">Switch to list view</string>

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

@@ -33,6 +33,7 @@ import com.owncloud.android.R;
 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.providers.UsersAndGroupsSearchProvider;
 
 import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -197,6 +198,9 @@ public class ShareActivity extends FileActivity
             chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
         }
 
+        if (operation instanceof UnshareOperation && result.isSuccess() && getEditShareFragment() != null) {
+            getSupportFragmentManager().popBackStack();
+        }
     }
 
 
@@ -238,4 +242,13 @@ public class ShareActivity extends FileActivity
         return (SearchShareesFragment) getSupportFragmentManager().findFragmentByTag(TAG_SEARCH_FRAGMENT);
     }
 
+    /**
+     * Shortcut to get access to the {@link EditShareFragment} instance, if any
+     *
+     * @return  A {@link EditShareFragment} instance, or null
+     */
+    private EditShareFragment getEditShareFragment() {
+        return (EditShareFragment) getSupportFragmentManager().findFragmentByTag(TAG_EDIT_SHARE_FRAGMENT);
+    }
+
 }

+ 46 - 1
src/com/owncloud/android/ui/fragment/EditShareFragment.java

@@ -27,13 +27,19 @@ import android.support.v4.app.Fragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.CompoundButton;
+import android.widget.TextView;
+import android.widget.Toast;
 
 import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.resources.shares.ShareType;
+import com.owncloud.android.ui.activity.FileActivity;
 
 public class EditShareFragment extends Fragment {
 
@@ -117,11 +123,12 @@ public class EditShareFragment extends Fragment {
 
         // Setup layout
         initPrivileges(view);
+        initUnshareButton(view);
+        initDoneButton(view);
 
         return view;
     }
 
-
     /**
      * Binds listener for user actions to enable or disable a privilege on the edited share
      * to the views receiving the user events.
@@ -311,6 +318,44 @@ public class EditShareFragment extends Fragment {
     }
 
 
+    /**
+     * Binds listener for user interactions on the 'unshare' button with the button itself.
+     *
+     * @param editShareView     Root view in the fragment.
+     */
+    private void initUnshareButton(View editShareView) {
+        TextView unshareButton  = (TextView) editShareView.findViewById(R.id.unshareButton);
+        unshareButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ((FileActivity) getActivity()).getFileOperationsHelper().
+                        unshareFileWithUserOrGroup(
+                                mFile,
+                                mShare.getShareType(),
+                                mShare.getShareWith()
+                        )
+                ;
+            }
+        });
+    }
+
+
+    /**
+     * Binds listener for user interactions on the 'done' button with the button itself.
+     *
+     * @param editShareView     Root view in the fragment.
+     */
+    private void initDoneButton(View editShareView) {
+        TextView doneButton  = (TextView) editShareView.findViewById(R.id.doneButton);
+        doneButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Toast.makeText(getActivity(), "TODO - update permissions in server", Toast.LENGTH_LONG).show();
+            }
+        });
+    }
+
+
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);