Skip to content

Commit 9d0fd50

Browse files
committed
Email selection from contact implemented with Test Cases.
1 parent 285f3fc commit 9d0fd50

13 files changed

Lines changed: 772 additions & 266 deletions

File tree

app/src/androidTest/java/com/nmc/android/ui/FileSharingIT.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ class FileSharingIT : AbstractIT() {
9999
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
100100
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("You can create links or send shares by mail. If you invite MagentaCLOUD users, you have more opportunities for collaboration.")))
101101
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
102+
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
102103
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
103104
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))
104105

105106
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
106-
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
107+
onView(withId(R.id.share_create_new_link)).check(matches(withText("Create Link")))
107108

108109
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
109110
onView(withId(R.id.sharesList)).check(matches(not(isDisplayed())))
@@ -155,11 +156,12 @@ class FileSharingIT : AbstractIT() {
155156
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
156157
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("You can create links or send shares by mail. If you invite MagentaCLOUD users, you have more opportunities for collaboration.")))
157158
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
159+
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
158160
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
159161
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))
160162

161163
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
162-
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
164+
onView(withId(R.id.share_create_new_link)).check(matches(withText("Create Link")))
163165

164166
onView(withId(R.id.tv_your_shares)).check(matches(isCompletelyDisplayed()))
165167
onView(withId(R.id.tv_your_shares)).check(matches(withText("Your Shares")))
@@ -185,6 +187,7 @@ class FileSharingIT : AbstractIT() {
185187
onView(withId(R.id.shared_with_you_avatar)).check(matches(isCompletelyDisplayed()))
186188

187189
onView(withId(R.id.searchView)).check(matches(not(isDisplayed())))
190+
onView(withId(R.id.pick_contact_email_btn)).check(matches(not(isDisplayed())))
188191
onView(withId(R.id.label_personal_share)).check(matches(not(isDisplayed())))
189192
onView(withId(R.id.share_create_new_link)).check(matches(not(isDisplayed())))
190193
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
@@ -208,6 +211,7 @@ class FileSharingIT : AbstractIT() {
208211
onView(withId(R.id.shared_with_you_note_container)).check(matches(not(isDisplayed())))
209212

210213
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
214+
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
211215
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
212216
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
213217
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))

app/src/main/java/com/nmc/android/utils/CheckableThemeUtils.kt

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,33 @@ package com.nmc.android.utils
33
import android.content.res.ColorStateList
44
import androidx.appcompat.widget.AppCompatCheckBox
55
import androidx.appcompat.widget.SwitchCompat
6-
import androidx.core.graphics.drawable.DrawableCompat
7-
import androidx.core.widget.CompoundButtonCompat
8-
import com.owncloud.android.MainApp
6+
import androidx.core.content.res.ResourcesCompat
97
import com.owncloud.android.R
108

119
object CheckableThemeUtils {
1210
@JvmStatic
1311
fun tintCheckbox(vararg checkBoxes: AppCompatCheckBox) {
1412
for (checkBox in checkBoxes) {
15-
val checkEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_enabled)
16-
val checkDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_disabled)
17-
val uncheckEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_enabled)
18-
val uncheckDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_disabled)
13+
val checkEnabled = ResourcesCompat.getColor(
14+
checkBox.context.resources,
15+
R.color.checkbox_checked_enabled,
16+
checkBox.context.theme
17+
)
18+
val checkDisabled = ResourcesCompat.getColor(
19+
checkBox.context.resources,
20+
R.color.checkbox_checked_disabled,
21+
checkBox.context.theme
22+
)
23+
val uncheckEnabled = ResourcesCompat.getColor(
24+
checkBox.context.resources,
25+
R.color.checkbox_unchecked_enabled,
26+
checkBox.context.theme
27+
)
28+
val uncheckDisabled = ResourcesCompat.getColor(
29+
checkBox.context.resources,
30+
R.color.checkbox_unchecked_disabled,
31+
checkBox.context.theme
32+
)
1933

