From 8c9841f03374ec9ce2af53f2aa90ad65f4e8a82e Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 25 Jun 2020 12:10:27 +0200 Subject: [PATCH 1/7] add multiple share links Signed-off-by: tobiasKaminsky --- build.gradle | 2 +- .../datamodel/FileDataStorageManager.java | 16 +- .../com/owncloud/android/db/ProviderMeta.java | 3 +- .../CreateShareViaLinkOperation.java | 48 +--- .../android/operations/UnshareOperation.java | 47 ++-- .../UpdateShareViaLinkOperation.java | 14 +- .../providers/FileContentProvider.java | 21 +- .../android/services/OperationsService.java | 14 +- .../android/ui/activity/FileActivity.java | 1 + .../ui/adapter/PublicShareInterface.java | 33 +++ .../ui/adapter/PublicShareListAdapter.java | 68 +++++ .../ui/adapter/PublicShareViewHolder.java | 66 +++++ .../fragment/FileDetailSharingFragment.java | 235 +++++++----------- .../ui/helpers/FileOperationsHelper.java | 44 ++-- ...details_share_public_link_add_new_item.xml | 70 ++++++ .../file_details_share_public_link_item.xml | 82 ++++++ .../layout/file_details_sharing_fragment.xml | 67 +---- .../fragment_file_detail_sharing_link.xml | 22 +- src/main/res/values/strings.xml | 4 + 19 files changed, 529 insertions(+), 328 deletions(-) create mode 100644 src/main/java/com/owncloud/android/ui/adapter/PublicShareInterface.java create mode 100644 src/main/java/com/owncloud/android/ui/adapter/PublicShareListAdapter.java create mode 100644 src/main/java/com/owncloud/android/ui/adapter/PublicShareViewHolder.java create mode 100644 src/main/res/layout/file_details_share_public_link_add_new_item.xml create mode 100644 src/main/res/layout/file_details_share_public_link_item.xml diff --git a/build.gradle b/build.gradle index e9b36b1a6a1e..76cdb32b5850 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ ext { daggerVersion = "2.28.1" markwonVersion = "4.4.0" prismVersion = "2.0.0" - androidLibraryVersion = "master-SNAPSHOT" + androidLibraryVersion = "publicLink-SNAPSHOT" travisBuild = System.getenv("TRAVIS") == "true" diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 2748d92d408e..94b8f2df502a 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1195,9 +1195,9 @@ private Cursor getShareCursorForValue(String key, String value) { * @param path Path of the file. * @param type Type of the share to get * @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK} - * @return First {@link OCShare} instance found in DB bound to the file in 'path' + * @return All {@link OCShare} instance found in DB bound to the file in 'path' */ - public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) { + public List getSharesByPathAndType(String path, ShareType type, String shareWith) { Cursor cursor; if (shareWith == null) { shareWith = ""; @@ -1246,14 +1246,18 @@ public OCShare getFirstShareByPathAndType(String path, ShareType type, String sh } } - OCShare share = null; + List shares = new ArrayList<>(); + OCShare share; if (cursor != null) { if (cursor.moveToFirst()) { - share = createShareInstance(cursor); + do { + share = createShareInstance(cursor); + shares.add(share); + } while (cursor.moveToNext()); } cursor.close(); } - return share; + return shares; } // test with null cursor? @@ -1274,6 +1278,7 @@ private OCShare createShareInstance(Cursor cursor) { share.setPasswordProtected(getInt(cursor, ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED) == 1); share.setNote(getString(cursor, ProviderTableMeta.OCSHARES_NOTE)); share.setHideFileDownload(getInt(cursor, ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD) == 1); + share.setShareLink(getString(cursor, ProviderTableMeta.OCSHARES_SHARE_LINK)); return share; } @@ -1626,6 +1631,7 @@ private ArrayList prepareInsertShares( contentValues.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0); contentValues.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote()); contentValues.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, share.isHideFileDownload()); + contentValues.put(ProviderTableMeta.OCSHARES_SHARE_LINK, share.getShareLink()); // adding a new share resource operations.add(ContentProviderOperation diff --git a/src/main/java/com/owncloud/android/db/ProviderMeta.java b/src/main/java/com/owncloud/android/db/ProviderMeta.java index 25a54152b851..e473ffc40eef 100644 --- a/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -31,7 +31,7 @@ */ public class ProviderMeta { public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 57; + public static final int DB_VERSION = 58; private ProviderMeta() { // No instance @@ -145,6 +145,7 @@ static public class ProviderTableMeta implements BaseColumns { public static final String OCSHARES_IS_PASSWORD_PROTECTED = "is_password_protected"; public static final String OCSHARES_NOTE = "note"; public static final String OCSHARES_HIDE_DOWNLOAD = "hide_download"; + public static final String OCSHARES_SHARE_LINK = "share_link"; public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE + " collate nocase asc"; diff --git a/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java b/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java index b845a1eeecab..adf837063077 100644 --- a/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java +++ b/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java @@ -23,11 +23,9 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation; -import com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.operations.common.SyncOperation; @@ -49,45 +47,23 @@ public CreateShareViaLinkOperation(String path, String password) { @Override protected RemoteOperationResult run(OwnCloudClient client) { - // Check if the share link already exists - RemoteOperation operation = new GetSharesForFileRemoteOperation(path, false, false); - RemoteOperationResult result = operation.execute(client); - - // Create public link if doesn't exist yet - boolean publicShareExists = false; - if (result.isSuccess()) { - OCShare share; - for (int i=0 ; i 0) { Object item = result.getData().get(0); - if (item instanceof OCShare) { + if (item instanceof OCShare) { updateData((OCShare) item); } else { ArrayList data = result.getData(); - result = new RemoteOperationResult( - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND - ); + result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); result.setData(data); } } else { @@ -110,8 +86,8 @@ private void updateData(OCShare share) { getStorageManager().saveShare(share); // Update OCFile with data from share: ShareByLink and publicLink - OCFile file = getStorageManager().getFileByPath(path); - if (file!=null) { + OCFile file = getStorageManager().getFileByEncryptedRemotePath(path); + if (file != null) { file.setPublicLink(share.getShareLink()); file.setSharedViaLink(true); getStorageManager().saveFile(file); diff --git a/src/main/java/com/owncloud/android/operations/UnshareOperation.java b/src/main/java/com/owncloud/android/operations/UnshareOperation.java index 133832348b20..2d066dced580 100644 --- a/src/main/java/com/owncloud/android/operations/UnshareOperation.java +++ b/src/main/java/com/owncloud/android/operations/UnshareOperation.java @@ -21,8 +21,6 @@ package com.owncloud.android.operations; -import android.content.Context; - import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -46,44 +44,37 @@ public class UnshareOperation extends SyncOperation { private static final int SINGLY_SHARED = 1; private String mRemotePath; - private ShareType mShareType; - private String mShareWith; - private Context mContext; + private long shareId; - public UnshareOperation(String remotePath, ShareType shareType, String shareWith, - Context context) { + public UnshareOperation(String remotePath, long shareId) { mRemotePath = remotePath; - mShareType = shareType; - mShareWith = shareWith; - mContext = context; + this.shareId = shareId; } @Override protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; + RemoteOperationResult result; // Get Share for a file - OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, - mShareType, mShareWith); + OCShare share = getStorageManager().getShareById(shareId); if (share != null) { - OCFile file = getStorageManager().getFileByPath(mRemotePath); - RemoveShareRemoteOperation operation = - new RemoveShareRemoteOperation((int) share.getRemoteId()); + OCFile file = getStorageManager().getFileByEncryptedRemotePath(mRemotePath); + RemoveShareRemoteOperation operation = new RemoveShareRemoteOperation(share.getRemoteId()); result = operation.execute(client); if (result.isSuccess()) { Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted"); - if (ShareType.PUBLIC_LINK.equals(mShareType)) { + if (ShareType.PUBLIC_LINK.equals(share.getShareType())) { file.setSharedViaLink(false); file.setPublicLink(""); - } else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType) - || ShareType.FEDERATED.equals(mShareType)){ + } else if (ShareType.USER.equals(share.getShareType()) || ShareType.GROUP.equals(share.getShareType()) + || ShareType.FEDERATED.equals(share.getShareType())) { // Check if it is the last share - List sharesWith = getStorageManager(). - getSharesWithForAFile(mRemotePath, - getStorageManager().getAccount().name); + List sharesWith = getStorageManager(). + getSharesWithForAFile(mRemotePath, + getStorageManager().getAccount().name); if (sharesWith.size() == SINGLY_SHARED) { file.setSharedWithSharee(false); } @@ -104,15 +95,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { return result; } - private boolean existsFile(OwnCloudClient client, String remotePath){ - ExistenceCheckRemoteOperation existsOperation = - new ExistenceCheckRemoteOperation(remotePath, mContext, false); - RemoteOperationResult result = existsOperation.execute(client); - return result.isSuccess(); - } - - public ShareType getShareType() { - return mShareType; + private boolean existsFile(OwnCloudClient client, String remotePath) { + return new ExistenceCheckRemoteOperation(remotePath, false).execute(client).isSuccess(); } - } diff --git a/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java b/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java index 01fbc3af4105..72ae1de52c80 100644 --- a/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java +++ b/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java @@ -27,7 +27,6 @@ import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation; import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.shares.UpdateShareRemoteOperation; import com.owncloud.android.operations.common.SyncOperation; @@ -44,25 +43,22 @@ public class UpdateShareViaLinkOperation extends SyncOperation { private Boolean publicUploadOnFile; private Boolean hideFileDownload; private long expirationDateInMillis; + private long shareId; /** * Constructor * - * @param path Full path of the file/folder being shared. Mandatory argument + * @param path Full path of the file/folder being shared. Mandatory argument */ - public UpdateShareViaLinkOperation(String path) { + public UpdateShareViaLinkOperation(String path, long shareId) { this.path = path; expirationDateInMillis = 0; + this.shareId = shareId; } @Override protected RemoteOperationResult run(OwnCloudClient client) { - OCShare publicShare = getStorageManager().getFirstShareByPathAndType(path, ShareType.PUBLIC_LINK, ""); - - if (publicShare == null) { - // TODO try to get remote share before failing? - return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); - } + OCShare publicShare = getStorageManager().getShareById(shareId); UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(publicShare.getRemoteId()); updateOp.setPassword(password); diff --git a/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/src/main/java/com/owncloud/android/providers/FileContentProvider.java index ec853564a062..670cb5f30600 100644 --- a/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -747,7 +747,8 @@ private void createOCSharesTable(SQLiteDatabase db) { + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER + ProviderTableMeta.OCSHARES_NOTE + TEXT - + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER );"); + + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + INTEGER + + ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT );"); } private void createCapabilitiesTable(SQLiteDatabase db) { @@ -2234,6 +2235,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (!upgraded) { Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion)); } + + if (oldVersion < 58 && newVersion >= 58) { + Log_OC.i(SQL, "Entering in the #58 add public link to share table"); + db.beginTransaction(); + try { + db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME + + ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT "); + + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + + if (!upgraded) { + Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion)); + } } } } diff --git a/src/main/java/com/owncloud/android/services/OperationsService.java b/src/main/java/com/owncloud/android/services/OperationsService.java index d015b78fd94b..57be86a6d55e 100644 --- a/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/src/main/java/com/owncloud/android/services/OperationsService.java @@ -538,7 +538,8 @@ private Pair newOperation(Intent operationIntent) { shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1); if (!TextUtils.isEmpty(remotePath)) { - UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(remotePath); + UpdateShareViaLinkOperation updateLinkOperation = + new UpdateShareViaLinkOperation(remotePath, shareId); password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD); updateLinkOperation.setPassword(password); @@ -547,7 +548,7 @@ private Pair newOperation(Intent operationIntent) { updateLinkOperation.setExpirationDateInMillis(expirationDate); boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, - false); + false); updateLinkOperation.setHideFileDownload(hideFileDownload); if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) { @@ -593,17 +594,16 @@ private Pair newOperation(Intent operationIntent) { int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1); if (!TextUtils.isEmpty(remotePath)) { operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType, - permissions); + permissions); } break; case ACTION_UNSHARE: remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); - shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE); - String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH); + shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1); - if (!TextUtils.isEmpty(remotePath)) { - operation = new UnshareOperation(remotePath, shareType, shareWith, this); + if (shareId > 0) { + operation = new UnshareOperation(remotePath, shareId); } break; diff --git a/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index b003c1a8f1b4..f8bc5cfd53e1 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -771,6 +771,7 @@ private void onUpdateShareInformation(RemoteOperationResult result, @StringRes i if (result.isSuccess()) { updateFileFromDB(); if (sharingFragment != null) { + sharingFragment.refreshPublicShareFromDB(); sharingFragment.onUpdateShareInformation(result, getFile()); } } else if (sharingFragment != null && sharingFragment.getView() != null) { diff --git a/src/main/java/com/owncloud/android/ui/adapter/PublicShareInterface.java b/src/main/java/com/owncloud/android/ui/adapter/PublicShareInterface.java new file mode 100644 index 000000000000..d34d5bb90405 --- /dev/null +++ b/src/main/java/com/owncloud/android/ui/adapter/PublicShareInterface.java @@ -0,0 +1,33 @@ +/* + * + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2020 Tobias Kaminsky + * Copyright (C) 2020 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.ui.adapter; + +import android.widget.ImageView; + +import com.owncloud.android.lib.resources.shares.OCShare; + +public interface PublicShareInterface { + void copyLink(OCShare share); + + void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink); +} diff --git a/src/main/java/com/owncloud/android/ui/adapter/PublicShareListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/PublicShareListAdapter.java new file mode 100644 index 000000000000..abc11ecdea24 --- /dev/null +++ b/src/main/java/com/owncloud/android/ui/adapter/PublicShareListAdapter.java @@ -0,0 +1,68 @@ +/* + * + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2020 Tobias Kaminsky + * Copyright (C) 2020 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.ui.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import com.owncloud.android.databinding.FileDetailsSharePublicLinkItemBinding; +import com.owncloud.android.lib.resources.shares.OCShare; + +import java.util.List; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +public class PublicShareListAdapter extends RecyclerView.Adapter { + private Context context; + private List shares; + private PublicShareInterface listener; + + public PublicShareListAdapter(Context context, List shares, PublicShareInterface listener) { + this.context = context; + this.shares = shares; + this.listener = listener; + } + + @NonNull + @Override + public PublicShareViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + FileDetailsSharePublicLinkItemBinding binding = + FileDetailsSharePublicLinkItemBinding.inflate(LayoutInflater.from(context), parent, false); + + return new PublicShareViewHolder(binding, context); + } + + @Override + public void onBindViewHolder(@NonNull PublicShareViewHolder holder, int position) { + OCShare share = shares.get(position); + + holder.bind(share, listener); + } + + @Override + public int getItemCount() { + return shares.size(); + } +} diff --git a/src/main/java/com/owncloud/android/ui/adapter/PublicShareViewHolder.java b/src/main/java/com/owncloud/android/ui/adapter/PublicShareViewHolder.java new file mode 100644 index 000000000000..bc0238221bea --- /dev/null +++ b/src/main/java/com/owncloud/android/ui/adapter/PublicShareViewHolder.java @@ -0,0 +1,66 @@ +/* + * + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2020 Tobias Kaminsky + * Copyright (C) 2020 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.ui.adapter; + +import android.content.Context; +import android.graphics.PorterDuff; +import android.view.View; + +import com.owncloud.android.R; +import com.owncloud.android.databinding.FileDetailsSharePublicLinkItemBinding; +import com.owncloud.android.lib.resources.shares.OCShare; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +class PublicShareViewHolder extends RecyclerView.ViewHolder { + private FileDetailsSharePublicLinkItemBinding binding; + private Context context; + + public PublicShareViewHolder(@NonNull View itemView) { + super(itemView); + } + + public PublicShareViewHolder(FileDetailsSharePublicLinkItemBinding binding, Context context) { + this(binding.getRoot()); + this.binding = binding; + this.context = context; + } + + public void bind(OCShare publicShare, PublicShareInterface listener) { + binding.copyInternalLinkIcon + .getBackground() + .setColorFilter(context.getResources().getColor(R.color.primary_button_background_color), + PorterDuff.Mode.SRC_IN); + binding.copyInternalLinkIcon + .getDrawable() + .mutate() + .setColorFilter(context.getResources().getColor(R.color.black), + PorterDuff.Mode.SRC_IN); + + binding.shareLinkCopyIcon.setOnClickListener(v -> listener.copyLink(publicShare)); + + binding.overflowMenuShareLink.setOnClickListener( + v -> listener.showLinkOverflowMenu(publicShare, binding.overflowMenuShareLink)); + } +} diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 8aacb5ff985e..35ad6feab6d9 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -40,7 +40,6 @@ 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 +57,8 @@ 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 +77,7 @@ 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,7 +88,9 @@ 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"; @@ -98,7 +101,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda private OCFile file; private User user; private OCCapability capabilities; - private OCShare publicShare; private FileOperationsHelper fileOperationsHelper; private FileActivity fileActivity; @@ -112,20 +114,14 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda @BindView(R.id.shareUsersList) RecyclerView usersList; - @BindView(R.id.share_by_link) - AppCompatCheckBox shareByLink; + @BindView(R.id.publicShareList) + RecyclerView publicShareList; - @BindView(R.id.share_link_copy_icon) - ImageView shareLinkCopyIcon; + @BindView(R.id.new_public_share) + View addPublicShare; - @BindView(R.id.overflow_menu_share_link) - ImageView overflowMenuShareLink; - - @BindView(R.id.share_by_link_allow_editing) - AppCompatCheckBox shareByLinkAllowEditing; - - @BindView(R.id.share_by_link_container) - LinearLayout shareByLinkContainer; + @BindView(R.id.shareNoUsers) + TextView noList; @BindView(R.id.shared_with_you_container) LinearLayout sharedWithYouContainer; @@ -267,45 +263,6 @@ private void disableSearchView(View view) { } } - /** - * 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 +285,9 @@ private void setShareWithYou() { } } - private void updateListOfUserGroups() { + private void setShareWithUserInfo() { // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed - + shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), account.name); if (shares.size() > 0) { AccountManager accountManager = AccountManager.get(getContext()); String userId = accountManager.getUserData(user.toPlatformAccount(), @@ -351,15 +308,6 @@ private void updateListOfUserGroups() { } } - @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 +347,7 @@ private void showSendLinkTo() { } } - @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 +357,55 @@ public void copyLinkToClipboard() { } } - @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() > 17) { + 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 +429,12 @@ private boolean optionsItemSelected(MenuItem item) { 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 +445,11 @@ private boolean optionsItemSelected(MenuItem item) { 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); default: return super.onOptionsItemSelected(item); } @@ -545,30 +495,29 @@ public void onUpdateShareInformation(RemoteOperationResult result, OCFile file) * 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 +567,32 @@ public void refreshCapabilitiesFromDB() { */ 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 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())); } } diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index a7fead72c713..073989fc7bce 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -69,6 +69,7 @@ import com.owncloud.android.ui.activity.ConflictsResolveActivity; import com.owncloud.android.ui.activity.ExternalSiteWebView; import com.owncloud.android.ui.activity.FileActivity; +import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.RichDocumentsEditorWebView; import com.owncloud.android.ui.activity.ShareActivity; import com.owncloud.android.ui.activity.TextEditorWebView; @@ -476,19 +477,19 @@ public void shareFileViaLink(OCFile file, String password) { } } - public void getFileWithLink(OCFile file) { - if (file != null) { - fileActivity.showLoadingDialog(fileActivity.getApplicationContext(). - getString(R.string.wait_a_moment)); - - Intent service = new Intent(fileActivity, OperationsService.class); - service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK); - service.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount()); - service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - mWaitingForOpId = fileActivity.getOperationsServiceBinder().queueNewOperation(service); + public void getFileWithLink(@NonNull OCFile file) { + List shares = fileActivity.getStorageManager().getSharesByPathAndType(file.getRemotePath(), + ShareType.PUBLIC_LINK, + ""); + if (shares.size() == 1) { + FileActivity.copyAndShareFileLink(fileActivity, file, shares.get(0).getShareLink()); } else { - Log_OC.e(TAG, "Trying to share a NULL OCFile"); + if (fileActivity instanceof FileDisplayActivity) { + ((FileDisplayActivity) fileActivity).showDetails(file, 1); + } else { + showShareFile(file); + } } } @@ -541,33 +542,18 @@ public void restoreFileVersion(FileVersion fileVersion) { } /** - * Helper method to unshare a file publicly shared via link. - * Starts a request to do it in {@link OperationsService} + * Helper method to unshare a file publicly shared via link. Starts a request to do it in {@link OperationsService} * * @param file The file to unshare. */ - public void unshareFileViaLink(OCFile file) { - - // Unshare the file: Create the intent - Intent unshareService = new Intent(fileActivity, OperationsService.class); - unshareService.setAction(OperationsService.ACTION_UNSHARE); - unshareService.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount()); - unshareService.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK); - unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, ""); - - queueShareIntent(unshareService); - } - - public void unshareFileWithUserOrGroup(OCFile file, ShareType shareType, String userOrGroup) { + public void unshareShare(OCFile file, OCShare share) { // Unshare the file: Create the intent Intent unshareService = new Intent(fileActivity, OperationsService.class); unshareService.setAction(OperationsService.ACTION_UNSHARE); unshareService.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount()); unshareService.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType); - unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, userOrGroup); + unshareService.putExtra(OperationsService.EXTRA_SHARE_ID, share.getId()); queueShareIntent(unshareService); } diff --git a/src/main/res/layout/file_details_share_public_link_add_new_item.xml b/src/main/res/layout/file_details_share_public_link_add_new_item.xml new file mode 100644 index 000000000000..e8a61755363b --- /dev/null +++ b/src/main/res/layout/file_details_share_public_link_add_new_item.xml @@ -0,0 +1,70 @@ + + + + + + + + + + diff --git a/src/main/res/layout/file_details_share_public_link_item.xml b/src/main/res/layout/file_details_share_public_link_item.xml new file mode 100644 index 000000000000..74f51eda0a73 --- /dev/null +++ b/src/main/res/layout/file_details_share_public_link_item.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + diff --git a/src/main/res/layout/file_details_sharing_fragment.xml b/src/main/res/layout/file_details_sharing_fragment.xml index 1e71f1a37fb4..f7683f193151 100644 --- a/src/main/res/layout/file_details_sharing_fragment.xml +++ b/src/main/res/layout/file_details_sharing_fragment.xml @@ -99,68 +99,15 @@ - - - - - - - - - - + android:layout_height="0dp" + android:layout_weight="1" + android:divider="@drawable/divider" + android:dividerHeight="1dp" /> - - + + + - - + app:showAsAction="never" /> + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index cade42cbe83d..3b6b60fbafbf 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -926,4 +926,8 @@ Error creating conflict dialog! QR Code could not be read! Note icon + Add another link + Unshare + Allow editing + Add new public share link From 3c7fe3a4051670d0af7527b1251fa6b1d2dee38d Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 25 Jun 2020 15:18:38 +0200 Subject: [PATCH 2/7] UI fine tuning for link items / sharing fragments Signed-off-by: Andy Scherzinger --- ...details_share_public_link_add_new_item.xml | 88 ++++++++--------- .../file_details_share_public_link_item.xml | 94 +++++++++---------- .../layout/file_details_sharing_fragment.xml | 48 +++++----- 3 files changed, 102 insertions(+), 128 deletions(-) diff --git a/src/main/res/layout/file_details_share_public_link_add_new_item.xml b/src/main/res/layout/file_details_share_public_link_add_new_item.xml index e8a61755363b..7e6aa96126dd 100644 --- a/src/main/res/layout/file_details_share_public_link_add_new_item.xml +++ b/src/main/res/layout/file_details_share_public_link_add_new_item.xml @@ -1,56 +1,48 @@ - + + + + + android:layout_marginEnd="@dimen/standard_margin" + android:background="@drawable/round_bgnd" + android:contentDescription="@string/share" + android:padding="@dimen/standard_half_padding" + android:src="@drawable/shared_via_link" /> diff --git a/src/main/res/layout/file_details_share_public_link_item.xml b/src/main/res/layout/file_details_share_public_link_item.xml index 74f51eda0a73..8400d3e2a224 100644 --- a/src/main/res/layout/file_details_share_public_link_item.xml +++ b/src/main/res/layout/file_details_share_public_link_item.xml @@ -1,52 +1,44 @@ - + + + + + android:layout_height="@dimen/standard_list_item_size" + android:orientation="horizontal"> + android:layout_marginEnd="@dimen/standard_margin" + android:background="@drawable/round_bgnd" + android:contentDescription="@string/share" + android:padding="@dimen/standard_half_padding" + android:src="@drawable/shared_via_link" /> + diff --git a/src/main/res/layout/file_details_sharing_fragment.xml b/src/main/res/layout/file_details_sharing_fragment.xml index f7683f193151..f5ebfef9975f 100644 --- a/src/main/res/layout/file_details_sharing_fragment.xml +++ b/src/main/res/layout/file_details_sharing_fragment.xml @@ -33,12 +33,12 @@ + android:hint="@string/share_search" /> @@ -121,48 +121,42 @@ android:id="@+id/copy_internal_container" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/standard_margin" + android:orientation="horizontal" android:paddingStart="@dimen/zero" + android:paddingTop="@dimen/standard_half_padding" android:paddingEnd="@dimen/standard_padding" - android:orientation="horizontal"> + android:paddingBottom="@dimen/standard_padding"> + android:layout_marginEnd="@dimen/standard_margin" + android:background="@drawable/round_bgnd" + android:contentDescription="@string/share" + android:padding="@dimen/standard_half_padding" + android:src="@drawable/ic_external" /> + android:text="@string/share_internal_link" + android:textColor="@color/text_color" /> + android:layout_height="wrap_content" + tools:text="@string/share_internal_link_to_folder_text" /> From 3848346f4aca3b24cebc76b6767b6e089589091c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 25 Jun 2020 18:37:28 +0200 Subject: [PATCH 3/7] remove literals in conditional statements --- .../android/ui/fragment/FileDetailSharingFragment.java | 3 ++- .../com/owncloud/android/ui/helpers/FileOperationsHelper.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 35ad6feab6d9..041dc92dbb07 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -94,6 +94,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda private static final String ARG_FILE = "FILE"; private static final String ARG_USER = "USER"; + public static final int PERMISSION_EDITING_ALLOWED = 17; // to show share with users/groups info private List shares; @@ -390,7 +391,7 @@ private void prepareOptionsMenu(Menu menu, OCShare publicShare) { menu.findItem(R.id.action_share_send_note).setVisible(capabilities.getVersion().isNoteOnShareSupported()); - if (publicShare.getPermissions() > 17) { + 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); diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 073989fc7bce..bf754f75cda2 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -118,6 +118,7 @@ public class FileOperationsHelper { private static final String FILE_EXTENSION_URL = "url"; private static final String FILE_EXTENSION_DESKTOP = "desktop"; private static final String FILE_EXTENSION_WEBLOC = "webloc"; + public static final int SINGLE_LINK_SIZE = 1; private FileActivity fileActivity; private CurrentAccountProvider currentAccount; @@ -482,7 +483,7 @@ public void getFileWithLink(@NonNull OCFile file) { ShareType.PUBLIC_LINK, ""); - if (shares.size() == 1) { + if (shares.size() == SINGLE_LINK_SIZE) { FileActivity.copyAndShareFileLink(fileActivity, file, shares.get(0).getShareLink()); } else { if (fileActivity instanceof FileDisplayActivity) { From 51365fa7c30e3d27ff61fc6b4ca4b3c1601aaf39 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 29 Jun 2020 15:33:11 +0200 Subject: [PATCH 4/7] fixes after rebase Signed-off-by: tobiasKaminsky --- .../android/ui/fragment/FileDetailSharingFragment.java | 5 ----- src/main/res/layout/file_details_sharing_fragment.xml | 1 - 2 files changed, 6 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 041dc92dbb07..587f496a0ff2 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -121,9 +121,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda @BindView(R.id.new_public_share) View addPublicShare; - @BindView(R.id.shareNoUsers) - TextView noList; - @BindView(R.id.shared_with_you_container) LinearLayout sharedWithYouContainer; @@ -242,13 +239,11 @@ private void setupView() { 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); } } diff --git a/src/main/res/layout/file_details_sharing_fragment.xml b/src/main/res/layout/file_details_sharing_fragment.xml index f5ebfef9975f..947792c25a40 100644 --- a/src/main/res/layout/file_details_sharing_fragment.xml +++ b/src/main/res/layout/file_details_sharing_fragment.xml @@ -18,7 +18,6 @@ License along with this program. If not, see . --> Date: Mon, 29 Jun 2020 16:49:06 +0200 Subject: [PATCH 5/7] revert library Signed-off-by: tobiasKaminsky --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 76cdb32b5850..e9b36b1a6a1e 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ ext { daggerVersion = "2.28.1" markwonVersion = "4.4.0" prismVersion = "2.0.0" - androidLibraryVersion = "publicLink-SNAPSHOT" + androidLibraryVersion = "master-SNAPSHOT" travisBuild = System.getenv("TRAVIS") == "true" From f07e14fd305082f0d8e76a2f412860bfb2c5d9fa Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 30 Jun 2020 07:45:59 +0200 Subject: [PATCH 6/7] minor code changes after rebase Signed-off-by: tobiasKaminsky --- .../android/ui/fragment/FileDetailSharingFragment.java | 8 +++----- .../file_details_share_public_link_add_new_item.xml | 1 - src/main/res/values/dims.xml | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 587f496a0ff2..aef14d8e5817 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -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; @@ -96,9 +95,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda private static final String ARG_USER = "USER"; public static final int PERMISSION_EDITING_ALLOWED = 17; - // to show share with users/groups info - private List shares; - private OCFile file; private User user; private OCCapability capabilities; @@ -283,7 +279,9 @@ private void setShareWithYou() { private void setShareWithUserInfo() { // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed - shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), account.name); + // to show share with users/groups info + List shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), + user.toPlatformAccount().name); if (shares.size() > 0) { AccountManager accountManager = AccountManager.get(getContext()); String userId = accountManager.getUserData(user.toPlatformAccount(), diff --git a/src/main/res/layout/file_details_share_public_link_add_new_item.xml b/src/main/res/layout/file_details_share_public_link_add_new_item.xml index 7e6aa96126dd..5fd4a5d65a8f 100644 --- a/src/main/res/layout/file_details_share_public_link_add_new_item.xml +++ b/src/main/res/layout/file_details_share_public_link_add_new_item.xml @@ -30,7 +30,6 @@ android:visibility="gone"> 18sp 24dp 4 - 10dp 130dp 170dp 12dp From 7cbfc580360ba30a33bfb40af8fe74df758c8966 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 30 Jun 2020 09:35:33 +0200 Subject: [PATCH 7/7] fix switch statement Signed-off-by: tobiasKaminsky --- .../owncloud/android/ui/fragment/FileDetailSharingFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index aef14d8e5817..6a71a9092b20 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -444,6 +444,7 @@ public boolean optionsItemSelected(MenuItem item, OCShare publicShare) { return true; case R.id.action_unshare: fileOperationsHelper.unshareShare(file, publicShare); + return true; default: return super.onOptionsItemSelected(item); }