Update file+share to align toggled text with mock.
When text is toggled off, it should say e.g. "Image only".
Mock:
https://www.figma.com/file/JVIcmg4OhWuO5Vc1UdPVxe/Sharesheet-(U)?node-id=66-5067&t=Wj5ulJXOpvpOPlYY-0
Bug: 279599021
Test: atest UnbundledChooserActivityTest
Test: Manual test with ShareTest
Change-Id: I85eecae3c24f348e355717b78b2cf23aa748f91a
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 8a24b34..360e2bc 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -155,48 +155,85 @@
}
</string>
<!-- Title atop a sharing UI indicating that some number of files are being shared
- (for example: sharing a mixture of photos and videos [CHAR_LIMIT=50] -->
+ (for example: sharing a mixture of photos and videos) [CHAR_LIMIT=50] -->
<string name="sharing_files">{count, plural,
=1 {Sharing # file}
other {Sharing # files}
}
</string>
+
+ <!-- Title atop a sharing UI indicating that some number of images are being shared
+ along with text [CHAR_LIMIT=50] -->
<string name="sharing_images_with_text">{count, plural,
=1 {Sharing image with text}
other {Sharing # images with text}
}
</string>
+ <!-- Title atop a sharing UI indicating that some number of images are being shared
+ along with a web link [CHAR_LIMIT=50] -->
<string name="sharing_images_with_link">{count, plural,
=1 {Sharing image with link}
other {Sharing # images with link}
}
</string>
+ <!-- Title atop a sharing UI indicating that some number of videos are being shared
+ along with text [CHAR_LIMIT=50] -->
<string name="sharing_videos_with_text">{count, plural,
=1 {Sharing video with text}
other {Sharing # videos with text}
}
</string>
+ <!-- Title atop a sharing UI indicating that some number of videos are being shared
+ along with a web link [CHAR_LIMIT=50] -->
<string name="sharing_videos_with_link">{count, plural,
=1 {Sharing video with link}
other {Sharing # videos with link}
}
</string>
+ <!-- Title atop a sharing UI indicating that some number of files are being shared
+ along with text [CHAR_LIMIT=50] -->
<string name="sharing_files_with_text">{count, plural,
=1 {Sharing file with text}
other {Sharing # files with text}
}
</string>
+ <!-- Title atop a sharing UI indicating that some number of files are being shared
+ along with a web link [CHAR_LIMIT=50] -->
<string name="sharing_files_with_link">{count, plural,
=1 {Sharing file with link}
other {Sharing # files with link}
}
</string>
+ <!-- Message indicating that the attached text has been removed from this share and only the
+ images are being shared. [CHAR LIMIT=none] -->
+ <string name="sharing_images_only">{count, plural,
+ =1 {Image only}
+ other {Images only}
+ }
+ </string>
+
+ <!-- Message indicating that the attached text has been removed from this share and only the
+ videos are being shared. [CHAR LIMIT=none] -->
+ <string name="sharing_videos_only">{count, plural,
+ =1 {Video only}
+ other {Videos only}
+ }
+ </string>
+
+ <!-- Message indicating that the attached text has been removed from this share and only the
+ files are being shared. [CHAR LIMIT=none] -->
+ <string name="sharing_files_only">{count, plural,
+ =1 {File only}
+ other {Files only}
+ }
+ </string>
+
<!-- ChooserActivity - No direct share targets are available. [CHAR LIMIT=NONE] -->
<string name="chooser_no_direct_share_targets">No recommended people to share with</string>
diff --git a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
index e15d53c..5c42b4b 100644
--- a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
@@ -21,6 +21,7 @@
import android.content.res.Resources;
import android.text.util.Linkify;
+import android.util.PluralsMessageFormatter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -33,6 +34,7 @@
import com.android.intentresolver.widget.ScrollableImagePreviewView;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
@@ -175,9 +177,35 @@
shareTextAction.accept(false);
includeText.setOnCheckedChangeListener((view, isChecked) -> {
textView.setEnabled(isChecked);
+ if (isChecked) {
+ textView.setText(mText);
+ } else {
+ textView.setText(getNoTextString(contentPreview.getResources()));
+ }
shareTextAction.accept(!isChecked);
updateHeadline(contentPreview);
});
includeText.setVisibility(View.VISIBLE);
}
+
+ private String getNoTextString(Resources resources) {
+ int stringResource;
+
+ if (mAllImages) {
+ stringResource = R.string.sharing_images_only;
+ } else if (mAllVideos) {
+ stringResource = R.string.sharing_videos_only;
+ } else {
+ stringResource = R.string.sharing_files_only;
+ }
+
+ HashMap<String, Object> params = new HashMap<>();
+ params.put("count", mFiles.size());
+
+ return PluralsMessageFormatter.format(
+ resources,
+ params,
+ stringResource
+ );
+ }
}
diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
index 6c65913..7c4838a 100644
--- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
+++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
@@ -694,14 +694,13 @@
}
@Test
- public void testImagePlusTextSharing_ExcludeText() {
+ public void testFilePlusTextSharing_ExcludeText() {
Uri uri = Uri.parse(
"android.resource://com.android.frameworks.coretests/"
+ R.drawable.test320x240);
Intent sendIntent = createSendImageIntent(uri);
ChooserActivityOverrideData.getInstance().imageLoader =
createImageLoader(uri, createBitmap());
- ChooserActivityOverrideData.getInstance().isImageType = true;
sendIntent.putExtra(Intent.EXTRA_TEXT, "https://google.com/search?q=google");
List<ResolvedComponentInfo> resolvedComponentInfos = Arrays.asList(
@@ -723,6 +722,8 @@
.perform(click());
waitForIdle();
+ onView(withId(R.id.content_preview_text)).check(matches(withText("File only")));
+
AtomicReference<Intent> launchedIntentRef = new AtomicReference<>();
ChooserActivityOverrideData.getInstance().onSafelyStartInternalCallback = targetInfo -> {
launchedIntentRef.set(targetInfo.getTargetIntent());
@@ -736,14 +737,13 @@
}
@Test
- public void testImagePlusTextSharing_RemoveAndAddBackText() {
+ public void testFilePlusTextSharing_RemoveAndAddBackText() {
Uri uri = Uri.parse(
"android.resource://com.android.frameworks.coretests/"
+ R.drawable.test320x240);
Intent sendIntent = createSendImageIntent(uri);
ChooserActivityOverrideData.getInstance().imageLoader =
createImageLoader(uri, createBitmap());
- ChooserActivityOverrideData.getInstance().isImageType = true;
final String text = "https://google.com/search?q=google";
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
@@ -765,10 +765,14 @@
.check(matches(isDisplayed()))
.perform(click());
waitForIdle();
+ onView(withId(R.id.content_preview_text)).check(matches(withText("File only")));
+
onView(withId(R.id.include_text_action))
.perform(click());
waitForIdle();
+ onView(withId(R.id.content_preview_text)).check(matches(withText(text)));
+
AtomicReference<Intent> launchedIntentRef = new AtomicReference<>();
ChooserActivityOverrideData.getInstance().onSafelyStartInternalCallback = targetInfo -> {
launchedIntentRef.set(targetInfo.getTargetIntent());
@@ -782,14 +786,13 @@
}
@Test
- public void testImagePlusTextSharing_TextExclusionDoesNotAffectAlternativeIntent() {
+ public void testFilePlusTextSharing_TextExclusionDoesNotAffectAlternativeIntent() {
Uri uri = Uri.parse(
"android.resource://com.android.frameworks.coretests/"
+ R.drawable.test320x240);
Intent sendIntent = createSendImageIntent(uri);
ChooserActivityOverrideData.getInstance().imageLoader =
createImageLoader(uri, createBitmap());
- ChooserActivityOverrideData.getInstance().isImageType = true;
sendIntent.putExtra(Intent.EXTRA_TEXT, "https://google.com/search?q=google");
Intent alternativeIntent = createSendTextIntent();
@@ -828,7 +831,7 @@
}
@Test
- public void testImagePlusTextSharing_failedThumbnailAndExcludedText_textRemainsVisible() {
+ public void testImagePlusTextSharing_failedThumbnailAndExcludedText_textChanges() {
Uri uri = Uri.parse(
"android.resource://com.android.frameworks.coretests/"
+ R.drawable.test320x240);
@@ -860,7 +863,7 @@
onView(withId(R.id.image_view))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
onView(withId(R.id.content_preview_text))
- .check(matches(allOf(isDisplayed(), not(isEnabled()))));
+ .check(matches(allOf(isDisplayed(), not(isEnabled()), withText("File only"))));
}
@Test