2034
val states = arrayOf(
2135
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
@@ -29,8 +43,7 @@ object CheckableThemeUtils {
2943
uncheckEnabled,
3044
uncheckDisabled
3145
)
32-
val checkColorStateList = ColorStateList(states, colors)
33-
CompoundButtonCompat.setButtonTintList(checkBox, checkColorStateList)
46+
checkBox.buttonTintList = ColorStateList(states, colors)
3447
}
3548
}
3649

@@ -40,47 +53,65 @@ object CheckableThemeUtils {
4053
if (colorText) {
4154
switchView.setTextColor(color)
4255
}
43-
val thumbColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_enabled)
44-
val thumbColorUncheckedEnabled =
45-
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_enabled)
46-
val thumbColorCheckedDisabled =
47-
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_disabled)
48-
val thumbColorUncheckedDisabled =
49-
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_disabled)
5056

5157
val states = arrayOf(
5258
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
53-
intArrayOf(-android.R.attr.state_enabled, android.R.attr.state_checked),
5459
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked),
55-
intArrayOf(-android.R.attr.state_enabled, -android.R.attr.state_checked)
60+
intArrayOf(-android.R.attr.state_enabled)
5661
)
62+
63+
val thumbColorCheckedEnabled = ResourcesCompat.getColor(
64+
switchView.context.resources,
65+
R.color.switch_thumb_checked_enabled,
66+
switchView.context.theme
67+
)
68+
val thumbColorUncheckedEnabled =
69+
ResourcesCompat.getColor(
70+
switchView.context.resources,
71+
R.color.switch_thumb_unchecked_enabled,
72+
switchView.context.theme
73+
)
74+
val thumbColorDisabled =
75+
ResourcesCompat.getColor(
76+
switchView.context.resources,
77+
R.color.switch_thumb_disabled,
78+
switchView.context.theme
79+
)
80+
5781
val thumbColors = intArrayOf(
5882
thumbColorCheckedEnabled,
59-
thumbColorCheckedDisabled,
6083
thumbColorUncheckedEnabled,
61-
thumbColorUncheckedDisabled
84+
thumbColorDisabled
6285
)
6386
val thumbColorStateList = ColorStateList(states, thumbColors)
64-
val trackColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_enabled)
87+
88+
val trackColorCheckedEnabled = ResourcesCompat.getColor(
89+
switchView.context.resources,
90+
R.color.switch_track_checked_enabled,
91+
switchView.context.theme
92+
)
6593
val trackColorUncheckedEnabled =
66-
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_enabled)
67-
val trackColorCheckedDisabled =
68-
MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_disabled)
69-
val trackColorUncheckedDisabled =
70-
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_disabled)
94+
ResourcesCompat.getColor(
95+
switchView.context.resources,
96+
R.color.switch_track_unchecked_enabled,
97+
switchView.context.theme
98+
)
99+
val trackColorDisabled =
100+
ResourcesCompat.getColor(
101+
switchView.context.resources,
102+
R.color.switch_track_disabled,
103+
switchView.context.theme
104+
)
71105

72106
val trackColors = intArrayOf(
73107
trackColorCheckedEnabled,
74-
trackColorCheckedDisabled,
75108
trackColorUncheckedEnabled,
76-
trackColorUncheckedDisabled
109+
trackColorDisabled
77110
)
78-
val trackColorStateList = ColorStateList(states, trackColors)
79111

80-
// setting the thumb color
81-
DrawableCompat.setTintList(switchView.thumbDrawable, thumbColorStateList)
112+
val trackColorStateList = ColorStateList(states, trackColors)
82113

83-
// setting the track color
84-
DrawableCompat.setTintList(switchView.trackDrawable, trackColorStateList)
114+
switchView.thumbTintList = thumbColorStateList
115+
switchView.trackTintList = trackColorStateList
85116
}
86117
}

app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
1212
import com.google.android.material.bottomsheet.BottomSheetDialog
1313
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
1414
import com.google.android.material.snackbar.Snackbar
15-
import com.nextcloud.android.common.ui.theme.utils.ColorRole
1615
import com.nextcloud.client.di.Injectable
1716
import com.nextcloud.client.utils.IntentUtil.createSendIntent
1817
import com.nextcloud.utils.extensions.getParcelableArgument
@@ -85,7 +84,6 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
8584
binding.btnShare.setOnClickListener { shareFile(file) }
8685
binding.btnLink.setOnClickListener { shareByLink() }
8786

