1212package com .owncloud .android .ui .fragment .util ;
1313
1414import android .content .Context ;
15- import android .content .res .Resources ;
1615import android .view .MenuItem ;
1716
1817import com .owncloud .android .R ;
1918import com .owncloud .android .lib .resources .shares .OCShare ;
2019
21- import java .text .SimpleDateFormat ;
22- import java .util .Date ;
23-
2420import static com .owncloud .android .lib .resources .shares .OCShare .CREATE_PERMISSION_FLAG ;
21+ import static com .owncloud .android .lib .resources .shares .OCShare .DELETE_PERMISSION_FLAG ;
2522import static com .owncloud .android .lib .resources .shares .OCShare .MAXIMUM_PERMISSIONS_FOR_FILE ;
2623import static com .owncloud .android .lib .resources .shares .OCShare .MAXIMUM_PERMISSIONS_FOR_FOLDER ;
2724import static com .owncloud .android .lib .resources .shares .OCShare .NO_PERMISSION ;
2825import static com .owncloud .android .lib .resources .shares .OCShare .READ_PERMISSION_FLAG ;
2926import static com .owncloud .android .lib .resources .shares .OCShare .SHARE_PERMISSION_FLAG ;
27+ import static com .owncloud .android .lib .resources .shares .OCShare .UPDATE_PERMISSION_FLAG ;
3028
3129/**
3230 * Helper calls for visibility logic of the sharing menu.
@@ -53,38 +51,6 @@ public static void setupHideFileDownload(MenuItem menuItem,
5351 }
5452 }
5553
56- /**
57- * sets up the password {@link MenuItem}'s title based on the fact if a password is present.
58- *
59- * @param password the password {@link MenuItem}
60- * @param isPasswordProtected flag is a password is present
61- */
62- public static void setupPasswordMenuItem (MenuItem password , boolean isPasswordProtected ) {
63- if (isPasswordProtected ) {
64- password .setTitle (R .string .share_password_title );
65- } else {
66- password .setTitle (R .string .share_no_password_title );
67- }
68- }
69-
70- /**
71- * sets up the expiration date {@link MenuItem}'s title based on the fact if an expiration date is present.
72- *
73- * @param expirationDate the expiration date {@link MenuItem}
74- * @param expirationDateValue the expiration date
75- * @param res Resources to load the corresponding strings.
76- */
77- public static void setupExpirationDateMenuItem (MenuItem expirationDate , long expirationDateValue , Resources res ) {
78- if (expirationDateValue > 0 ) {
79- expirationDate .setTitle (res .getString (
80- R .string .share_expiration_date_label ,
81- SimpleDateFormat .getDateInstance ().format (new Date (expirationDateValue ))
82- ));
83- } else {
84- expirationDate .setTitle (R .string .share_no_expiration_date_label );
85- }
86- }
87-
8854 public static boolean isUploadAndEditingAllowed (OCShare share ) {
8955 if (share .getPermissions () == NO_PERMISSION ) {
9056 return false ;
@@ -119,6 +85,30 @@ public static boolean isSecureFileDrop(OCShare share) {
11985 return (share .getPermissions () & ~SHARE_PERMISSION_FLAG ) == CREATE_PERMISSION_FLAG + READ_PERMISSION_FLAG ;
12086 }
12187
88+ public static boolean isCreatePermission (OCShare share ) {
89+ if (share .getPermissions () == NO_PERMISSION ) {
90+ return false ;
91+ }
92+
93+ return (share .getPermissions () & ~SHARE_PERMISSION_FLAG ) == CREATE_PERMISSION_FLAG ;
94+ }
95+
96+ public static boolean isUpdatePermission (OCShare share ) {
97+ if (share .getPermissions () == NO_PERMISSION ) {
98+ return false ;
99+ }
100+
101+ return (share .getPermissions () & ~SHARE_PERMISSION_FLAG ) == UPDATE_PERMISSION_FLAG ;
102+ }
103+
104+ public static boolean isDeletePermission (OCShare share ) {
105+ if (share .getPermissions () == NO_PERMISSION ) {
106+ return false ;
107+ }
108+
109+ return (share .getPermissions () & ~SHARE_PERMISSION_FLAG ) == DELETE_PERMISSION_FLAG ;
110+ }
111+
122112 public static String getPermissionName (Context context , OCShare share ) {
123113 if (SharingMenuHelper .isUploadAndEditingAllowed (share )) {
124114 return context .getResources ().getString (R .string .share_permission_can_edit );
@@ -147,6 +137,14 @@ public static int getPermissionCheckedItem(Context context, OCShare share, Strin
147137 return getPermissionIndexFromArray (context , permissionArray , R .string .link_share_view_only );
148138 } else if (SharingMenuHelper .isFileDrop (share )) {
149139 return getPermissionIndexFromArray (context , permissionArray , R .string .link_share_file_drop );
140+ } else if (SharingMenuHelper .isCreatePermission (share )) {
141+ return getPermissionIndexFromArray (context , permissionArray , R .string .share_create_permission );
142+ } else if (SharingMenuHelper .isUpdatePermission (share )) {
143+ return getPermissionIndexFromArray (context , permissionArray , R .string .share_edit_permission );
144+ } else if (SharingMenuHelper .isDeletePermission (share )) {
145+ return getPermissionIndexFromArray (context , permissionArray , R .string .share_delete_permission );
146+ } else if (SharingMenuHelper .canReshare (share )) {
147+ return getPermissionIndexFromArray (context , permissionArray , R .string .share_re_share_permission );
150148 }
151149 return 0 ;//default first item selected
152150 }
0 commit comments