From 2bc2bbe3afe0a3fbc1e5cb5f163086b1251f1e99 Mon Sep 17 00:00:00 2001 From: A117870935 Date: Mon, 25 Sep 2023 19:51:32 +0530 Subject: [PATCH 1/6] Share via email selection from contact. Signed-off-by: A117870935 --- .../gplay/res/drawable/ic_contact_book.xml | 10 ++ .../fragment/FileDetailSharingFragment.java | 93 ++++++++++++++++++- .../layout/file_details_sharing_fragment.xml | 17 +++- app/src/main/res/values/strings.xml | 2 + 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 app/src/gplay/res/drawable/ic_contact_book.xml diff --git a/app/src/gplay/res/drawable/ic_contact_book.xml b/app/src/gplay/res/drawable/ic_contact_book.xml new file mode 100644 index 000000000000..03331e98ba93 --- /dev/null +++ b/app/src/gplay/res/drawable/ic_contact_book.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index cde91289f708..f299a1470eab 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -7,7 +7,7 @@ * * Copyright (C) 2018 Andy Scherzinger * Copyright (C) 2020 Chris Narkiewicz - * Copyright (C) 2020 TSI-mc + * Copyright (C) 2023 TSI-mc * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -25,11 +25,17 @@ package com.owncloud.android.ui.fragment; +import android.Manifest; import android.accounts.AccountManager; +import android.app.Activity; import android.app.SearchManager; import android.content.Context; +import android.content.Intent; +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; @@ -46,6 +52,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudAccount; 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; @@ -61,6 +68,7 @@ import com.owncloud.android.ui.helpers.FileOperationsHelper; import com.owncloud.android.utils.ClipboardUtil; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.ArrayList; @@ -68,6 +76,8 @@ import javax.inject.Inject; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -167,6 +177,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, file.isEncrypted())); binding.sharesList.setLayoutManager(new LinearLayoutManager(getContext())); + binding.pickContactEmailBtn.setOnClickListener(v -> checkContactPermission()); + setupView(); return view; @@ -208,6 +220,7 @@ private void setupView() { } else { binding.searchView.setQueryHint(getResources().getString(R.string.reshare_not_allowed)); binding.searchView.setInputType(InputType.TYPE_NULL); + binding.pickContactEmailBtn.setVisibility(View.GONE); disableSearchView(binding.searchView); } } @@ -460,6 +473,52 @@ public void refreshSharesFromDB() { adapter.addShares(publicShares); } + private void checkContactPermission() { + if (PermissionUtil.checkSelfPermission(requireActivity(), Manifest.permission.READ_CONTACTS)) { + pickContactEmail(); + } else { + requestContactPermissionLauncher.launch(Manifest.permission.READ_CONTACTS); + } + } + + private void pickContactEmail() { + Intent intent = new Intent(Intent.ACTION_PICK); + intent.setDataAndType(ContactsContract.Contacts.CONTENT_URI, ContactsContract.CommonDataKinds.Email.CONTENT_TYPE); + onContactSelectionResultLauncher.launch(intent); + } + + private void handleContactResult(@NonNull Uri contactUri) { + // Define the projection to get all email addresses. + String[] projection = {ContactsContract.CommonDataKinds.Email.ADDRESS}; + + Cursor cursor = fileActivity.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 { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address."); + } + } else { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as no Email found."); + } + cursor.close(); + } else { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as Cursor is null."); + } + } private boolean containsNoNewPublicShare(List shares) { for (OCShare share : shares) { @@ -546,6 +605,38 @@ 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 { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.contact_no_permission); + } + }); + + //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) { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + return; + } + + Uri contactUri = intent.getData(); + if (contactUri == null) { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + return; + } + + handleContactResult(contactUri); + + } + }); + public interface OnEditShareListener { void editExistingShare(OCShare share, int screenTypePermission, boolean isReshareShown, boolean isExpiryDateShown); diff --git a/app/src/main/res/layout/file_details_sharing_fragment.xml b/app/src/main/res/layout/file_details_sharing_fragment.xml index bd9e093bf740..b129d3dff6de 100644 --- a/app/src/main/res/layout/file_details_sharing_fragment.xml +++ b/app/src/main/res/layout/file_details_sharing_fragment.xml @@ -1,7 +1,10 @@ *Y*Xy3H!+)TC(Bu`T9o)@BJEGk(rRwG7wgaIUmlj6}Jw zeVTucUdIYxvua56Y;nEKuh&Z_$Ev5T;%Owe@f7>S5nv&*!?H!oK{;gv!K!pWDb%)%|x!)hN8=RC8M(QnczbLh-0eh|ND?$@uFI8JaOL#(*8!UQ{6DKJ&R zZ<;uGj=8kc*fi(cW46$`uKg8Y9$o@wKtY(6s+4&jqV)Vxe`ZU9Od1F&tJJ&oL(l?% zOXJ17Z(v?AO|2OXqeqCPSSWBzEqB^KHzNGP`s3)SHcFx?_V{4++72@vNVE+6dMmXj znQjM#(^9MwJ6BcylQy(1|6UU4;4^oQ5snm+(h6|WoqgI!OwbzrurUTK8&LvF^rgwN z)J6C86thB(ooR9qn1wSUxKc+r&}mcbV^dMpMfed@$1a3ennuwnfqCwUdX+`XhT*9L zwhO7wN={Tsi{px6jzJAcw(g8Lk@LU1q&iIvkBOJe?bG;}bK_-710+bg7Z5P6;foTJ zmO;k;VF@o7l$tsMitPbXMSrmO8~S0To7}Xb0m%@7OOh+8*uv|gtMP}2 zY{`D_#YY9-n7yy$>;?|B535Z2K++vhh_z2AXDzD$MgqpV{Q86bx`cfmCu-ufD3OYy zzf523j|~{JHObwVBQ5_&{@^&G7#I&%_19^Kk`SbO+sU9_P}go(_A<4uu*Fk{dT(jN zx0PY(-r}R)*z%PQOj+m_6ltE|wH^v~0W=zVS*8lz&243M9DAMr?bNx%L$Q$ecR`FN zCcY)D$s~zT`;)p(F5@0}X5>F$Na;u3mi@gts>WMuecTpK?*k!qJ52mXj`7K4<%YkL z)toL)UKiMpY?V$%0^?rK)ImO7GaG!r(y46>!Wwg7T+Ojvb$4)W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Df-86DPGZIoiZ6D8Tem-a#DlXvfXLh5wUE^O_C$tYyTlNUGPn;WK(cV*Wf&~9 z+i(CHGrUU!VaUj|_BpmVorH!)P!zV2KwbEF&JB+Gz)Iy~pA@J+YE%TdY*B}1( F{{avEMjZeE From 1af7b621e2596d78d717dd6b4e820db1ed5fc63b Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 20 Nov 2023 10:14:01 +0100 Subject: [PATCH 3/6] Update icon to Google Material one, improve layouting, make available for any build Signed-off-by: Andy Scherzinger --- .../gplay/res/drawable/ic_contact_book.xml | 10 ------- app/src/main/res/drawable/ic_contact_book.xml | 26 +++++++++++++++++++ .../layout/file_details_sharing_fragment.xml | 12 ++++----- 3 files changed, 32 insertions(+), 16 deletions(-) delete mode 100644 app/src/gplay/res/drawable/ic_contact_book.xml create mode 100644 app/src/main/res/drawable/ic_contact_book.xml diff --git a/app/src/gplay/res/drawable/ic_contact_book.xml b/app/src/gplay/res/drawable/ic_contact_book.xml deleted file mode 100644 index 03331e98ba93..000000000000 --- a/app/src/gplay/res/drawable/ic_contact_book.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_contact_book.xml b/app/src/main/res/drawable/ic_contact_book.xml new file mode 100644 index 000000000000..add239bdf719 --- /dev/null +++ b/app/src/main/res/drawable/ic_contact_book.xml @@ -0,0 +1,26 @@ + + + + diff --git a/app/src/main/res/layout/file_details_sharing_fragment.xml b/app/src/main/res/layout/file_details_sharing_fragment.xml index b129d3dff6de..5adce798a100 100644 --- a/app/src/main/res/layout/file_details_sharing_fragment.xml +++ b/app/src/main/res/layout/file_details_sharing_fragment.xml @@ -33,8 +33,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingStart="@dimen/standard_padding" - android:paddingEnd="@dimen/standard_padding"> + android:paddingStart="@dimen/standard_padding"> @@ -130,6 +129,7 @@ android:dividerHeight="1dp" android:id="@+id/sharesList" android:layout_height="match_parent" - android:layout_width="match_parent" /> + android:layout_width="match_parent" + tools:listitem="@layout/file_details_share_link_share_item" /> From 585c17075cb598d10cf47cabf7b28ca0ad6226a8 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 21 Nov 2023 16:59:37 +0100 Subject: [PATCH 4/6] define paddingEnd for right-to-left symmetry Signed-off-by: Andy Scherzinger --- app/src/main/res/layout/file_details_sharing_fragment.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/file_details_sharing_fragment.xml b/app/src/main/res/layout/file_details_sharing_fragment.xml index 5adce798a100..bc8495fff472 100644 --- a/app/src/main/res/layout/file_details_sharing_fragment.xml +++ b/app/src/main/res/layout/file_details_sharing_fragment.xml @@ -33,7 +33,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingStart="@dimen/standard_padding"> + android:paddingStart="@dimen/standard_padding" + android:paddingEnd="@dimen/zero"> Date: Tue, 21 Nov 2023 18:19:46 +0100 Subject: [PATCH 5/6] reformat layout Signed-off-by: Andy Scherzinger --- .../layout/file_details_sharing_fragment.xml | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/res/layout/file_details_sharing_fragment.xml b/app/src/main/res/layout/file_details_sharing_fragment.xml index bc8495fff472..e4a1723e92d8 100644 --- a/app/src/main/res/layout/file_details_sharing_fragment.xml +++ b/app/src/main/res/layout/file_details_sharing_fragment.xml @@ -38,21 +38,21 @@ @@ -68,57 +68,57 @@ + android:paddingTop="@dimen/standard_padding" + android:paddingRight="@dimen/standard_padding"> + android:paddingTop="@dimen/standard_half_padding" + android:paddingRight="@dimen/standard_padding"> @@ -126,11 +126,11 @@ From 8cc428a3a969e1ee5bd5dc9a6f436f56d5d306aa Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 21 Nov 2023 18:40:28 +0100 Subject: [PATCH 6/6] Optimize layout, revert icon style Signed-off-by: Andy Scherzinger --- app/src/main/res/drawable/ic_contact_book.xml | 6 +++--- app/src/main/res/layout/file_details_sharing_fragment.xml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/drawable/ic_contact_book.xml b/app/src/main/res/drawable/ic_contact_book.xml index add239bdf719..6dff9b171724 100644 --- a/app/src/main/res/drawable/ic_contact_book.xml +++ b/app/src/main/res/drawable/ic_contact_book.xml @@ -18,9 +18,9 @@ android:width="24dp" android:height="24dp" android:tint="#666666" - android:viewportWidth="960" - android:viewportHeight="960"> + android:viewportWidth="24" + android:viewportHeight="24"> + android:pathData="M20,0L4,0v2h16L20,0zM4,24h16v-2L4,22v2zM20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM12,6.75c1.24,0 2.25,1.01 2.25,2.25s-1.01,2.25 -2.25,2.25S9.75,10.24 9.75,9 10.76,6.75 12,6.75zM17,17L7,17v-1.5c0,-1.67 3.33,-2.5 5,-2.5s5,0.83 5,2.5L17,17z" /> diff --git a/app/src/main/res/layout/file_details_sharing_fragment.xml b/app/src/main/res/layout/file_details_sharing_fragment.xml index e4a1723e92d8..f9122e926f92 100644 --- a/app/src/main/res/layout/file_details_sharing_fragment.xml +++ b/app/src/main/res/layout/file_details_sharing_fragment.xml @@ -62,6 +62,7 @@ android:layout_height="@dimen/minimum_size_for_touchable_area" android:layout_gravity="center_vertical" android:padding="12dp" + android:layout_marginEnd="@dimen/standard_quarter_margin" android:src="@drawable/ic_contact_book" />