From 48670cfd80e6e884cf42b9ab7c80fa0af9a53a23 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 14 Feb 2025 10:34:04 +0100 Subject: [PATCH] fix git conflicts Signed-off-by: alperozturk --- .../notes/persistence/dao/ShareDao.kt | 10 +- .../notes/share/ClientFactoryImpl.java | 84 --- .../share/CreateShareViaLinkOperation.java | 91 --- .../notes/share/NoteShareFragment.java | 692 ------------------ .../owncloud/notes/share/SyncOperation.java | 37 - .../owncloud/notes/shared/server/Server.kt | 40 - .../owncloud/notes/shared/user/User.kt | 56 -- .../notes/shared/util/ClipboardUtil.kt | 50 -- app/src/main/res/layout/activity_row.xml | 2 +- app/src/main/res/values/strings.xml | 76 +- 10 files changed, 59 insertions(+), 1079 deletions(-) delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/share/ClientFactoryImpl.java delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/share/CreateShareViaLinkOperation.java delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareFragment.java delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/share/SyncOperation.java delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/shared/server/Server.kt delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/shared/user/User.kt delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/shared/util/ClipboardUtil.kt diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/ShareDao.kt b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/ShareDao.kt index 97f27cac0..15ab98f80 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/ShareDao.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/ShareDao.kt @@ -2,15 +2,15 @@ package it.niedermann.owncloud.notes.persistence.dao import androidx.room.Dao import androidx.room.Insert +import androidx.room.OnConflictStrategy import androidx.room.Query import it.niedermann.owncloud.notes.persistence.entity.ShareEntity @Dao interface ShareDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun addShareEntities(entities: List) - @Insert - fun addShareEntity(entity: ShareEntity) - - @Query("SELECT * FROM share_table WHERE noteRemoteId = :noteRemoteId AND userName = :userName") - fun getShareEntities(noteRemoteId: Long, userName: String): List + @Query("SELECT * FROM share_table WHERE path = :path") + fun getShareEntities(path: String): List } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/ClientFactoryImpl.java b/app/src/main/java/it/niedermann/owncloud/notes/share/ClientFactoryImpl.java deleted file mode 100644 index b9c82d25e..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/ClientFactoryImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2019 Chris Narkiewicz - * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only - */ - -package it.niedermann.owncloud.notes.share.operations; - -import android.accounts.Account; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.app.Activity; -import android.content.Context; -import android.net.Uri; - -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.common.PlainClient; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; -import com.owncloud.android.lib.common.accounts.AccountUtils; - -import java.io.IOException; - -import it.niedermann.owncloud.notes.shared.user.User; - -public class ClientFactoryImpl implements ClientFactory { - - private Context context; - - public ClientFactoryImpl(Context context) { - this.context = context; - } - - @Override - public OwnCloudClient create(User user) throws CreationException { - try { - return OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(), context); - } catch (OperationCanceledException | - AuthenticatorException | - IOException e) { - throw new CreationException(e); - } - } - - @Override - public NextcloudClient createNextcloudClient(User user) throws CreationException { - try { - return OwnCloudClientFactory.createNextcloudClient(user, context); - } catch (AccountUtils.AccountNotFoundException e) { - throw new CreationException(e); - } - } - - @Override - public OwnCloudClient create(Account account) - throws OperationCanceledException, AuthenticatorException, IOException, - AccountUtils.AccountNotFoundException { - return OwnCloudClientFactory.createOwnCloudClient(account, context); - } - - @Override - public OwnCloudClient create(Account account, Activity currentActivity) - throws OperationCanceledException, AuthenticatorException, IOException, - AccountUtils.AccountNotFoundException { - return OwnCloudClientFactory.createOwnCloudClient(account, context, currentActivity); - } - - @Override - public OwnCloudClient create(Uri uri, boolean followRedirects, boolean useNextcloudUserAgent) { - return OwnCloudClientFactory.createOwnCloudClient(uri, context, followRedirects); - } - - @Override - public OwnCloudClient create(Uri uri, boolean followRedirects) { - return OwnCloudClientFactory.createOwnCloudClient(uri, context, followRedirects); - } - - @Override - public PlainClient createPlainClient() { - return new PlainClient(context); - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/CreateShareViaLinkOperation.java b/app/src/main/java/it/niedermann/owncloud/notes/share/CreateShareViaLinkOperation.java deleted file mode 100644 index 509fce819..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/CreateShareViaLinkOperation.java +++ /dev/null @@ -1,91 +0,0 @@ -package it.niedermann.owncloud.notes.share; - -import java.util.ArrayList; - -import com.owncloud.android.lib.common.OwnCloudClient; -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.OCShare; -import com.owncloud.android.lib.resources.shares.ShareType; - - -import it.niedermann.owncloud.notes.shared.user.User; - -/** - * Creates a new public share for a given file - */ -public class CreateShareViaLinkOperation extends SyncOperation { - - private final String path; - private final String password; - private int permissions = OCShare.NO_PERMISSION; - - public CreateShareViaLinkOperation(String path, String password, User user) { - super(user); - - this.path = path; - this.password = password; - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - CreateShareRemoteOperation createOp = new CreateShareRemoteOperation(path, - ShareType.PUBLIC_LINK, - "", - false, - password, - permissions); - createOp.setGetShareDetails(true); - RemoteOperationResult result = createOp.execute(client); - - if (result.isSuccess()) { - if (result.getData().size() > 0) { - Object item = result.getData().get(0); - if (item instanceof OCShare) { - updateData((OCShare) item); - } else { - ArrayList data = result.getData(); - result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); - result.setData(data); - } - } else { - result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); - } - } - - return result; - } - - private void updateData(OCShare share) { - // Update DB with the response - share.setPath(path); - if (path.endsWith(FileUtils.PATH_SEPARATOR)) { - share.setFolder(true); - } else { - share.setFolder(false); - } - - // TODO: Save share - - /* - getStorageManager().saveShare(share); - - // Update OCFile with data from share: ShareByLink and publicLink - OCFile file = getStorageManager().getFileByEncryptedRemotePath(path); - if (file != null) { - file.setSharedViaLink(true); - getStorageManager().saveFile(file); - } - */ - - } - - public String getPath() { - return this.path; - } - - public String getPassword() { - return this.password; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareFragment.java deleted file mode 100644 index 759c8a8f0..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareFragment.java +++ /dev/null @@ -1,692 +0,0 @@ -package it.niedermann.owncloud.notes.share; - -import android.Manifest; -import android.app.Activity; -import android.app.SearchManager; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.database.Cursor; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.Bundle; -import android.provider.ContactsContract; -import android.text.InputType; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; - -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import androidx.appcompat.widget.SearchView; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; -import com.google.android.material.snackbar.Snackbar; -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.ShareType; -import com.owncloud.android.lib.resources.status.NextcloudVersion; - -import java.util.ArrayList; -import java.util.List; - -import it.niedermann.nextcloud.sso.glide.SingleSignOnUrl; -import it.niedermann.owncloud.notes.R; -import it.niedermann.owncloud.notes.branding.BrandedSnackbar; -import it.niedermann.owncloud.notes.databinding.FragmentNoteShareBinding; -import it.niedermann.owncloud.notes.persistence.entity.Account; -import it.niedermann.owncloud.notes.persistence.entity.Note; -import it.niedermann.owncloud.notes.share.adapter.ShareeListAdapter; -import it.niedermann.owncloud.notes.share.dialog.FileDetailSharingMenuBottomSheetDialog; -import it.niedermann.owncloud.notes.share.dialog.QuickSharingPermissionsBottomSheetDialog; -import it.niedermann.owncloud.notes.share.dialog.ShareLinkToDialog; -import it.niedermann.owncloud.notes.share.dialog.SharePasswordDialogFragment; -import it.niedermann.owncloud.notes.share.listener.FileDetailsSharingMenuBottomSheetActions; -import it.niedermann.owncloud.notes.share.listener.ShareeListAdapterListener; -import it.niedermann.owncloud.notes.share.model.UsersAndGroupsSearchConfig; -import it.niedermann.owncloud.notes.share.operations.ClientFactoryImpl; -import it.niedermann.owncloud.notes.share.operations.RetrieveHoverCardAsyncTask; -import it.niedermann.owncloud.notes.shared.user.User; -import it.niedermann.owncloud.notes.shared.util.extensions.BundleExtensionsKt; - -public class NoteShareFragment extends Fragment implements ShareeListAdapterListener, FileDetailsSharingMenuBottomSheetActions, QuickSharingPermissionsBottomSheetDialog.QuickPermissionSharingBottomSheetActions { - - private static final String TAG = "NoteShareFragment"; - private static final String ARG_NOTE = "NOTE"; - private static final String ARG_ACCOUNT = "ACCOUNT"; - private static final String ARG_USER = "USER"; - public static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; - - private FragmentNoteShareBinding binding; - private Note note; - private User user; - private Account account; - - private OnEditShareListener onEditShareListener; - private ClientFactoryImpl clientFactory; - - public static NoteShareFragment newInstance(Note note, User user, Account account) { - NoteShareFragment fragment = new NoteShareFragment(); - Bundle args = new Bundle(); - args.putSerializable(ARG_NOTE, note); - args.putSerializable(ARG_ACCOUNT, account); - args.putParcelable(ARG_USER, user); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - clientFactory = new ClientFactoryImpl(requireContext()); - - if (savedInstanceState != null) { - note = BundleExtensionsKt.getSerializableArgument(savedInstanceState, ARG_NOTE, Note.class); - account = BundleExtensionsKt.getSerializableArgument(savedInstanceState, ARG_ACCOUNT, Account.class); - user = BundleExtensionsKt.getParcelableArgument(savedInstanceState, ARG_USER, User.class); - } else { - Bundle arguments = getArguments(); - if (arguments != null) { - note = BundleExtensionsKt.getSerializableArgument(arguments, ARG_NOTE, Note.class); - account = BundleExtensionsKt.getSerializableArgument(arguments, ARG_ACCOUNT, Account.class); - user = BundleExtensionsKt.getParcelableArgument(arguments, ARG_USER, User.class); - } - } - - if (note == null) { - throw new IllegalArgumentException("Note cannot be null"); - } - - if (user == null) { - throw new IllegalArgumentException("Account cannot be null"); - } - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - refreshCapabilitiesFromDB(); - refreshSharesFromDB(); - } - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - binding = FragmentNoteShareBinding.inflate(inflater, container, false); - - binding.sharesList.setAdapter(new ShareeListAdapter(requireActivity(), - new ArrayList<>(), - this, - user, - account)); - - binding.sharesList.setLayoutManager(new LinearLayoutManager(requireContext())); - - binding.pickContactEmailBtn.setOnClickListener(v -> checkContactPermission()); - - setupView(); - - return binding.getRoot(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - binding = null; - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - try { - onEditShareListener = (OnEditShareListener) context; - } catch (Exception e) { - throw new IllegalArgumentException("Calling activity must implement the interface", e); - } - } - - @Override - public void onStart() { - super.onStart(); - UsersAndGroupsSearchConfig.INSTANCE.setSearchOnlyUsers(true); - } - - @Override - public void onStop() { - super.onStop(); - UsersAndGroupsSearchConfig.INSTANCE.reset(); - } - - private void setupView() { - setShareWithYou(); - - // OCFile parentFile = fileDataStorageManager.getFileById(file.getParentId()); - - setupSearchView((SearchManager) requireContext().getSystemService(Context.SEARCH_SERVICE), binding.searchView, requireActivity().getComponentName()); - // viewThemeUtils.androidx.themeToolbarSearchView(binding.searchView); - - binding.searchView.setQueryHint(getResources().getString(R.string.note_share_fragment_resharing_not_allowed)); - binding.searchView.setInputType(InputType.TYPE_NULL); - binding.pickContactEmailBtn.setVisibility(View.GONE); - disableSearchView(binding.searchView); - - /* - if (file.canReshare()) { - binding.searchView.setQueryHint(getResources().getString(R.string.note_share_fragment_search_text)); - } else { - binding.searchView.setQueryHint(getResources().getString(R.string.note_share_fragment_resharing_not_allowed)); - binding.searchView.setInputType(InputType.TYPE_NULL); - binding.pickContactEmailBtn.setVisibility(View.GONE); - disableSearchView(binding.searchView); - } - */ - - } - - private void setupSearchView(@Nullable SearchManager searchManager, SearchView searchView, - ComponentName componentName) { - if (searchManager == null) { - searchView.setVisibility(View.GONE); - return; - } - - // assumes parent activity is the searchable activity - searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName)); - - // do not iconify the widget; expand it by default - searchView.setIconifiedByDefault(false); - - // avoid fullscreen with softkeyboard - searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - // return true to prevent the query from being processed; - return true; - } - - @Override - public boolean onQueryTextChange(String newText) { - // leave it for the parent listener in the hierarchy / default behaviour - return false; - } - }); - } - - private void disableSearchView(View view) { - view.setEnabled(false); - - if (view instanceof ViewGroup viewGroup) { - for (int i = 0; i < viewGroup.getChildCount(); i++) { - disableSearchView(viewGroup.getChildAt(i)); - } - } - } - - // TODO: Check if note.getAccountId() return note's owner's id - private boolean accountOwnsFile() { - String noteId = String.valueOf(note.getAccountId()); - return TextUtils.isEmpty(noteId) || account.getAccountName().split("@")[0].equalsIgnoreCase(noteId); - } - - private void setShareWithYou() { - if (accountOwnsFile()) { - binding.sharedWithYouContainer.setVisibility(View.GONE); - } else { - - /* - // TODO: How to get owner display name from note? - - binding.sharedWithYouUsername.setText( - String.format(getString(R.string.note_share_fragment_shared_with_you), file.getOwnerDisplayName())); - */ - - - Glide.with(this) - .load(new SingleSignOnUrl(account.getAccountName(), account.getUrl() + "/index.php/avatar/" + Uri.encode(account.getUserName()) + "/64")) - .placeholder(R.drawable.ic_account_circle_grey_24dp) - .error(R.drawable.ic_account_circle_grey_24dp) - .apply(RequestOptions.circleCropTransform()) - .into(binding.sharedWithYouAvatar); - - binding.sharedWithYouAvatar.setVisibility(View.VISIBLE); - - /* - // TODO: Note's note? - String note = file.getNote(); - - if (!TextUtils.isEmpty(note)) { - binding.sharedWithYouNote.setText(file.getNote()); - binding.sharedWithYouNoteContainer.setVisibility(View.VISIBLE); - } else { - binding.sharedWithYouNoteContainer.setVisibility(View.GONE); - } - */ - } - } - - public void copyInternalLink() { - if (account == null) { - BrandedSnackbar.make(requireView(), getString(R.string.note_share_fragment_could_not_retrieve_url), Snackbar.LENGTH_LONG) - .setAnchorView(binding.sharesList) - .show(); - return; - } - - showShareLinkDialog(); - } - - private void showShareLinkDialog() { - String link = createInternalLink(); - - Intent intentToShareLink = new Intent(Intent.ACTION_SEND); - - intentToShareLink.putExtra(Intent.EXTRA_TEXT, link); - intentToShareLink.setType("text/plain"); - intentToShareLink.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.note_share_fragment_subject_shared_with_you, note.getTitle())); - - String[] packagesToExclude = new String[] { requireContext().getPackageName() }; - DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude); - chooserDialog.show(getParentFragmentManager(), FTAG_CHOOSER_DIALOG); - } - - // TODO: Check account.getUrl returning base url? - private String createInternalLink() { - Uri baseUri = Uri.parse(account.getUrl()); - return baseUri + "/index.php/f/" + note.getId(); - } - - // TODO: Capabilities in notes app doesn't have following functions... - public void createPublicShareLink() { - /* - if (capabilities != null && (capabilities.getFilesSharingPublicPasswordEnforced().isTrue() || - capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue())) { - // password enforced by server, request to the user before trying to create - requestPasswordForShareViaLink(true, - capabilities.getFilesSharingPublicAskForOptionalPassword().isTrue()); - - } else { - // TODO: Share files logic not suitable with notes app. How can I get remote path from remote id of the note - // Is CreateShareViaLink operation compatible? - - Intent service = new Intent(fileActivity, OperationsService.class); - service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK); - service.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount()); - if (!TextUtils.isEmpty(password)) { - service.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password); - } - service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - mWaitingForOpId = fileActivity.getOperationsServiceBinder().queueNewOperation(service); - } - */ - - } - - public void createSecureFileDrop() { - // fileOperationsHelper.shareFolderViaSecureFileDrop(file); - } - - /* - // TODO: Cant call getFileWithLink - - public void getFileWithLink(@NonNull OCFile file, final ViewThemeUtils viewThemeUtils) { - List shares = fileActivity.getStorageManager().getSharesByPathAndType(file.getRemotePath(), - ShareType.PUBLIC_LINK, - ""); - - if (shares.size() == SINGLE_LINK_SIZE) { - FileActivity.copyAndShareFileLink(fileActivity, file, shares.get(0).getShareLink(), viewThemeUtils); - } else { - if (fileActivity instanceof FileDisplayActivity) { - ((FileDisplayActivity) fileActivity).showDetails(file, 1); - } else { - showShareFile(file); - } - } - - fileActivity.refreshList(); - } - */ - private void showSendLinkTo(OCShare publicShare) { - /* - if (file.isSharedViaLink()) { - if (TextUtils.isEmpty(publicShare.getShareLink())) { - fileOperationsHelper.getFileWithLink(file, viewThemeUtils); - } else { - // TODO: get link from public share and pass to the function - showShareLinkDialog(); - } - } - */ - - } - - public void copyLink(OCShare share) { - /* - if (file.isSharedViaLink()) { - if (TextUtils.isEmpty(share.getShareLink())) { - fileOperationsHelper.getFileWithLink(file, viewThemeUtils); - } else { - ClipboardUtil.copyToClipboard(requireActivity(), share.getShareLink()); - } - } - */ - - } - - @Override - public void showSharingMenuActionSheet(OCShare share) { - if (getActivity() != null && !getActivity().isFinishing()) { - new FileDetailSharingMenuBottomSheetDialog(getActivity(), this, share).show(); - } - } - - @Override - public void showPermissionsDialog(OCShare share) { - new QuickSharingPermissionsBottomSheetDialog(getActivity(), this, share).show(); - } - - public void onUpdateShareInformation(RemoteOperationResult result) { - if (result.isSuccess()) { - refreshUiFromDB(); - } else { - setupView(); - } - } - - /** - * Get {@link OCShare} instance from DB and updates the UI. - */ - private void refreshUiFromDB() { - refreshSharesFromDB(); - // Updates UI with new state - setupView(); - } - - private void unshareWith(OCShare share) { - // fileOperationsHelper.unshareShare(file, share); - } - - /** - * Starts a dialog that requests a password to the user to protect a share link. - * - * @param createShare When 'true', the request for password will be followed by the creation of a new public - * link; when 'false', a public share is assumed to exist, and the password is bound to it. - * @param askForPassword if true, password is optional - */ - public void requestPasswordForShareViaLink(boolean createShare, boolean askForPassword) { - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(note, - createShare, - askForPassword); - dialog.show(getChildFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); - } - - @Override - public void requestPasswordForShare(OCShare share, boolean askForPassword) { - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(share, askForPassword); - dialog.show(getChildFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); - } - - @Override - public void showProfileBottomSheet(User user, String shareWith) { - if (user.getServer().getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_23)) { - new RetrieveHoverCardAsyncTask(user, - account, - shareWith, - getActivity(), - clientFactory).execute(); - } - } - - /** - * Get known server capabilities from DB - */ - public void refreshCapabilitiesFromDB() { - // capabilities = fileDataStorageManager.getCapability(user.getAccountName()); - } - - /** - * Get public link from the DB to fill in the "Share link" section in the UI. Takes into account server capabilities - * before reading database. - */ - public void refreshSharesFromDB() { - /* - OCFile newFile = fileDataStorageManager.getFileById(file.getFileId()); - if (newFile != null) { - file = newFile; - } - - ShareeListAdapter adapter = (ShareeListAdapter) binding.sharesList.getAdapter(); - - if (adapter == null) { - BrandedSnackbar.make(requireView(), getString(R.string.could_not_retrieve_shares), Snackbar.LENGTH_LONG) - .show(); - return; - } - adapter.getShares().clear(); - - // to show share with users/groups info - List shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(), - user.getAccountName()); - - adapter.addShares(shares); - - if (FileDetailSharingFragmentHelper.isPublicShareDisabled(capabilities) || !file.canReshare()) { - return; - } - - // Get public share - List publicShares = fileDataStorageManager.getSharesByPathAndType(file.getRemotePath(), - ShareType.PUBLIC_LINK, - ""); - - if (publicShares.isEmpty() && containsNoNewPublicShare(adapter.getShares())) { - final OCShare ocShare = new OCShare(); - ocShare.setShareType(ShareType.NEW_PUBLIC_LINK); - publicShares.add(ocShare); - } else { - adapter.removeNewPublicShare(); - } - - adapter.addShares(publicShares); - */ - - } - - private void checkContactPermission() { - if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { - pickContactEmail(); - } else { - requestContactPermissionLauncher.launch(Manifest.permission.READ_CONTACTS); - } - } - - private void pickContactEmail() { - Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI); - - if (intent.resolveActivity(requireContext().getPackageManager()) != null) { - onContactSelectionResultLauncher.launch(intent); - } else { - BrandedSnackbar.make(requireView(), getString(R.string.file_detail_sharing_fragment_no_contact_app_message), Snackbar.LENGTH_LONG) - .show(); - } - } - - private void handleContactResult(@NonNull Uri contactUri) { - // Define the projection to get all email addresses. - String[] projection = {ContactsContract.CommonDataKinds.Email.ADDRESS}; - - Cursor cursor = requireActivity().getContentResolver().query(contactUri, projection, null, null, null); - - if (cursor != null) { - if (cursor.moveToFirst()) { - // The contact has only one email address, use it. - int columnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS); - if (columnIndex != -1) { - // Use the email address as needed. - // email variable contains the selected contact's email address. - String email = cursor.getString(columnIndex); - binding.searchView.post(() -> { - binding.searchView.setQuery(email, false); - binding.searchView.requestFocus(); - }); - } else { - BrandedSnackbar.make(requireView(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - Log_OC.e(NoteShareFragment.class.getSimpleName(), "Failed to pick email address."); - } - } else { - BrandedSnackbar.make(requireView(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - Log_OC.e(NoteShareFragment.class.getSimpleName(), "Failed to pick email address as no Email found."); - } - cursor.close(); - } else { - BrandedSnackbar.make(requireView(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - Log_OC.e(NoteShareFragment.class.getSimpleName(), "Failed to pick email address as Cursor is null."); - } - } - - private boolean containsNoNewPublicShare(List shares) { - for (OCShare share : shares) { - if (share.getShareType() == ShareType.NEW_PUBLIC_LINK) { - return false; - } - } - - return true; - } - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putSerializable(ARG_NOTE, note); - outState.putSerializable(ARG_ACCOUNT, account); - outState.putParcelable(ARG_USER, user); - } - - public void avatarGenerated(Drawable avatarDrawable, Object callContext) { - binding.sharedWithYouAvatar.setImageDrawable(avatarDrawable); - } - - public boolean shouldCallGeneratedCallback(String tag, Object callContext) { - return false; - } - - private boolean isReshareForbidden(OCShare share) { - return false; - // return ShareType.FEDERATED == share.getShareType() || capabilities != null && capabilities.getFilesSharingResharing().isFalse(); - } - - @VisibleForTesting - public void search(String query) { - SearchView searchView = requireView().findViewById(R.id.searchView); - searchView.setQuery(query, true); - } - - @Override - public void advancedPermissions(OCShare share) { - // modifyExistingShare(share, FileDetailsSharingProcessFragment.SCREEN_TYPE_PERMISSION); - } - - - @Override - public void sendNewEmail(OCShare share) { - // modifyExistingShare(share, FileDetailsSharingProcessFragment.SCREEN_TYPE_NOTE); - } - - @Override - public void unShare(OCShare share) { - unshareWith(share); - ShareeListAdapter adapter = (ShareeListAdapter) binding.sharesList.getAdapter(); - if (adapter == null) { - BrandedSnackbar.make(requireView(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - return; - } - adapter.remove(share); - } - - @Override - public void sendLink(OCShare share) { - /* - if (file.isSharedViaLink() && !TextUtils.isEmpty(share.getShareLink())) { - FileDisplayActivity.showShareLinkDialog(fileActivity, file, share.getShareLink()); - } else { - showSendLinkTo(share); - } - */ - - } - - @Override - public void addAnotherLink(OCShare share) { - createPublicShareLink(); - } - - private void modifyExistingShare(OCShare share, int screenTypePermission) { - // onEditShareListener.editExistingShare(share, screenTypePermission, !isReshareForbidden(share), capabilities.getVersion().isNewerOrEqual(OwnCloudVersion.nextcloud_18)); - } - - @Override - public void onQuickPermissionChanged(OCShare share, int permission) { - // fileOperationsHelper.setPermissionsToShare(share, permission); - } - - //launcher for contact permission - private final ActivityResultLauncher requestContactPermissionLauncher = - registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { - if (isGranted) { - pickContactEmail(); - } else { - BrandedSnackbar.make(binding.getRoot(), getString(R.string.contact_no_permission), Snackbar.LENGTH_LONG) - .show(); - } - }); - - //launcher to handle contact selection - private final ActivityResultLauncher onContactSelectionResultLauncher = - registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), - result -> { - if (result.getResultCode() == Activity.RESULT_OK) { - Intent intent = result.getData(); - if (intent == null) { - BrandedSnackbar.make(binding.getRoot(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - return; - } - - Uri contactUri = intent.getData(); - if (contactUri == null) { - BrandedSnackbar.make(binding.getRoot(), getString(R.string.email_pick_failed), Snackbar.LENGTH_LONG) - .show(); - return; - } - - handleContactResult(contactUri); - - } - }); - - public interface OnEditShareListener { - void editExistingShare(OCShare share, int screenTypePermission, boolean isReshareShown, - boolean isExpiryDateShown); - - void onShareProcessClosed(); - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/share/SyncOperation.java b/app/src/main/java/it/niedermann/owncloud/notes/share/SyncOperation.java deleted file mode 100644 index 62eb8661a..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/share/SyncOperation.java +++ /dev/null @@ -1,37 +0,0 @@ -package it.niedermann.owncloud.notes.share; - - -import android.content.Context; -import android.os.Handler; - -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.common.User; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; - -import androidx.annotation.NonNull; - -public abstract class SyncOperation extends RemoteOperation { - private final User user; - - public SyncOperation(@NonNull User user) { - this.user = user; - } - - public RemoteOperationResult execute(Context context) { - return super.execute(user, context); - } - - public RemoteOperationResult execute(@NonNull NextcloudClient client) { - return run(client); - } - - public Thread execute(OwnCloudClient client, - OnRemoteOperationListener listener, - Handler listenerHandler) { - return super.execute(client, listener, listenerHandler); - } - -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/server/Server.kt b/app/src/main/java/it/niedermann/owncloud/notes/shared/server/Server.kt deleted file mode 100644 index be773c7f7..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/server/Server.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2019 Chris Narkiewicz - * SPDX-FileCopyrightText: 2019 Nextcloud GmbH - * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only - */ -package it.niedermann.owncloud.notes.shared.server - -import android.os.Parcel -import android.os.Parcelable -import com.owncloud.android.lib.resources.status.OwnCloudVersion -import java.net.URI - -/** - * This object provides all information necessary to interact - * with backend server. - */ -data class Server(val uri: URI, val version: OwnCloudVersion) : Parcelable { - - constructor(source: Parcel) : this( - source.readSerializable() as URI, - source.readParcelable(OwnCloudVersion::class.java.classLoader) as OwnCloudVersion - ) - - override fun describeContents() = 0 - - override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) { - writeSerializable(uri) - writeParcelable(version, 0) - } - - companion object { - @JvmField - val CREATOR: Parcelable.Creator = object : Parcelable.Creator { - override fun createFromParcel(source: Parcel): Server = Server(source) - override fun newArray(size: Int): Array = arrayOfNulls(size) - } - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/user/User.kt b/app/src/main/java/it/niedermann/owncloud/notes/shared/user/User.kt deleted file mode 100644 index b68c4598d..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/user/User.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2020 Chris Narkiewicz - * SPDX-FileCopyrightText: 2020 Nextcloud GmbH - * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only - */ -package it.niedermann.owncloud.notes.shared.user - -import android.accounts.Account -import android.os.Parcelable -import com.owncloud.android.lib.common.OwnCloudAccount -import it.niedermann.owncloud.notes.shared.server.Server - -interface User : Parcelable, com.nextcloud.common.User { - override val accountName: String - val server: Server - - /** - * This is temporary helper method created to facilitate incremental refactoring. - * Code using legacy platform Account can be partially converted to instantiate User - * object and use account instance when required. - * - * This method calls will allow tracing code awaiting further refactoring. - * - * @return Account instance that is associated with this User object. - */ - @Deprecated("Temporary workaround") - override fun toPlatformAccount(): Account - - /** - * This is temporary helper method created to facilitate incremental refactoring. - * Code using legacy ownCloud account can be partially converted to instantiate User - * object and use account instance when required. - * - * This method calls will allow tracing code awaiting further refactoring. - * - * @return OwnCloudAccount instance that is associated with this User object. - */ - @Deprecated("Temporary workaround") - fun toOwnCloudAccount(): OwnCloudAccount - - /** - * Compare account names, case insensitive. - * - * @return true if account names are same, false otherwise - */ - fun nameEquals(user: User?): Boolean - - /** - * Compare account names, case insensitive. - * - * @return true if account names are same, false otherwise - */ - fun nameEquals(accountName: CharSequence?): Boolean -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ClipboardUtil.kt b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ClipboardUtil.kt deleted file mode 100644 index cb6c5e14f..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ClipboardUtil.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2018 Andy Scherzinger - * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only - */ - -package it.niedermann.owncloud.notes.shared.util - -import android.app.Activity -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context -import android.text.TextUtils -import android.widget.Toast -import com.owncloud.android.lib.common.utils.Log_OC -import it.niedermann.owncloud.notes.R - -/** - * Helper implementation to copy a string into the system clipboard. - */ -object ClipboardUtil { - private val TAG = ClipboardUtil::class.java.name - - @JvmStatic - @JvmOverloads - @Suppress("TooGenericExceptionCaught") - fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { - if (!TextUtils.isEmpty(text)) { - try { - val clip = ClipData.newPlainText( - activity.getString( - R.string.clipboard_label, - activity.getString(R.string.app_name) - ), - text - ) - (activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(clip) - if (showToast) { - Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show() - } - } catch (e: Exception) { - Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show() - Log_OC.e(TAG, "Exception caught while copying to clipboard", e) - } - } else { - Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show() - } - } -} diff --git a/app/src/main/res/layout/activity_row.xml b/app/src/main/res/layout/activity_row.xml index 8d6e4d150..ffb8e2e6c 100644 --- a/app/src/main/res/layout/activity_row.xml +++ b/app/src/main/res/layout/activity_row.xml @@ -23,7 +23,7 @@ android:layout_height="@dimen/default_icon_size" android:layout_gravity="center_vertical" android:layout_marginEnd="@dimen/spacer_2x" - android:contentDescription="@string/note_share_fragment_activity_icon_content_description" /> + android:contentDescription="@string/note_share_activity_activity_icon_content_description" /> Choose a category - + + com.nextcloud.android.providers.UsersAndGroupsSearchProvider + com.nextcloud.android.providers.UsersAndGroupsSearchProvider.action.SHARE_WITH + + + @string/link_share_view_only @string/link_share_allow_upload_and_editing @string/link_share_file_drop - + @string/link_share_view_only @string/link_share_editing - note activity icon - note share icon - note share external icon - note share copy icon - note share more icon - note share icon - note share user icon - note share contact icon - Shared with you by %1$s - Name, Federated Cloud ID or email address… - Share link - Policy or permissions prevent resharing - Could not retrieve URL - \"%1$s\" has been shared with you - Contact permission is required. - You must enter a password - Password - Enter an optional password - Skip - Cancel - + + + note activity icon + note share icon + note share external icon + note share copy icon + note share more icon + note share icon + note share user icon + note share contact icon + Shared with you by %1$s + Share note + Name, Federated Cloud ID or email address… + Share link + Policy or permissions prevent resharing + Could not retrieve URL + \"%1$s\" has been shared with you + Contact permission is required. + + + Advanced Settings + Hide download + Note to recipient + Note + Next + Share and Copy Link + Confirm + Set Note + Send Share + Name + Link Name + You must enter a password + Password + Please select at least one permission to share. + Label cannot be empty + Cancel + Failed to create a share + + + Enter an optional password + Skip + Enter a password OK Delete @@ -76,6 +102,7 @@ No App available to handle mail address No actions for this user + Failed to remove share Failed to pick email address. Failed to update UI No app available to select contacts @@ -124,6 +151,9 @@ %1$s (remote) %1$s (conversation) on %1$s + (remote) + + Copy link Share