|
@@ -23,7 +23,6 @@
|
|
|
|
|
|
package com.owncloud.android.ui.fragment;
|
|
|
|
|
|
-import android.accounts.Account;
|
|
|
import android.accounts.AccountManager;
|
|
|
import android.app.SearchManager;
|
|
|
import android.content.Context;
|
|
@@ -40,7 +39,6 @@ import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
-import android.widget.PopupMenu;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
@@ -58,6 +56,8 @@ import com.owncloud.android.lib.resources.shares.ShareType;
|
|
|
import com.owncloud.android.lib.resources.status.OCCapability;
|
|
|
import com.owncloud.android.ui.activity.FileActivity;
|
|
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
|
|
+import com.owncloud.android.ui.adapter.PublicShareInterface;
|
|
|
+import com.owncloud.android.ui.adapter.PublicShareListAdapter;
|
|
|
import com.owncloud.android.ui.adapter.ShareeListAdapter;
|
|
|
import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
|
|
|
import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
|
|
@@ -76,7 +76,7 @@ import javax.inject.Inject;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
-import androidx.appcompat.widget.AppCompatCheckBox;
|
|
|
+import androidx.appcompat.widget.PopupMenu;
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
@@ -87,18 +87,17 @@ import butterknife.OnClick;
|
|
|
import butterknife.Unbinder;
|
|
|
|
|
|
public class FileDetailSharingFragment extends Fragment implements ShareeListAdapter.ShareeListAdapterListener,
|
|
|
- DisplayUtils.AvatarGenerationListener, Injectable {
|
|
|
+ DisplayUtils.AvatarGenerationListener,
|
|
|
+ PublicShareInterface,
|
|
|
+ Injectable {
|
|
|
|
|
|
private static final String ARG_FILE = "FILE";
|
|
|
private static final String ARG_USER = "USER";
|
|
|
-
|
|
|
- // to show share with users/groups info
|
|
|
- private List<OCShare> shares;
|
|
|
+ public static final int PERMISSION_EDITING_ALLOWED = 17;
|
|
|
|
|
|
private OCFile file;
|
|
|
private User user;
|
|
|
private OCCapability capabilities;
|
|
|
- private OCShare publicShare;
|
|
|
|
|
|
private FileOperationsHelper fileOperationsHelper;
|
|
|
private FileActivity fileActivity;
|
|
@@ -112,20 +111,11 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
@BindView(R.id.shareUsersList)
|
|
|
RecyclerView usersList;
|
|
|
|
|
|
- @BindView(R.id.share_by_link)
|
|
|
- AppCompatCheckBox shareByLink;
|
|
|
-
|
|
|
- @BindView(R.id.share_link_copy_icon)
|
|
|
- ImageView shareLinkCopyIcon;
|
|
|
-
|
|
|
- @BindView(R.id.overflow_menu_share_link)
|
|
|
- ImageView overflowMenuShareLink;
|
|
|
-
|
|
|
- @BindView(R.id.share_by_link_allow_editing)
|
|
|
- AppCompatCheckBox shareByLinkAllowEditing;
|
|
|
+ @BindView(R.id.publicShareList)
|
|
|
+ RecyclerView publicShareList;
|
|
|
|
|
|
- @BindView(R.id.share_by_link_container)
|
|
|
- LinearLayout shareByLinkContainer;
|
|
|
+ @BindView(R.id.new_public_share)
|
|
|
+ View addPublicShare;
|
|
|
|
|
|
@BindView(R.id.shared_with_you_container)
|
|
|
LinearLayout sharedWithYouContainer;
|
|
@@ -245,13 +235,11 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
ThemeUtils.themeSearchView(searchView, requireContext());
|
|
|
|
|
|
if (file.canReshare()) {
|
|
|
- setShareByLinkInfo(file.isSharedViaLink());
|
|
|
setShareWithUserInfo();
|
|
|
} else {
|
|
|
searchView.setQueryHint(getResources().getString(R.string.reshare_not_allowed));
|
|
|
searchView.setInputType(InputType.TYPE_NULL);
|
|
|
disableSearchView(searchView);
|
|
|
- shareByLinkContainer.setVisibility(View.GONE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -267,45 +255,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Updates Share by link UI
|
|
|
- *
|
|
|
- * @param isShareByLink flag is share by link is enable
|
|
|
- */
|
|
|
- public void setShareByLinkInfo(boolean isShareByLink) {
|
|
|
- shareByLink.setChecked(isShareByLink);
|
|
|
- if (isShareByLink) {
|
|
|
- shareLinkCopyIcon.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- shareLinkCopyIcon.setVisibility(View.INVISIBLE);
|
|
|
- }
|
|
|
- int accentColor = ThemeUtils.primaryAccentColor(getContext());
|
|
|
- ThemeUtils.tintCheckbox(shareByLink, accentColor);
|
|
|
- ThemeUtils.tintCheckbox(shareByLinkAllowEditing, accentColor);
|
|
|
- setLinkDetailVisible(isShareByLink);
|
|
|
- }
|
|
|
-
|
|
|
- private void setLinkDetailVisible(boolean visible) {
|
|
|
- if (visible) {
|
|
|
- shareByLinkAllowEditing.setVisibility(View.VISIBLE);
|
|
|
- overflowMenuShareLink.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- shareByLinkAllowEditing.setVisibility(View.INVISIBLE);
|
|
|
- overflowMenuShareLink.setVisibility(View.INVISIBLE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Update Share With data
|
|
|
- */
|
|
|
- public void setShareWithUserInfo() {
|
|
|
- // Get Users and Groups
|
|
|
- shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), user.getAccountName());
|
|
|
-
|
|
|
- // Update list of users/groups
|
|
|
- updateListOfUserGroups();
|
|
|
- }
|
|
|
-
|
|
|
private void setShareWithYou() {
|
|
|
if (accountManager.userOwnsFile(file, user)) {
|
|
|
sharedWithYouContainer.setVisibility(View.GONE);
|
|
@@ -328,9 +277,11 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void updateListOfUserGroups() {
|
|
|
+ private void setShareWithUserInfo() {
|
|
|
// TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
|
|
|
-
|
|
|
+ // to show share with users/groups info
|
|
|
+ List<OCShare> shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(),
|
|
|
+ user.toPlatformAccount().name);
|
|
|
if (shares.size() > 0) {
|
|
|
AccountManager accountManager = AccountManager.get(getContext());
|
|
|
String userId = accountManager.getUserData(user.toPlatformAccount(),
|
|
@@ -351,15 +302,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @OnClick(R.id.share_by_link)
|
|
|
- public void toggleShareByLink() {
|
|
|
- if (shareByLink.isChecked()) {
|
|
|
- createShareLink();
|
|
|
- } else {
|
|
|
- fileOperationsHelper.unshareFileViaLink(file);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@OnClick(R.id.copy_internal_container)
|
|
|
public void copyInternalLink() {
|
|
|
OwnCloudAccount account = accountManager.getCurrentOwnCloudAccount();
|
|
@@ -399,8 +341,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @OnClick({R.id.share_link_copy_icon})
|
|
|
- public void copyLinkToClipboard() {
|
|
|
+ public void copyLink(OCShare share) {
|
|
|
if (file.isSharedViaLink()) {
|
|
|
if (TextUtils.isEmpty(file.getPublicLink())) {
|
|
|
fileOperationsHelper.getFileWithLink(file);
|
|
@@ -410,55 +351,55 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @OnClick(R.id.share_by_link_allow_editing)
|
|
|
- public void toggleShareLinkAllowEditing() {
|
|
|
- if (file.isSharedViaLink()) {
|
|
|
- fileOperationsHelper.setUploadPermissionsToShare(file, shareByLinkAllowEditing.isChecked());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @OnClick(R.id.overflow_menu_share_link)
|
|
|
- public void showLinkOverflowMenu() {
|
|
|
- Context context = getContext();
|
|
|
- if (context != null && ThemeUtils.themingEnabled(context)) {
|
|
|
+ public void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink) {
|
|
|
+ if (ThemeUtils.themingEnabled(requireContext())) {
|
|
|
// use grey as fallback for elements where custom theming is not available
|
|
|
- context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
|
|
|
- } else {
|
|
|
- context = getActivity();
|
|
|
+ requireContext().getTheme().applyStyle(R.style.FallbackThemingTheme, true);
|
|
|
}
|
|
|
|
|
|
- PopupMenu popup = new PopupMenu(context, overflowMenuShareLink);
|
|
|
+ PopupMenu popup = new PopupMenu(requireContext(), overflowMenuShareLink);
|
|
|
popup.inflate(R.menu.fragment_file_detail_sharing_link);
|
|
|
- prepareOptionsMenu(popup.getMenu());
|
|
|
- popup.setOnMenuItemClickListener(this::optionsItemSelected);
|
|
|
+ prepareOptionsMenu(popup.getMenu(), publicShare);
|
|
|
+ popup.setOnMenuItemClickListener(menuItem -> optionsItemSelected(menuItem, publicShare));
|
|
|
popup.show();
|
|
|
}
|
|
|
|
|
|
- private void prepareOptionsMenu(Menu menu) {
|
|
|
- Resources res = getResources();
|
|
|
- SharingMenuHelper.setupHideFileListingMenuItem(
|
|
|
- menu.findItem(R.id.action_hide_file_listing),
|
|
|
- file.isFolder(),
|
|
|
- shareByLinkAllowEditing.isChecked(),
|
|
|
- publicShare.getPermissions()
|
|
|
- );
|
|
|
+ private void prepareOptionsMenu(Menu menu, OCShare publicShare) {
|
|
|
+ Resources res = requireContext().getResources();
|
|
|
+ SharingMenuHelper.setupHideFileListingMenuItem(menu.findItem(R.id.action_hide_file_listing),
|
|
|
+ file.isFolder(),
|
|
|
+ menu.findItem(R.id.action_allow_editing).isChecked(),
|
|
|
+ publicShare.getPermissions());
|
|
|
+
|
|
|
SharingMenuHelper.setupHideFileDownload(menu.findItem(R.id.action_hide_file_download),
|
|
|
- publicShare.isHideFileDownload(), capabilities);
|
|
|
- SharingMenuHelper.setupPasswordMenuItem(
|
|
|
- menu.findItem(R.id.action_password),
|
|
|
- publicShare.isPasswordProtected()
|
|
|
- );
|
|
|
- SharingMenuHelper.setupExpirationDateMenuItem(
|
|
|
- menu.findItem(R.id.action_share_expiration_date),
|
|
|
- publicShare.getExpirationDate(),
|
|
|
- res
|
|
|
- );
|
|
|
+ publicShare.isHideFileDownload(),
|
|
|
+ capabilities);
|
|
|
+
|
|
|
+ SharingMenuHelper.setupPasswordMenuItem(menu.findItem(R.id.action_password),
|
|
|
+ publicShare.isPasswordProtected());
|
|
|
+
|
|
|
+ SharingMenuHelper.setupExpirationDateMenuItem(menu.findItem(R.id.action_share_expiration_date),
|
|
|
+ publicShare.getExpirationDate(),
|
|
|
+ res);
|
|
|
|
|
|
menu.findItem(R.id.action_share_send_note).setVisible(capabilities.getVersion().isNoteOnShareSupported());
|
|
|
+
|
|
|
+ if (publicShare.getPermissions() > PERMISSION_EDITING_ALLOWED) {
|
|
|
+ menu.findItem(R.id.action_allow_editing).setChecked(true);
|
|
|
+ } else {
|
|
|
+ menu.findItem(R.id.action_allow_editing).setChecked(false);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private boolean optionsItemSelected(MenuItem item) {
|
|
|
+ public boolean optionsItemSelected(MenuItem item, OCShare publicShare) {
|
|
|
switch (item.getItemId()) {
|
|
|
+ case R.id.action_allow_editing:
|
|
|
+ if (file.isSharedViaLink()) {
|
|
|
+ item.setChecked(!item.isChecked());
|
|
|
+ fileOperationsHelper.setUploadPermissionsToShare(file,
|
|
|
+ item.isChecked());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
case R.id.action_hide_file_listing: {
|
|
|
item.setChecked(!item.isChecked());
|
|
|
if (capabilities.getFilesFileDrop().isTrue()) {
|
|
@@ -482,14 +423,12 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
case R.id.action_share_expiration_date: {
|
|
|
ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment
|
|
|
.newInstance(file, publicShare.getExpirationDate());
|
|
|
- dialog.show(
|
|
|
- fileActivity.getSupportFragmentManager(),
|
|
|
- ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG
|
|
|
- );
|
|
|
+ dialog.show(fileActivity.getSupportFragmentManager(),
|
|
|
+ ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG);
|
|
|
return true;
|
|
|
}
|
|
|
case R.id.action_share_send_link: {
|
|
|
- if(shareByLink.isChecked() && file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) {
|
|
|
+ if (file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) {
|
|
|
FileDisplayActivity.showShareLinkDialog(fileActivity, file, file.getPublicLink());
|
|
|
} else {
|
|
|
showSendLinkTo();
|
|
@@ -500,6 +439,12 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
NoteDialogFragment dialog = NoteDialogFragment.newInstance(publicShare);
|
|
|
dialog.show(fileActivity.getSupportFragmentManager(), NoteDialogFragment.NOTE_FRAGMENT);
|
|
|
return true;
|
|
|
+ case R.id.action_add_another_public_share_link:
|
|
|
+ createShareLink();
|
|
|
+ return true;
|
|
|
+ case R.id.action_unshare:
|
|
|
+ fileOperationsHelper.unshareShare(file, publicShare);
|
|
|
+ return true;
|
|
|
default:
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
@@ -545,30 +490,29 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
* Get {@link OCShare} instance from DB and updates the UI.
|
|
|
*/
|
|
|
private void refreshUiFromDB() {
|
|
|
- if (publicShare != null) {
|
|
|
- // Get edited shared by link
|
|
|
- publicShare = fileDataStorageManager.getShareById(publicShare.getId());
|
|
|
- }
|
|
|
-
|
|
|
// Updates UI with new state
|
|
|
setupView();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void unshareWith(OCShare share) {
|
|
|
- fileOperationsHelper.unshareFileWithUserOrGroup(file, share.getShareType(), share.getShareWith());
|
|
|
+ fileOperationsHelper.unshareShare(file, share);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int updatePermissionsToShare(OCShare share, boolean canReshare, boolean canEdit, boolean canEditCreate,
|
|
|
- boolean canEditChange, boolean canEditDelete) {
|
|
|
+ public int updatePermissionsToShare(OCShare share,
|
|
|
+ boolean canReshare,
|
|
|
+ boolean canEdit,
|
|
|
+ boolean canEditCreate,
|
|
|
+ boolean canEditChange,
|
|
|
+ boolean canEditDelete) {
|
|
|
SharePermissionsBuilder spb = new SharePermissionsBuilder();
|
|
|
spb.setSharePermission(canReshare);
|
|
|
|
|
|
if (file.isFolder()) {
|
|
|
spb.setUpdatePermission(canEditChange)
|
|
|
- .setCreatePermission(canEditCreate)
|
|
|
- .setDeletePermission(canEditDelete);
|
|
|
+ .setCreatePermission(canEditCreate)
|
|
|
+ .setDeletePermission(canEditDelete);
|
|
|
} else {
|
|
|
spb.setUpdatePermission(canEdit);
|
|
|
}
|
|
@@ -618,34 +562,32 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
|
|
|
*/
|
|
|
public void refreshPublicShareFromDB() {
|
|
|
if (FileDetailSharingFragmentHelper.isPublicShareDisabled(capabilities) || !file.canReshare()) {
|
|
|
- shareByLinkContainer.setVisibility(View.GONE);
|
|
|
- } else {
|
|
|
- // Get public share
|
|
|
- publicShare = fileDataStorageManager.getFirstShareByPathAndType(file.getRemotePath(),
|
|
|
- ShareType.PUBLIC_LINK, "");
|
|
|
-
|
|
|
- // Update public share section
|
|
|
- updatePublicShareSection();
|
|
|
+ publicShareList.setVisibility(View.GONE);
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Updates in the UI the section about public share with the information
|
|
|
- * in the current public share bound to, if any.
|
|
|
- */
|
|
|
- private void updatePublicShareSection() {
|
|
|
- if (publicShare != null && ShareType.PUBLIC_LINK.equals(publicShare.getShareType())) {
|
|
|
- shareByLink.setChecked(true);
|
|
|
-
|
|
|
- if (publicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) {
|
|
|
- shareByLinkAllowEditing.setChecked(true);
|
|
|
- } else {
|
|
|
- shareByLinkAllowEditing.setChecked(false);
|
|
|
- }
|
|
|
|
|
|
- setShareByLinkInfo(true);
|
|
|
+ // Get public share
|
|
|
+ List<OCShare> shares = fileDataStorageManager.getSharesByPathAndType(file.getRemotePath(),
|
|
|
+ ShareType.PUBLIC_LINK,
|
|
|
+ "");
|
|
|
+
|
|
|
+ if (shares.isEmpty()) {
|
|
|
+ addPublicShare.setVisibility(View.VISIBLE);
|
|
|
+ publicShareList.setVisibility(View.GONE);
|
|
|
+ ImageView icon = requireView().findViewById(R.id.copy_internal_link_icon);
|
|
|
+ icon.getBackground().setColorFilter(requireContext()
|
|
|
+ .getResources()
|
|
|
+ .getColor(R.color.primary_button_background_color),
|
|
|
+ PorterDuff.Mode.SRC_IN);
|
|
|
+ icon.getDrawable().mutate().setColorFilter(requireContext().getResources().getColor(R.color.black),
|
|
|
+ PorterDuff.Mode.SRC_IN);
|
|
|
+ requireView().findViewById(R.id.add_new_public_share_link).setOnClickListener(v -> createShareLink());
|
|
|
} else {
|
|
|
- setShareByLinkInfo(false);
|
|
|
+ addPublicShare.setVisibility(View.GONE);
|
|
|
+ publicShareList.setVisibility(View.VISIBLE);
|
|
|
+ publicShareList.setAdapter(new PublicShareListAdapter(getContext(), shares, this));
|
|
|
+ publicShareList.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
+ publicShareList.addItemDecoration(new SimpleListItemDividerDecoration(getContext()));
|
|
|
}
|
|
|
}
|
|
|
|