-
-
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.
Share via email selection from contact.
Signed-off-by: A117870935 <[email protected]>
- Loading branch information
1 parent
154796b
commit c61f2da
Showing
4 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
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,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#757575" | ||
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
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
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