88-
applyTintColor()
8987
setupBottomSheetBehaviour()
9088
checkButtonVisibilities()
9189
setupSendButtonRecyclerView()
@@ -109,12 +107,6 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
109107
bottomSheetDialog.behavior.skipCollapsed = true
110108
}
111109

112-
private fun applyTintColor() {
113-
viewThemeUtils?.material?.colorMaterialButtonPrimaryFilled(binding.btnLink)
114-
viewThemeUtils?.material?.colorMaterialButtonPrimaryFilled(binding.btnShare)
115-
viewThemeUtils?.platform?.colorViewBackground(binding.bottomSheet, ColorRole.SURFACE)
116-
}
117-
118110
@Suppress("MagicNumber")
119111
private fun checkButtonVisibilities() {
120112
if (hideNcSharingOptions) {
@@ -138,6 +130,9 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
138130
}
139131

140132
private fun shareByLink() {
133+
// NMC Customization
134+
isPeopleShareClicked = false
135+
141136
val fileOperationsHelper = (requireActivity() as FileActivity).fileOperationsHelper
142137

143138
if (file?.isSharedViaLink == true) {
@@ -221,6 +216,9 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
221216
}
222217

223218
private fun shareFile(file: OCFile?) {
219+
// NMC Customization
220+
isPeopleShareClicked = true
221+
224222
dismiss()
225223

226224
if (activity is FileDisplayActivity) {
@@ -247,6 +245,11 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
247245
const val PACKAGE_NAME = "PACKAGE_NAME"
248246
const val ACTIVITY_NAME = "ACTIVITY_NAME"
249247

248+
// TODO: 06/21/23 remove this condition after Comments section included
249+
// flag to avoid crash during creating new link share for a file for which link share already exist
250+
@JvmField
251+
var isPeopleShareClicked = false
252+
250253
@JvmStatic
251254
fun newInstance(file: OCFile?, hideNcSharingOptions: Boolean, capability: OCCapability): SendShareDialog {
252255
val dialogFragment = SendShareDialog()

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.Context;
3131
import android.content.res.ColorStateList;
3232
import android.graphics.Bitmap;
33+
import android.graphics.PorterDuff;
3334
import android.graphics.drawable.Drawable;
3435
import android.os.Bundle;
3536
import android.view.LayoutInflater;
@@ -95,6 +96,7 @@
9596
import androidx.annotation.IdRes;
9697
import androidx.annotation.NonNull;
9798
import androidx.annotation.Nullable;
99+
import androidx.core.content.ContextCompat;
98100
import androidx.core.content.res.ResourcesCompat;
99101
import androidx.fragment.app.FragmentManager;
100102

@@ -548,11 +550,17 @@ private void setFileModificationTimestamp(OCFile file, boolean showDetailedTimes
548550

549551
private void setFavoriteIconStatus(boolean isFavorite) {
550552
if (isFavorite) {
551-
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_star, null));
553+
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.favorite, null));
552554
} else {
553555
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
554-
R.drawable.ic_star_outline,
555-
null));
556+
R.drawable.ic_star_outline,
557+
null));
558+
559+
//NMC Customization
560+
binding.favorite.getDrawable().mutate().setColorFilter(requireContext()
561+
.getResources()
562+
.getColor(R.color.list_item_lastmod_and_filesize_text, null),
563+
PorterDuff.Mode.SRC_IN);
556564
}
557565
}
558566

