-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12059 from nextcloud/nmc/emailShareViaContactBook
Share screen email selection from contact book
- Loading branch information
Showing
6 changed files
with
156 additions
and
22 deletions.
There are no files selected for viewing
Binary file modified
BIN
+162 Bytes
(100%)
...android.ui.fragment.FileDetailSharingFragmentIT_listSharesFileAllShareTypes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+172 Bytes
(100%)
...owncloud.android.ui.fragment.FileDetailSharingFragmentIT_listSharesFileNone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* | ||
* Copyright (C) 2018 Andy Scherzinger | ||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]> | ||
* 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,13 +68,16 @@ | |
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; | ||
import java.util.List; | ||
|
||
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<OCShare> 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<String> 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<Intent> 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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!-- | ||
@author Google LLC | ||
Copyright (C) 2023 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#666666" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
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" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters