Skip to content

Commit

Permalink
Email selection from contact implemented with Test Cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Feb 8, 2024
1 parent ef7cad7 commit 573a9e4
Show file tree
Hide file tree
Showing 15 changed files with 779 additions and 275 deletions.
8 changes: 6 additions & 2 deletions app/src/androidTest/java/com/nmc/android/ui/FileSharingIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ class FileSharingIT : AbstractIT() {
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
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.")))
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))

onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
onView(withId(R.id.share_create_new_link)).check(matches(withText("Create Link")))

onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
onView(withId(R.id.sharesList)).check(matches(not(isDisplayed())))
Expand Down Expand Up @@ -155,11 +156,12 @@ class FileSharingIT : AbstractIT() {
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
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.")))
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))

onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
onView(withId(R.id.share_create_new_link)).check(matches(withText("Create Link")))

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

onView(withId(R.id.searchView)).check(matches(not(isDisplayed())))
onView(withId(R.id.pick_contact_email_btn)).check(matches(not(isDisplayed())))
onView(withId(R.id.label_personal_share)).check(matches(not(isDisplayed())))
onView(withId(R.id.share_create_new_link)).check(matches(not(isDisplayed())))
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
Expand All @@ -208,6 +211,7 @@ class FileSharingIT : AbstractIT() {
onView(withId(R.id.shared_with_you_note_container)).check(matches(not(isDisplayed())))

onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.pick_contact_email_btn)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
Expand Down
97 changes: 64 additions & 33 deletions app/src/main/java/com/nmc/android/utils/CheckableThemeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@ package com.nmc.android.utils
import android.content.res.ColorStateList
import androidx.appcompat.widget.AppCompatCheckBox
import androidx.appcompat.widget.SwitchCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.widget.CompoundButtonCompat
import com.owncloud.android.MainApp
import androidx.core.content.res.ResourcesCompat
import com.owncloud.android.R

object CheckableThemeUtils {
@JvmStatic
fun tintCheckbox(vararg checkBoxes: AppCompatCheckBox) {
for (checkBox in checkBoxes) {
val checkEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_enabled)
val checkDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_disabled)
val uncheckEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_enabled)
val uncheckDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_disabled)
val checkEnabled = ResourcesCompat.getColor(
checkBox.context.resources,
R.color.checkbox_checked_enabled,
checkBox.context.theme
)
val checkDisabled = ResourcesCompat.getColor(
checkBox.context.resources,
R.color.checkbox_checked_disabled,
checkBox.context.theme
)
val uncheckEnabled = ResourcesCompat.getColor(
checkBox.context.resources,
R.color.checkbox_unchecked_enabled,
checkBox.context.theme
)
val uncheckDisabled = ResourcesCompat.getColor(
checkBox.context.resources,
R.color.checkbox_unchecked_disabled,
checkBox.context.theme
)

val states = arrayOf(
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
Expand All @@ -29,8 +43,7 @@ object CheckableThemeUtils {
uncheckEnabled,
uncheckDisabled
)
val checkColorStateList = ColorStateList(states, colors)
CompoundButtonCompat.setButtonTintList(checkBox, checkColorStateList)
checkBox.buttonTintList = ColorStateList(states, colors)
}
}

Expand All @@ -40,47 +53,65 @@ object CheckableThemeUtils {
if (colorText) {
switchView.setTextColor(color)
}
val thumbColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_enabled)
val thumbColorUncheckedEnabled =
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_enabled)
val thumbColorCheckedDisabled =
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_disabled)
val thumbColorUncheckedDisabled =
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_disabled)

val states = arrayOf(
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
intArrayOf(-android.R.attr.state_enabled, android.R.attr.state_checked),
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked),
intArrayOf(-android.R.attr.state_enabled, -android.R.attr.state_checked)
intArrayOf(-android.R.attr.state_enabled)
)

val thumbColorCheckedEnabled = ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_thumb_checked_enabled,
switchView.context.theme
)
val thumbColorUncheckedEnabled =
ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_thumb_unchecked_enabled,
switchView.context.theme
)
val thumbColorDisabled =
ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_thumb_disabled,
switchView.context.theme
)

val thumbColors = intArrayOf(
thumbColorCheckedEnabled,
thumbColorCheckedDisabled,
thumbColorUncheckedEnabled,
thumbColorUncheckedDisabled
thumbColorDisabled
)
val thumbColorStateList = ColorStateList(states, thumbColors)
val trackColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_enabled)

val trackColorCheckedEnabled = ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_track_checked_enabled,
switchView.context.theme
)
val trackColorUncheckedEnabled =
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_enabled)
val trackColorCheckedDisabled =
MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_disabled)
val trackColorUncheckedDisabled =
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_disabled)
ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_track_unchecked_enabled,
switchView.context.theme
)
val trackColorDisabled =
ResourcesCompat.getColor(
switchView.context.resources,
R.color.switch_track_disabled,
switchView.context.theme
)

val trackColors = intArrayOf(
trackColorCheckedEnabled,
trackColorCheckedDisabled,
trackColorUncheckedEnabled,
trackColorUncheckedDisabled
trackColorDisabled
)
val trackColorStateList = ColorStateList(states, trackColors)

// setting the thumb color
DrawableCompat.setTintList(switchView.thumbDrawable, thumbColorStateList)
val trackColorStateList = ColorStateList(states, trackColors)

// setting the track color
DrawableCompat.setTintList(switchView.trackDrawable, trackColorStateList)
switchView.thumbTintList = thumbColorStateList
switchView.trackTintList = trackColorStateList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ protected void doShareWith(String shareeName, ShareType shareType) {
//if user sharing from Preview Image Fragment
fragment = getSupportFragmentManager().findFragmentByTag(ShareActivity.TAG_SHARE_FRAGMENT);
if (fragment != null) {
((FileDetailSharingFragment) fragment).initiateSharingProcess(shareeName, shareType);
((FileDetailSharingFragment) fragment).initiateSharingProcess(shareeName, shareType, usersAndGroupsSearchConfig.getSearchOnlyUsers());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.utils.IntentUtil.createSendIntent
import com.nextcloud.utils.extensions.getParcelableArgument
Expand Down Expand Up @@ -85,7 +84,6 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
binding.btnShare.setOnClickListener { shareFile(file) }
binding.btnLink.setOnClickListener { shareByLink() }

applyTintColor()
setupBottomSheetBehaviour()
checkButtonVisibilities()
setupSendButtonRecyclerView()
Expand All @@ -109,12 +107,6 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
bottomSheetDialog.behavior.skipCollapsed = true
}

private fun applyTintColor() {
viewThemeUtils?.material?.colorMaterialButtonPrimaryFilled(binding.btnLink)
viewThemeUtils?.material?.colorMaterialButtonPrimaryFilled(binding.btnShare)
viewThemeUtils?.platform?.colorViewBackground(binding.bottomSheet, ColorRole.SURFACE)
}

@Suppress("MagicNumber")
private fun checkButtonVisibilities() {
if (hideNcSharingOptions) {
Expand All @@ -138,6 +130,9 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment),
}

private fun shareByLink() {
// NMC Customization
isPeopleShareClicked = false

val fileOperationsHelper = (requireActivity() as FileActivity).fileOperationsHelper

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

private fun shareFile(file: OCFile?) {
// NMC Customization
isPeopleShareClicked = true

dismiss()

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

// TODO: 06/21/23 remove this condition after Comments section included
// flag to avoid crash during creating new link share for a file for which link share already exist
@JvmField
var isPeopleShareClicked = false

@JvmStatic
fun newInstance(file: OCFile?, hideNcSharingOptions: Boolean, capability: OCCapability): SendShareDialog {
val dialogFragment = SendShareDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -95,6 +96,7 @@
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentManager;

Expand Down Expand Up @@ -547,11 +549,17 @@ private void setFileModificationTimestamp(OCFile file, boolean showDetailedTimes

private void setFavoriteIconStatus(boolean isFavorite) {
if (isFavorite) {
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_star, null));
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.favorite, null));
} else {
binding.favorite.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
R.drawable.ic_star_outline,
null));
R.drawable.ic_star_outline,
null));

//NMC Customization
binding.favorite.getDrawable().mutate().setColorFilter(requireContext()
.getResources()
.getColor(R.color.list_item_lastmod_and_filesize_text, null),
PorterDuff.Mode.SRC_IN);
}
}

Expand All @@ -574,13 +582,12 @@ private void setFilePreview(OCFile file) {

if (toolbarActivity != null) {
if (file.isFolder()) {
toolbarActivity.setPreviewImageDrawable(MimeTypeUtil
.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
file.isSharedViaLink(), file.isEncrypted(),
file.isGroupFolder(),
syncedFolderProvider.findByRemotePathAndAccount(file.getRemotePath(), user),
file.getMountType(), requireContext(),
viewThemeUtils));
boolean isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user);

Integer overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder);
// NMC Customization: No overlay icon will be used. Directly using folder icons
toolbarActivity.setPreviewImageDrawable(ContextCompat.getDrawable(requireContext(), overlayIconId));

int leftRightPadding = requireContext().getResources().getDimensionPixelSize(R.dimen.standard_padding);
updatePreviewImageUI(leftRightPadding);

Expand Down
Loading

0 comments on commit 573a9e4

Please sign in to comment.