@@ -575,13 +583,12 @@ private void setFilePreview(OCFile file) {
575583

576584
if (toolbarActivity != null) {
577585
if (file.isFolder()) {
578-
toolbarActivity.setPreviewImageDrawable(MimeTypeUtil
579-
.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
580-
file.isSharedViaLink(), file.isEncrypted(),
581-
file.isGroupFolder(),
582-
syncedFolderProvider.findByRemotePathAndAccount(file.getRemotePath(), user),
583-
file.getMountType(), requireContext(),
584-
viewThemeUtils));
586+
boolean isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user);
587+
588+
Integer overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder);
589+
// NMC Customization: No overlay icon will be used. Directly using folder icons
590+
toolbarActivity.setPreviewImageDrawable(ContextCompat.getDrawable(requireContext(), overlayIconId));
591+
585592
int leftRightPadding = requireContext().getResources().getDimensionPixelSize(R.dimen.standard_padding);
586593
updatePreviewImageUI(leftRightPadding);
587594

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
import android.Manifest;
2929
import android.accounts.AccountManager;
3030
import android.annotation.SuppressLint;
31+
import android.app.Activity;
3132
import android.app.SearchManager;
3233
import android.content.Context;
34+
import android.content.Intent;
3335
import android.content.res.Configuration;
36+
import android.database.Cursor;
3437
import android.graphics.drawable.Drawable;
3538
import android.net.Uri;
3639
import android.os.Bundle;
40+
import android.provider.ContactsContract;
3741
import android.text.TextUtils;
3842
import android.view.LayoutInflater;
3943
import android.view.View;
@@ -186,6 +190,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
186190

187191
binding.sharesList.setLayoutManager(new LinearLayoutManager(requireContext()));
188192

193+
binding.pickContactEmailBtn.setOnClickListener(v -> checkContactPermission());
194+
189195
binding.shareCreateNewLink.setOnClickListener(v -> createPublicShareLink());
190196

191197
//remove focus from search view on click of root view
@@ -236,6 +242,7 @@ private void setUpSearchView() {
236242
binding.searchView.setQueryHint(getResources().getString(R.string.share_search));
237243
binding.searchView.setVisibility(View.VISIBLE);
238244
binding.labelPersonalShare.setVisibility(View.VISIBLE);
245+
binding.pickContactEmailBtn.setVisibility(View.VISIBLE);
239246

240247
binding.searchView.setOnQueryTextFocusChangeListener((view, hasFocus) -> {
241248
isSearchViewFocused = hasFocus;
@@ -351,9 +358,10 @@ private void setShareWithYou() {
351358

352359
String note = file.getNote();
353360

361+
//NMC Customization --> Share with me note container is not required
354362
if (!TextUtils.isEmpty(note)) {
355363
binding.sharedWithYouNote.setText(file.getNote());
356-
binding.sharedWithYouNoteContainer.setVisibility(View.VISIBLE);
364+
binding.sharedWithYouNoteContainer.setVisibility(View.GONE);
357365
} else {
358366
binding.sharedWithYouNoteContainer.setVisibility(View.GONE);
359367
}
@@ -364,6 +372,7 @@ private void setShareWithYou() {
364372
} else {
365373
binding.searchView.setVisibility(View.GONE);
366374
binding.labelPersonalShare.setVisibility(View.GONE);
375+
binding.pickContactEmailBtn.setVisibility(View.GONE);
367376
binding.shareCreateNewLink.setVisibility(View.GONE);
368377
binding.tvSharingDetailsMessage.setText(getResources().getString(R.string.reshare_not_allowed));
369378
}
@@ -557,6 +566,7 @@ public void refreshSharesFromDB() {
557566
ShareType.PUBLIC_LINK,
558567
"");
559568

569+
// NMC Customization: Not required for NMC
560570
/*if (publicShares.isEmpty() && containsNoNewPublicShare(adapter.getShares()) &&
561571
(!file.isEncrypted() || capabilities.getEndToEndEncryption().isTrue())) {
562572
final OCShare ocShare = new OCShare();
@@ -566,14 +576,6 @@ public void refreshSharesFromDB() {
566576
adapter.removeNewPublicShare();
567577
}*/
568578

569-
if (publicShares.isEmpty() && containsNoNewPublicShare(adapter.getShares())) {
570-
final OCShare ocShare = new OCShare();
571-
ocShare.setShareType(ShareType.NEW_PUBLIC_LINK);
572-
publicShares.add(ocShare);
573-
} else {
574-
adapter.removeNewPublicShare();
575-
}
576-
577579
adapter.addShares(publicShares);
578580

579581
showHideView((shares == null || shares.isEmpty()) && (publicShares == null || publicShares.isEmpty()));

0 commit comments

Comments
 (0)